Commit graph

63050 commits

Author SHA1 Message Date
Kristian Nielsen
7671fd70c0 MDEV-7080: rpl.rpl_gtid_crash fails sporadically in buildbot
The real problem here was inconsistent handling of entry->commit_errno in
MYSQL_BIN_LOG::write_transaction_or_stmt(). Some return paths were setting it
to the value of errno, some where not. And the setting was redundant anyway,
as it is set consistently by the caller.

Fix by consistently setting it in the caller, and not in each return path in
the function.

The test failure happened because a DBUG_EXECUTE_IF() used in the test case
set an entry->commit_errno that was immediately overwritten in the caller with
whatever happened to be the value of errno. This could lead to different error
message in the .result file.
2014-11-17 08:53:42 +01:00
Alexey Botchkov
c9742ceac5 MDEV-6883 ST_WITHIN crashes server if (0,0) is matched to POLYGON((0 0)).
Fixed the case when a polygon contains a single-point ring.
2014-11-15 21:30:16 +04:00
Sergei Golubchik
81d7e2f61c MDEV-7003 test-alter-table crashes debug build due to double free of plugin
correct the buffer boundary check
2014-11-13 13:40:19 +01:00
Sergei Golubchik
6a2c170141 MDEV-6849 ON UPDATE CURRENT_TIMESTAMP doesn't always work
reset default fields not for every modified row, but only once,
at the beginning, as the set of modified fields doesn't change.

exception: INSERT ... ON DUPLICATE KEY UPDATE - the set of fields
does change per row and in that case we reset default fields per row.
2014-11-13 13:40:11 +01:00
Sergey Petrunya
50c5339272 MDEV-7068: MRR accessing uninitialised bytes, test case failure main.innodb_mrr
Backport to 5.3:
- Don't call index_reader->interrupt_read() if the
  index reader has returned all rows that matched its keys.
2014-11-13 14:12:41 +03:00
Kristian Nielsen
26b1113032 MDEV-6917: Parallel replication: "Commit failed due to failure of an earlier commit on which this one depends", but no prior failure seen
This bug was seen when parallel replication experienced a deadlock between
transactions T1 and T2, where T2 has reached the commit phase and is waiting
for T1 to commit first. In this case, the deadlock is broken by sending a kill
to T2; that kill error is then later detected and converted to a deadlock
error, which causes T2 to be rolled back and retried.

The problem was that the kill caused ha_commit_trans() to errorneously call
wakeup_subsequent_commits() on T3, signalling it to abort because T2 failed
during commit. This is incorrect, because the error in T2 is only a temporary
error, which will be resolved by normal transaction retry. We should not
signal error to the next transaction until we have executed the code that
handles such temporary errors.

So this patch just removes the calls to wakeup_subsequent_commits() from
ha_commit_trans(). They are incorrect in this case, and they are not needed in
general, as wakeup_subsequent_commits() must in any case be called in
finish_event_group() to wakeup any transactions that may have started to wait
after ha_commit_trans(). And normally, wakeup will in fact have happened
earlier, either from the binlog group commit code, or (in case of no
binlogging) after the fast part of InnoDB/XtraDB group commit.

The symptom of this bug was that replication would break on some transaction
with "Commit failed due to failure of an earlier commit on which this one
depends", but with no such failure of an earlier commit visible anywhere.
2014-11-13 11:01:31 +01:00
Kristian Nielsen
3dcd01e5e6 MDEV-7065: Incorrect relay log position in parallel replication after retry of transaction
The retry of an event group in parallel replication set the wrong value for
the end log position of the event that was retried
(qev->future_event_relay_log_pos). It was too large by the size of the event,
so it pointed into the middle of the following event.

If the retry happened in the very last event of the event group, _and_ the SQL
thread was stopped just after successfully retrying that event, then the SQL
threads's relay log position would be left incorrect. Restarting the SQL
thread could then try to read events from a garbage offset in the relay log,
usually leading to an error about not being able to read the event.
2014-11-13 10:46:09 +01:00
Kristian Nielsen
d08b893b39 MDEV-6775: Wrong binlog order in parallel replication: Intermediate commit
The code in binlog group commit around wait_for_commit that controls commit
order, did the wakeup of subsequent commits early, as soon as a following
transaction is put into the group commit queue, but before any such commit has
actually taken place. This causes problems with too early wakeup of
transactions that need to wait for prior to commit, but do not take part in
the binlog group commit for one reason or the other.

This patch solves the problem, by moving the wakeup to happen only after the
binlog group commit is completed.

This requires a new solution to ensure that transactions that arrive later
than the leader are still able to participate in group commit. This patch
introduces a flag wait_for_commit::commit_started. When this is set, a waiter
can queue up itself in the group commit queue.

This way, effectively the wait_for_prior_commit() is skipped only for
transactions that participate in group commit, so that skipping the wait is
safe. Other transactions still wait as needed for correctness.
2014-11-13 10:31:20 +01:00
Kristian Nielsen
eec04fb4f6 MDEV-6680: Performance of domain_parallel replication is disappointing
The code that handles free lists of various objects passed to worker threads
in parallel replication handles freeing in batches, to avoid taking and
releasing LOCK_rpl_thread too often. However, it was possible for freeing to
be delayed to the point where one thread could stall the SQL driver thread due
to full queue, while other worker threads might be idle. This could
significantly degrade possible parallelism and thus performance.

Clean up the batch freeing code so that it is more robust and now able to
regularly free batches of object, so that normally the queue will not run full
unless the SQL driver thread is really far ahead of the worker threads.
2014-11-13 10:20:48 +01:00
Kristian Nielsen
8a3e2f29bb MDEV-6718: Server crashed in Gtid_log_event::Gtid_log_event with parallel replication
The bug occured in parallel replication when re-trying transactions that
failed due to deadlock. In this case, the relay log file is re-opened and the
events are read out again. This reading requires a format description event of
the appropriate version. But the code was using a description event stored in
rli, which is not thread-safe. This could lead to various rare races if the
format description event was replaced by the SQL driver thread at the exact
moment where a worker thread was trying to use it.

The fix is to instead make the retry code create and maintain its own format
description event. When the relay log file is opened, we first read the format
description event from the start of the file, before seeking to the current
position. This now uses the same code as when the SQL driver threads starts
from a given relay log position. This also makes sure that the correct format
description event version will be used in cases where the version of the
binlog could change during replication.
2014-11-13 10:09:46 +01:00
Kristian Nielsen
a98a034c5e MDEV-7102: Incorrect PSI_stage_info message in SHOW PROCESSLIST during parallel replication
In parallel replication, threads can do two different waits for a prior
transaction. One is for the prior transaction to start commit, the other is
for it to complete commit.

It turns out that the same PSI_stage_info message was errorneously used in
both cases (probably a merge error), causing SHOW PROCESSLIST to be
misleading.

Fix by using correct, distinct message in each case.
2014-11-13 09:56:28 +01:00
Kristian Nielsen
684715a269 MDEV-6775: Wrong binlog order in parallel replication
In parallel replication, the wait_for_commit facility is used to ensure that
events are written into the binlog in the correct order. This is handled in an
optimised way in the binlogging group commit code.

However, some statements, for example GRANT, are written directly into the
binlog, outside of the group commit code. There was a bug that this direct
write does not correctly wait for the prior transactions to have been written
first, which allows f.ex. GRANT to be written ahead of earlier transactions.

This patch adds the missing wait_for_prior_commit() before writing directly to
the binlog.

However, the problem is still there, although the race is much less likely to
occur now. The problem is that the optimised group commit code does wakeup of
following transactions early, before the binlog write is actually done. A
woken-up following transaction is then allowed to run ahead and queue up for
the group commit, which will ensure that binlog write happens in correct order
in the end. However, the code for directly written events currently bypass
this mechanism, so they get woken up and written too early.

This will be fixed properly in a later patch.
2014-11-13 09:49:07 +01:00
Kristian Nielsen
55791c1a77 Revert incorrect/redundant fix for old BUG#34656
The real bug was that open_tables() returned error in case of
thd->killed() without properly calling thd->send_kill_message()
to set the correct error. This was fixed some time ago.

So remove the, now redundant, extra checks for thd->is_error(),
possibly allowing to catch in debug builds more incorrect
error handling cases.
2014-11-13 09:20:40 +01:00
Kristian Nielsen
fbc8768ce5 MDEV-7101: SAFE_MUTEX lock order warning when reusing wait_for_commit mutex
In SAFE_MUTEX builds, reset the wait_for_commit mutex (destroy and
re-initialise), so that SAFE_MUTEX lock order check does not become
confused when the mutex is re-used for a different purpose.
2014-11-13 09:19:12 +01:00
Tor Didriksen
9bd6e87545 Bug#19890133 MAKE DIST USING BZR EXPORT EVEN FOR SOURCE DIR NOT A BZR REPO
For 'make dist': only use 'bzr export' if bzr root == ${CMAKE_SOURCE_DIR}
Same thing for git.
2014-11-11 10:58:47 +01:00
Sergei Golubchik
815667086c sql_update.cc: always update default fields *after* compare_record()
(it was *after* in two cases and *before* in one case)
2014-11-11 10:39:35 +01:00
Alexander Barkov
9e8202013a MDEV-6965 non-captured group \2 in regexp_replace 2014-11-10 16:43:27 +04:00
Sergei Golubchik
360c49c1b9 MDEV-6179: dynamic columns functions/cast()/convert() doesn't play nice with CREATE/ALTER TABLE
When parsing a field declaration, grab type information from LEX before it's overwritten
by further rules. Pass type information through the parser stack to the rule that needs it.
2014-11-08 19:54:42 +01:00
Alexander Barkov
e072a647d9 MDEV-6865 Merge Bug#18935421 RPAD DIES WITH CERTAIN PADSTR INTPUTS.. 2014-11-17 17:24:04 +04:00
unknown
e7c356f717 MDEV-6868: MariaDB server crash ( select with union and order by with subquery )
Excluding ORDER BY condition should be done after preparation it (even to catch syntax errors).
2014-11-15 22:18:33 +01:00
Sergey Petrunya
06c7f493e3 MDEV-7068: MRR accessing uninitialised bytes, test case failure main.innodb_mrr
- Don't call index_reader->interrupt_read() if the
  index reader has returned all rows that matched its keys.
2014-11-13 13:56:35 +03:00
Alexander Barkov
b84a892fb2 MDEV-7019 String::chop() is wrong and may potentially crash (MySQL bug#56492)
Merging a fix from the upstream.
2014-11-10 18:08:17 +04:00
Sergei Golubchik
2160646c1d 5.5 merge 2014-11-03 17:47:37 +01:00
mithun
73b99f055e Bug #19372926 : 5.5.38 FAILS FUNC_MATH MTR TEST.
Issue :
-------
This seems for some platform -(LONGLONG_MIN) is
not flagged as out of range.

Fix:
----
Fix is backported from mysql-5.6 bug 14314156.
Fixed by adding an explicit test for this value in
Item_func_neg::int_op().

sql/item_func.cc:
  For some platforms we need special handling of
  LONGLONG_MIN to guarantee overflow.
2014-11-03 18:10:28 +05:30
mithun
c5dfdec568 Bug #19372926 : 5.5.38 FAILS FUNC_MATH MTR TEST.
Issue :
-------
This seems for some platform -(LONGLONG_MIN) is
not flagged as out of range.

Fix:
----
Fix is backported from mysql-5.6 bug 14314156.
Fixed by adding an explicit test for this value in
Item_func_neg::int_op().
2014-11-03 18:10:28 +05:30
Alexander Barkov
d1ca1c1fae MDEV-7001 Bad result for NOT NOT STRCMP('a','b') and NOT NOT NULLIF(2,3)
The bug is not very important per se, but it was helpful to move
Item_func_strcmp out of Item_bool_func2 (to Item_int_func),
for the purposes of "MDEV-4912 Add a plugin to field types (column types)".
2014-11-02 01:08:09 +04:00
unknown
ee309b10b8 Cleanup. 2014-10-31 14:07:29 +01:00
Sergey Petrunya
e4521f8cae Merge 2014-10-29 15:20:46 +03:00
Sergey Petrunya
30b28babdc Merge 5.3->5.5 2014-10-29 13:22:48 +03:00
Igor Babaev
100b10d8ef Fixed bug mdev-6843.
The function  get_column_range_cardinality() returned a wrong result for any column
containing only null values.
2014-10-28 22:31:52 -07:00
Igor Babaev
2d088e265c Merge 2014-10-28 16:31:26 -07:00
Sergey Petrunya
a8341dfd6e MDEV-6879: Dereference of NULL primary_file->table in DsMrr_impl::get_disk_sweep_mrr_cost()
(Backport to 5.3)
(Attempt #2)
- Don't attempt to use BKA for materialized derived tables. The 
  table is neither filled nor fully opened yet, so attempt to 
  call handler->multi_range_read_info() causes crash.
2014-10-29 01:46:05 +03:00
Sergey Petrunya
9cb002b359 MDEV-6878: Use of uninitialized saved_primary_key in Mrr_ordered_index_reader::resume_read()
(Backport to 5.3)
(variant #2, with fixed coding style)
- Make Mrr_ordered_index_reader::resume_read() restore index position 
  only if it was saved before with Mrr_ordered_index_reader::interrupt_read().
2014-10-29 01:37:58 +03:00
Sergey Petrunya
94c8f33569 MDEV-6888: Query spends a long time in best_extension_by_limited_search with mrr enabled
- TABLE::create_key_part_by_field() should not set PART_KEY_FLAG in field->flags
  = The reason is that it is used by hash join code which calls it to create a hash
    table lookup structure. It doesn't create a real index.
  = Another caller of the function is TABLE::add_tmp_key(). Made it to set the flag itself.

- The differences in join_cache.result could also be observed before this patch: one
  could put "FLUSH TABLES" before the queries and get exactly the same difference.
2014-10-29 01:20:45 +03:00
Igor Babaev
592b7fbac9 Fixed bug mdev-6325.
Field::selectivity should be set for all fields used in range conditions.
2014-10-28 14:33:31 -07:00
Sergey Petrunya
bb58a18b86 Better comments 2014-10-23 12:31:13 +04:00
Sergey Petrunya
135bf1fcfb Merge 2014-10-21 00:02:24 +04:00
Sergey Petrunya
1a996bde1e MDEV-6879: Dereference of NULL primary_file->table in DsMrr_impl::get_disk_sweep_mrr_cost()
(Attempt #2)
- Don't attempt to use BKA for materialized derived tables. The 
  table is neither filled nor fully opened yet, so attempt to 
  call handler->multi_range_read_info() causes crash.
2014-10-20 23:35:34 +04:00
Alexander Barkov
81194d9203 MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zero_date_time_cast 2014-10-20 16:42:00 +04:00
Sergey Petrunya
ad66fafbbb Merge 2014-10-29 14:22:25 +03:00
Kristian Nielsen
64af1ecc20 Fix two races in test main.processlist that could cause random failures (seen in Buildbot)
1. Do not use NULL `info' field in processlist to select the thread of
interest. This can fail if the read of processlist ends up happening after
REAP succeeds, but before the `info' field is reset. Instead, select on the
CONNECTION_ID(), making sure we still scan the whole list to trigger the same
code as in the original test case.

2. Wait for the query to really complete before reading it in the
processlist. When REAP returns, it only means that ack has been sent to
client, the reset of query stage happens a bit later in the code.
2014-10-22 13:51:33 +02:00
Sergey Petrunya
af4d469a8d MDEV-6879: Dereference of NULL primary_file->table in DsMrr_impl::get_disk_sweep_mrr_cost()
- Don't attempt to use BKA for materialized derived tables. The 
  table is neither filled nor fully opened yet, so attempt to 
  call handler->multi_range_read_info() causes crash.
2014-10-16 22:58:08 +04:00
Sergey Petrunya
8925b4a935 MDEV-6878: Use of uninitialized saved_primary_key in Mrr_ordered_index_reader::resume_read()
- Make Mrr_ordered_index_reader::resume_read() restore index position 
  only if it was saved before with Mrr_ordered_index_reader::interrupt_read().
2014-10-16 17:57:13 +04:00
Sergey Petrunya
b261ec393a MDEV-6484: Assertion `tab->ref.use_count' failed on query with joins, constant table, multi-part key
- test_if_skip_sort_order()/create_ref_for_key() may change table 
  access from EQ_REF(index1) to REF(index2). 
- Doing so doesn't make much sense from optimization POV, but since 
  they are doing it, they should update tab->read_record.unlock_row
  accordingly.
2014-10-14 15:11:06 +04:00
Jon Olav Hauglid
57eec7bc29 Bug#17633291: SET PROPER COMPILE OPTIONS FOR CLANG
Bug#17959689: MAKE GCC AND CLANG GIVE CONSISTENT COMPILATION WARNINGS
Bug#18313717: ENABLE -WERROR IN MAINTANER MODE WHEN COMPILING WITH CLANG
Bug#18510941: REMOVE CMAKE WORKAROUNDS FOR OLDER VERSIONS OF OS X/XCODE
  
Backport from mysql-5.6 to mysql-5.5
2014-10-13 09:52:28 +02:00
Jon Olav Hauglid
8b64f82505 Bug#17633291: SET PROPER COMPILE OPTIONS FOR CLANG
Bug#17959689: MAKE GCC AND CLANG GIVE CONSISTENT COMPILATION WARNINGS
Bug#18313717: ENABLE -WERROR IN MAINTANER MODE WHEN COMPILING WITH CLANG
Bug#18510941: REMOVE CMAKE WORKAROUNDS FOR OLDER VERSIONS OF OS X/XCODE
  
Backport from mysql-5.6 to mysql-5.5
2014-10-13 09:52:28 +02:00
Sergei Golubchik
911ed9379f merge 2014-10-11 12:52:55 +02:00
Sergey Petrunya
1b960d9fd6 MDEV-6519: Assertion `join->best_read < double(...)' failed after adding a key to a TokuDB table...
- calculate_cond_selectivity_for_table() should handle the case
  where index statistics is not available (zeros are returned 
  in rec_per_key)
2014-10-10 23:52:47 +04:00
Sergei Golubchik
ba85a008e4 merge 2014-10-10 20:59:06 +02:00
Sergei Golubchik
1b75bed00f 5.5.40+ merge 2014-10-09 10:30:11 +02:00
Venkatesh Duggirala
0827d75627 Bug #18808072 MYSQLBINLOG USES LOCALTIME() TO PRINT EVENTS, CAUSES KERNEL MUTEX CONTENTION
Problem: For every event read, mysqlbinlog calls localtime() which in turn
calls stat(/etc/localtime) which is causing kernel mutex contention.

Analysis and Fix:
localtime() calls stat(/etc/localtime) for every instance of the call
where as localtime_r() the reentrant version was optimized to store
the read only tz internal structure. Hence it will not call
stat(/etc/localtime). It will call only once at the beginning.
The mysql server is calling localtime_r() and mysqlbinlog tool is
one place where we are still using localtime().

Once the process (mysqlbinlog) is started if timezone is changed
it will be not picked up the the process and it will continue
with the same values as the beginning of the process. This
behavior is in-lined with mysql server.

Also adding localtime_r() and gmtime_r() support for windows.
2014-10-08 21:54:35 +05:30
Venkatesh Duggirala
a3cc647dbd Bug #18808072 MYSQLBINLOG USES LOCALTIME() TO PRINT EVENTS, CAUSES KERNEL MUTEX CONTENTION
Problem: For every event read, mysqlbinlog calls localtime() which in turn
calls stat(/etc/localtime) which is causing kernel mutex contention.

Analysis and Fix:
localtime() calls stat(/etc/localtime) for every instance of the call
where as localtime_r() the reentrant version was optimized to store
the read only tz internal structure. Hence it will not call
stat(/etc/localtime). It will call only once at the beginning.
The mysql server is calling localtime_r() and mysqlbinlog tool is
one place where we are still using localtime().

Once the process (mysqlbinlog) is started if timezone is changed
it will be not picked up the the process and it will continue
with the same values as the beginning of the process. This
behavior is in-lined with mysql server.

Also adding localtime_r() and gmtime_r() support for windows.
2014-10-08 21:54:35 +05:30
Sujatha Sivakumar
9296809134 Bug#19145698: READ OUT OF BOUNDS ISSUE
Problem:
========
In a master slave replication if a slave receives a
Start_log_event_v3 the payload is expected to be of fixed
size. If a payload which is smaller than the fixed size is
received it causes a read out of bounds issue.

Analysis:
========
According to documentation the fixed data part of
Start_log_event_v3 looks as shown below.

2 bytes: The binary log format version
50 bytes: The MySQL server's version
4 bytes: Timestamp in seconds when this event was created

Since the payload is expected to be of fixed size, therefore
ST_SERVER_VER_LEN (50) bytes are memcpy'ed into
server_version. But if a malicious master sends a shorter
payload it causes a read out of bounds issue.

Fix:
===
In Start_log_event_v3 event's constructor a check has been
added which expects the minimum payload length to be of size
common_header_len + ST_COMMON_HEADER_LEN_OFFSET bytes. If a
malicious packet of lesser length is received it will be
considered as an invalid event.

sql/log_event.cc:
  Added code changes to check the minimum packet length
  of Start_log_event_v3 should be > 56.
sql/log_event.h:
  Moved server_version from stack to heap and modified
  is_valid function for Start_log_event_v3.
2014-10-08 10:50:02 +05:30
Sujatha Sivakumar
0d0c59ff80 Bug#19145698: READ OUT OF BOUNDS ISSUE
Problem:
========
In a master slave replication if a slave receives a
Start_log_event_v3 the payload is expected to be of fixed
size. If a payload which is smaller than the fixed size is
received it causes a read out of bounds issue.

Analysis:
========
According to documentation the fixed data part of
Start_log_event_v3 looks as shown below.

2 bytes: The binary log format version
50 bytes: The MySQL server's version
4 bytes: Timestamp in seconds when this event was created

Since the payload is expected to be of fixed size, therefore
ST_SERVER_VER_LEN (50) bytes are memcpy'ed into
server_version. But if a malicious master sends a shorter
payload it causes a read out of bounds issue.

Fix:
===
In Start_log_event_v3 event's constructor a check has been
added which expects the minimum payload length to be of size
common_header_len + ST_COMMON_HEADER_LEN_OFFSET bytes. If a
malicious packet of lesser length is received it will be
considered as an invalid event.
2014-10-08 10:50:02 +05:30
Sergei Golubchik
d3677c872f jemalloc compatibility 2014-10-08 00:45:41 +02:00
unknown
63ca157c92 MDEV-6781: bug with query cache when using views
The data base lenth passed to invalidator fixed
2014-10-07 19:38:45 +02:00
Sergei Golubchik
fc58ba6c76 MDEV-5553 A view or procedure with a non existing definer can block "SHOW TABLE STATUS" with an unclear error message
Don't double-check privileges for a column in the GROUP BY that refers to
the same column in SELECT clause. Privileges were already checked for SELECT clause.
2014-10-07 11:55:39 +02:00
Sergei Golubchik
1ddfce4840 mysql-5.5.40 2014-10-06 19:53:55 +02:00
Sergey Petrunya
41b45a8163 MDEV-6738: use_stat_table + histograms crashing optimizer
- When EITS code calls store_key_image_to_rec(), it should follow its 
  calling convention (which is counter-intuitive)
2014-10-10 17:08:12 +04:00
Sergey Petrunya
fd4c9af398 MDEV-6442: Assertion `join->best_read < double(...)' failed with optimizer_use_condition_selectivity >=3
- Fix the crash by making get_column_range_cardinality() 
  to handle the special case where Column_stats objects 
  is an all-zeros object (the question of what is the point
  of having Field::read_stats point to such object remains a 
  mystery)

- Added a few comments. Learning the code still.
2014-10-06 15:29:22 +04:00
Sergei Golubchik
689ffe3559 fix failing rpl.rpl_user_variables
typo fixed. use correct constant.
2014-10-05 22:07:28 +02:00
Sergei Golubchik
c0977073e1 MDEV-6743 crash in GROUP_CONCAT(IF () ORDER BY 1)
backport the new fix from 10.0
2014-10-03 23:04:25 +02:00
unknown
4af63f5d96 Bug#19553099 EXPIRE_LOGS_DAYS=1 CRASH MYSQLD DURING RESTART, DBUG_SYNC(NULL, ...)
- Restarting mysqld with --expire-log-days=1 triggers 'log_in_use()' to be called while current_thd is NULL.
 - Check current_thd before calling DEBUG_SYNC() to avoid passing NULL pointer to DEBUG_SYNC()
 - Wrap debug code construct inside #ifndef DBUG_OFF like in other parts of the file
2014-10-02 15:58:02 +02:00
magnus.blaudd@oracle.com
361ad4bd0b Bug#19553099 EXPIRE_LOGS_DAYS=1 CRASH MYSQLD DURING RESTART, DBUG_SYNC(NULL, ...)
- Restarting mysqld with --expire-log-days=1 triggers 'log_in_use()' to be called while current_thd is NULL.
 - Check current_thd before calling DEBUG_SYNC() to avoid passing NULL pointer to DEBUG_SYNC()
 - Wrap debug code construct inside #ifndef DBUG_OFF like in other parts of the file
2014-10-02 15:58:02 +02:00
Sergei Golubchik
11242006ad MDEV-6461 mysqld should not trap SIGTSTP if running with --gdb/--debug-gdb 2014-10-02 13:52:51 +02:00
Sergei Golubchik
384999f3e8 MDEV-6528 review debian patches for mysql
and apply whatever was reasonable
2014-10-02 11:58:24 +02:00
Sergei Golubchik
4a784356da cleanup: an outbreak of templatonia cured. 2014-09-30 17:06:02 +02:00
Sergei Golubchik
9fe7feb8bb fix more sql_command_flags:
SQLCOM_ASSIGN_TO_KEYCACHE should not be CF_AUTO_COMMIT_TRANS
  SQLCOM_PRELOAD_KEYS should not be CF_AUTO_COMMIT_TRANS
  SQLCOM_INSTALL_PLUGIN should need CF_AUTO_COMMIT_TRANS
  SQLCOM_UNINSTALL_PLUGIN should need CF_AUTO_COMMIT_TRANS
2014-09-30 15:57:38 +02:00
Sergei Golubchik
75908fc4ce BUG#13627921 - MISSING FLAGS IN SQL_COMMAND_FLAGS MAY LEAD TO REPLICATION PROBLEMS
merge from MySQL-5.6, revision:

revno: 3677.2.1
committer: Alfranio Correia <alfranio.correia@oracle.com>
timestamp: Tue 2012-02-28 16:26:37 +0000
message:
  BUG#13627921 - MISSING FLAGS IN SQL_COMMAND_FLAGS MAY LEAD TO REPLICATION PROBLEMS

  Flags in sql_command_flags[command] are not correctly set for the following
  commands:

    . SQLCOM_SET_OPTION is missing CF_CAN_GENERATE_ROW_EVENTS;
    . SQLCOM_BINLOG_BASE64_EVENT is missing CF_CAN_GENERATE_ROW_EVENTS;
    . SQLCOM_REVOKE_ALL is missing CF_CHANGES_DATA;
    . SQLCOM_CREATE_FUNCTION is missing CF_AUTO_COMMIT_TRANS;

  This may lead to a wrong sequence of events in the binary log. To fix
  the problem, we correctly set the flags in sql_command_flags[command].
2014-09-30 15:55:02 +02:00
Michael Widenius
213a4a9304 Auto merge 2014-09-30 20:43:14 +03:00
Michael Widenius
70823e1d91 MDEV-5120 Test suite test maria-no-logging fails
The reason for the failure was a bug in an include file on debian that causes 'struct stat'
to have different sized depending on the environment.

This patch fixes so that we always include my_global.h or my_config.h before we include any other files.

Other things:
- Removed #include <my_global.h> in some include files; Better to always do this at the top level to have as few
  "always-include-this-file-first' files as possible.
- Removed usage of some include files that where already included by my_global.h or by other files.


client/mysql_plugin.c:
  Use my_global.h first
client/mysqlslap.c:
  Remove duplicated include files
extra/comp_err.c:
  Remove duplicated include files
include/m_string.h:
  Remove duplicated include files
include/maria.h:
  Remove duplicated include files
libmysqld/emb_qcache.cc:
  Use my_global.h first
plugin/semisync/semisync.h:
  Use my_pthread.h first
sql/datadict.cc:
  Use my_global.h first
sql/debug_sync.cc:
  Use my_global.h first
sql/derror.cc:
  Use my_global.h first
sql/des_key_file.cc:
  Use my_global.h first
sql/discover.cc:
  Use my_global.h first
sql/event_data_objects.cc:
  Use my_global.h first
sql/event_db_repository.cc:
  Use my_global.h first
sql/event_parse_data.cc:
  Use my_global.h first
sql/event_queue.cc:
  Use my_global.h first
sql/event_scheduler.cc:
  Use my_global.h first
sql/events.cc:
  Use my_global.h first
sql/field.cc:
  Use my_global.h first
  Remove duplicated include files
sql/field_conv.cc:
  Use my_global.h first
sql/filesort.cc:
  Use my_global.h first
  Remove duplicated include files
sql/gstream.cc:
  Use my_global.h first
sql/ha_ndbcluster.cc:
  Use my_global.h first
sql/ha_ndbcluster_binlog.cc:
  Use my_global.h first
sql/ha_ndbcluster_cond.cc:
  Use my_global.h first
sql/ha_partition.cc:
  Use my_global.h first
sql/handler.cc:
  Use my_global.h first
sql/hash_filo.cc:
  Use my_global.h first
sql/hostname.cc:
  Use my_global.h first
sql/init.cc:
  Use my_global.h first
sql/item.cc:
  Use my_global.h first
sql/item_buff.cc:
  Use my_global.h first
sql/item_cmpfunc.cc:
  Use my_global.h first
sql/item_create.cc:
  Use my_global.h first
sql/item_geofunc.cc:
  Use my_global.h first
sql/item_inetfunc.cc:
  Use my_global.h first
sql/item_row.cc:
  Use my_global.h first
sql/item_strfunc.cc:
  Use my_global.h first
sql/item_subselect.cc:
  Use my_global.h first
sql/item_sum.cc:
  Use my_global.h first
sql/item_timefunc.cc:
  Use my_global.h first
sql/item_xmlfunc.cc:
  Use my_global.h first
sql/key.cc:
  Use my_global.h first
sql/lock.cc:
  Use my_global.h first
sql/log.cc:
  Use my_global.h first
sql/log_event.cc:
  Use my_global.h first
sql/log_event_old.cc:
  Use my_global.h first
sql/mf_iocache.cc:
  Use my_global.h first
sql/mysql_install_db.cc:
  Remove duplicated include files
sql/mysqld.cc:
  Remove duplicated include files
sql/net_serv.cc:
  Remove duplicated include files
sql/opt_range.cc:
  Use my_global.h first
sql/opt_subselect.cc:
  Use my_global.h first
sql/opt_sum.cc:
  Use my_global.h first
sql/parse_file.cc:
  Use my_global.h first
sql/partition_info.cc:
  Use my_global.h first
sql/procedure.cc:
  Use my_global.h first
sql/protocol.cc:
  Use my_global.h first
sql/records.cc:
  Use my_global.h first
sql/records.h:
  Don't include my_global.h
  Better to do this at the upper level
sql/repl_failsafe.cc:
  Use my_global.h first
sql/rpl_filter.cc:
  Use my_global.h first
sql/rpl_gtid.cc:
  Use my_global.h first
sql/rpl_handler.cc:
  Use my_global.h first
sql/rpl_injector.cc:
  Use my_global.h first
sql/rpl_record.cc:
  Use my_global.h first
sql/rpl_record_old.cc:
  Use my_global.h first
sql/rpl_reporting.cc:
  Use my_global.h first
sql/rpl_rli.cc:
  Use my_global.h first
sql/rpl_tblmap.cc:
  Use my_global.h first
sql/rpl_utility.cc:
  Use my_global.h first
sql/set_var.cc:
  Added comment
sql/slave.cc:
  Use my_global.h first
sql/sp.cc:
  Use my_global.h first
sql/sp_cache.cc:
  Use my_global.h first
sql/sp_head.cc:
  Use my_global.h first
sql/sp_pcontext.cc:
  Use my_global.h first
sql/sp_rcontext.cc:
  Use my_global.h first
sql/spatial.cc:
  Use my_global.h first
sql/sql_acl.cc:
  Use my_global.h first
sql/sql_admin.cc:
  Use my_global.h first
sql/sql_analyse.cc:
  Use my_global.h first
sql/sql_audit.cc:
  Use my_global.h first
sql/sql_base.cc:
  Use my_global.h first
sql/sql_binlog.cc:
  Use my_global.h first
sql/sql_bootstrap.cc:
  Use my_global.h first
  Use my_global.h first
sql/sql_cache.cc:
  Use my_global.h first
sql/sql_class.cc:
  Use my_global.h first
sql/sql_client.cc:
  Use my_global.h first
sql/sql_connect.cc:
  Use my_global.h first
sql/sql_crypt.cc:
  Use my_global.h first
sql/sql_cursor.cc:
  Use my_global.h first
sql/sql_db.cc:
  Use my_global.h first
sql/sql_delete.cc:
  Use my_global.h first
sql/sql_derived.cc:
  Use my_global.h first
sql/sql_do.cc:
  Use my_global.h first
sql/sql_error.cc:
  Use my_global.h first
sql/sql_explain.cc:
  Use my_global.h first
sql/sql_expression_cache.cc:
  Use my_global.h first
sql/sql_handler.cc:
  Use my_global.h first
sql/sql_help.cc:
  Use my_global.h first
sql/sql_insert.cc:
  Use my_global.h first
sql/sql_lex.cc:
  Use my_global.h first
sql/sql_load.cc:
  Use my_global.h first
sql/sql_locale.cc:
  Use my_global.h first
sql/sql_manager.cc:
  Use my_global.h first
sql/sql_parse.cc:
  Use my_global.h first
sql/sql_partition.cc:
  Use my_global.h first
sql/sql_plugin.cc:
  Added comment
sql/sql_prepare.cc:
  Use my_global.h first
sql/sql_priv.h:
  Added error if we use this before including my_global.h
  This check is here becasue so many files includes sql_priv.h first.
sql/sql_profile.cc:
  Use my_global.h first
sql/sql_reload.cc:
  Use my_global.h first
sql/sql_rename.cc:
  Use my_global.h first
sql/sql_repl.cc:
  Use my_global.h first
sql/sql_select.cc:
  Use my_global.h first
sql/sql_servers.cc:
  Use my_global.h first
sql/sql_show.cc:
  Added comment
sql/sql_signal.cc:
  Use my_global.h first
sql/sql_statistics.cc:
  Use my_global.h first
sql/sql_table.cc:
  Use my_global.h first
sql/sql_tablespace.cc:
  Use my_global.h first
sql/sql_test.cc:
  Use my_global.h first
sql/sql_time.cc:
  Use my_global.h first
sql/sql_trigger.cc:
  Use my_global.h first
sql/sql_udf.cc:
  Use my_global.h first
sql/sql_union.cc:
  Use my_global.h first
sql/sql_update.cc:
  Use my_global.h first
sql/sql_view.cc:
  Use my_global.h first
sql/sys_vars.cc:
  Added comment
sql/table.cc:
  Use my_global.h first
sql/thr_malloc.cc:
  Use my_global.h first
sql/transaction.cc:
  Use my_global.h first
sql/uniques.cc:
  Use my_global.h first
sql/unireg.cc:
  Use my_global.h first
sql/unireg.h:
  Removed inclusion of my_global.h
storage/archive/ha_archive.cc:
  Added comment
storage/blackhole/ha_blackhole.cc:
  Use my_global.h first
storage/csv/ha_tina.cc:
  Use my_global.h first
storage/csv/transparent_file.cc:
  Use my_global.h first
storage/federated/ha_federated.cc:
  Use my_global.h first
storage/federatedx/federatedx_io.cc:
  Use my_global.h first
storage/federatedx/federatedx_io_mysql.cc:
  Use my_global.h first
storage/federatedx/federatedx_io_null.cc:
  Use my_global.h first
storage/federatedx/federatedx_txn.cc:
  Use my_global.h first
storage/heap/ha_heap.cc:
  Use my_global.h first
storage/innobase/handler/handler0alter.cc:
  Use my_global.h first
storage/maria/ha_maria.cc:
  Use my_global.h first
storage/maria/unittest/ma_maria_log_cleanup.c:
  Remove duplicated include files
storage/maria/unittest/test_file.c:
  Added comment
storage/myisam/ha_myisam.cc:
  Move sql_plugin.h first as this includes my_global.h
storage/myisammrg/ha_myisammrg.cc:
  Use my_global.h first
storage/oqgraph/oqgraph_thunk.cc:
  Use my_config.h and my_global.h first
  One could not include my_global.h before oqgraph_thunk.h (don't know why)
storage/spider/ha_spider.cc:
  Use my_global.h first
storage/spider/hs_client/config.cpp:
  Use my_global.h first
storage/spider/hs_client/escape.cpp:
  Use my_global.h first
storage/spider/hs_client/fatal.cpp:
  Use my_global.h first
storage/spider/hs_client/hstcpcli.cpp:
  Use my_global.h first
storage/spider/hs_client/socket.cpp:
  Use my_global.h first
storage/spider/hs_client/string_util.cpp:
  Use my_global.h first
storage/spider/spd_conn.cc:
  Use my_global.h first
storage/spider/spd_copy_tables.cc:
  Use my_global.h first
storage/spider/spd_db_conn.cc:
  Use my_global.h first
storage/spider/spd_db_handlersocket.cc:
  Use my_global.h first
storage/spider/spd_db_mysql.cc:
  Use my_global.h first
storage/spider/spd_db_oracle.cc:
  Use my_global.h first
storage/spider/spd_direct_sql.cc:
  Use my_global.h first
storage/spider/spd_i_s.cc:
  Use my_global.h first
storage/spider/spd_malloc.cc:
  Use my_global.h first
storage/spider/spd_param.cc:
  Use my_global.h first
storage/spider/spd_ping_table.cc:
  Use my_global.h first
storage/spider/spd_sys_table.cc:
  Use my_global.h first
storage/spider/spd_table.cc:
  Use my_global.h first
storage/spider/spd_trx.cc:
  Use my_global.h first
storage/xtradb/handler/handler0alter.cc:
  Use my_global.h first
storage/xtradb/handler/i_s.cc:
  Use my_global.h first
2014-09-30 20:31:14 +03:00
Sergey Petrunya
5a677749cb MDEV-6808, part#2.
Fix apparently-wrong code in table_multi_eq_selectivity().
2014-09-30 21:28:36 +04:00
Michael Widenius
caca6b9907 Fixed warnings
storage/oqgraph/ha_oqgraph.cc:
  Fixed compiler warning
storage/xtradb/handler/ha_innodb.cc:
  Ifdef:ed note used function
2014-09-30 20:12:59 +03:00
Sergey Petrunya
9aeeba4864 MDEV-6808: MariaDB 10.0.13 crash with optimizer_use_condition_selectivity > 1
Fix a trivial typo: in table_multi_eq_cond_selectivity(), reset the loop variable
between loops.
2014-09-30 21:11:03 +04:00
Sergey Petrunya
4630732f25 MDEV-6799: Crash in field_conv, memcpy_field_possible
- Fix the crash, dont call from->type() at the start of the function
  because it might be unsafe.
- Unfortunately there is no testcase
- And this is also the reason we can't fix it properly (it should be
  safe to call from->type() here).
2014-09-26 18:48:40 +04:00
Alexander Barkov
68354ef272 MDEV-6592 Assertion `ltime->day == 0' failed with TIMESTAMP, MAKETIME 2014-10-03 15:07:53 +04:00
Sergey Petrunya
1f437f3e8c MDEV-6788: The variable 'role' is being used without being initialized at sql_acl.cc:8840
Second variant of the fix: reduce the scope of 'role' variable
2014-09-25 19:12:52 +04:00
Sergey Petrunya
949989e5ff MDEV-6788: The variable 'role' is being used without being initialized at sql_acl.cc:8840
Don't check the value of 'role' variable in the cases where we don't need it. (it 
may be marked as unitialized and we get a runtime error).
2014-09-25 18:16:29 +04:00
Sergey Vojtovich
b737d902a8 MDEV-6774 - Deadlock between SELECT, DROP TABLE, SHOW STATUS and
SET @@global.log_output

Deadlock chain:
rdlock(LOCK_logger) -> lock(LOCK_open)     SELECT 1
lock(LOCK_open)     -> lock(LOCK_status)   DROP TABLE t1
lock(LOCK_status)   -> lock(LOCK_g_s_v)    SHOW STATUS
lock(LOCK_g_s_)     -> wrlock(LOCK_logger) SET @@global.log_output=DEFAULT

Fixed by removing relationship between LOCK_status and
LOCK_global_system_variables during SHOW STATUS: we don't really need
LOCK_global_system_variables when accessing status vars.
2014-09-25 10:43:11 +04:00
Sergei Golubchik
f1afc003ee MDEV-6743 crash in GROUP_CONCAT(IF () ORDER BY 1)
new fix
2014-09-24 15:41:42 +02:00
Sergei Golubchik
9fa62b47f0 remove the bug fix for MDEV-6743 "crash in GROUP_CONCAT(IF () ORDER BY 1)"
but keep the test case - it succeeds in 10.0 without the fix
2014-09-24 13:08:47 +02:00
Bill Qu
cdb8e6ed38 Bug #15868071 USING SET GLOBAL SQL_LOG_BIN SHOULD NOT BE ALLOWED
Normally, SET SESSION SQL_LOG_BIN is used by DBAs to run a
non-conflicting command locally only, ensuring it does not
get replicated.
Setting GLOBAL SQL_LOG_BIN would not require all sessions to
disconnect. When SQL_LOG_BIN is changed globally, it does not
immediately take effect for any sessions. It takes effect by
becoming the session-level default inherited at the start of
each new session, and this setting is kept and cached for the
duration of that session. Setting it intentionally is unlikely
to have a useful effect under any circumstance; setting it
unintentionally, such as while intending to use SET [SESSION]
is potentially disastrous. Accidentally using SET GLOBAL
SQL_LOG_BIN will not show an immediate effect to the user,
instead not having the desired session-level effect, and thus
causing other potential problems with local-only maintenance
being binlogged and executed on slaves; And transactions from
new sessions (after SQL_LOG_BIN is changed globally) are not
binlogged and replicated, which would result in irrecoverable
or difficult data loss.
This is the regular GLOBAL variables way to work, but in
replication context it does not look right on a working server
(with connected sessions) 'set global sql_log_bin' and none of
that connections is affected. Unexperienced DBA after noticing
that the command did "nothing" will change the session var and
most probably won't unset the global var, causing new sessions
to not be binlog.
Setting GLOBAL SQL_LOG_BIN allows DBA to stop binlogging on all
new sessions, which can be used to make a server "replication
read-only" without restarting the server. But this has such big
requirements, stop all existing connections, that it is more
likely to make a mess, it is too risky to allow the GLOBAL variable.

The statement 'SET GLOBAL SQL_LOG_BIN=N' will produce an error
in 5.5, 5.6 and 5.7. Reading the GLOBAL SQL_LOG_BIN will produce
a deprecation warning in 5.7.
2014-09-24 09:44:48 +08:00
Bill Qu
5693b1e4a4 Bug #15868071 USING SET GLOBAL SQL_LOG_BIN SHOULD NOT BE ALLOWED
Normally, SET SESSION SQL_LOG_BIN is used by DBAs to run a
non-conflicting command locally only, ensuring it does not
get replicated.
Setting GLOBAL SQL_LOG_BIN would not require all sessions to
disconnect. When SQL_LOG_BIN is changed globally, it does not
immediately take effect for any sessions. It takes effect by
becoming the session-level default inherited at the start of
each new session, and this setting is kept and cached for the
duration of that session. Setting it intentionally is unlikely
to have a useful effect under any circumstance; setting it
unintentionally, such as while intending to use SET [SESSION]
is potentially disastrous. Accidentally using SET GLOBAL
SQL_LOG_BIN will not show an immediate effect to the user,
instead not having the desired session-level effect, and thus
causing other potential problems with local-only maintenance
being binlogged and executed on slaves; And transactions from
new sessions (after SQL_LOG_BIN is changed globally) are not
binlogged and replicated, which would result in irrecoverable
or difficult data loss.
This is the regular GLOBAL variables way to work, but in
replication context it does not look right on a working server
(with connected sessions) 'set global sql_log_bin' and none of
that connections is affected. Unexperienced DBA after noticing
that the command did "nothing" will change the session var and
most probably won't unset the global var, causing new sessions
to not be binlog.
Setting GLOBAL SQL_LOG_BIN allows DBA to stop binlogging on all
new sessions, which can be used to make a server "replication
read-only" without restarting the server. But this has such big
requirements, stop all existing connections, that it is more
likely to make a mess, it is too risky to allow the GLOBAL variable.

The statement 'SET GLOBAL SQL_LOG_BIN=N' will produce an error
in 5.5, 5.6 and 5.7. Reading the GLOBAL SQL_LOG_BIN will produce
a deprecation warning in 5.7.
2014-09-24 09:44:48 +08:00
Sergei Golubchik
06d6552192 5.5 merge 2014-09-23 23:55:29 +02:00
Sergei Golubchik
53a44915c5 merge 2014-09-23 23:37:35 +02:00
Michael Widenius
bab638d842 MDEV-6743 crash in GROUP_CONCAT(IF () ORDER BY 1)
mysql-test/r/func_group.result:
  Test case
mysql-test/t/func_group.test:
  Test case
sql/item_sum.cc:
  Restore ORDER for prepared statements
2014-09-23 13:57:29 +03:00
Michael Widenius
504c6cccd7 Fixed test failures
Added comments
Ensure that tokudb test works even if jemalloc is not installed
Removed not referenced function Item::remove_fixed()

mysql-test/suite/rpl/t/rpl_gtid_reconnect.test:
  Fixed race condition
sql/item.cc:
  Indentation fix
sql/item.h:
  Removed not used function
  Added comment
sql/sql_select.cc:
  Fixed indentation
storage/tokudb/mysql-test/rpl/include/have_tokudb.opt:
  Ensure that tokudb test works even if jemalloc is not installed
storage/tokudb/mysql-test/tokudb/suite.opt:
  Ensure that tokudb test works even if jemalloc is not installed
storage/tokudb/mysql-test/tokudb_add_index/suite.opt:
  Ensure that tokudb test works even if jemalloc is not installed
storage/tokudb/mysql-test/tokudb_alter_table/suite.opt:
  Ensure that tokudb test works even if jemalloc is not installed
storage/tokudb/mysql-test/tokudb_bugs/suite.opt:
  Ensure that tokudb test works even if jemalloc is not installed
storage/tokudb/mysql-test/tokudb_mariadb/suite.opt:
  Ensure that tokudb test works even if jemalloc is not installed
2014-09-22 23:25:56 +03:00
Sergei Golubchik
34f3aa9915 remove unused (obsolete) declarations from slave.h 2014-09-19 09:21:51 +02:00
Sergey Vojtovich
d1e46a50bc MDEV-6749 - Deadlock between GRANT/REVOKE, SELECT FROM I_S.COLUMNS,
SET slow_query_log and failed connection attempt

A very subtle though valid deadlock. Deadlock chain:
wrlock(LOCK_grant)    -> lock(acl_cache->lock) GRANT/REVOKE CREATE/DROP USER
lock(LOCK_open)       -> rdlock(LOCK_grant)    SELECT * FROM I_S.COLUMNS
wrlock(LOCK_logger)   -> lock(LOCK_open)       SET @@global.slow_query_log='ON'
lock(acl_cache->lock) -> rdlock(LOCK_logger)   Failed connection

Fixed by removing relationship between acl_cache->lock and LOCK_logger
during failed connection attempt.
2014-09-18 19:45:06 +04:00
Sergei Golubchik
152f1cd086 print binlog unsafe errors at log_warnings level 1, not 2. 2014-09-18 15:24:30 +02:00
Alexander Barkov
8286bcd721 MDEV-6752 Trailing incomplete characters are not replaced to question marks on conversion 2014-09-18 12:40:55 +04:00
Sergei Golubchik
c338772a59 fixes for valgrind failures
sql/item.cc:
  don't forget to adjust the length of the string when removing leading spaces
sql/sql_acl.cc:
  when updating the hostname of the ACL_USER, update the hostname_length too
sql/sql_parse.cc:
  first compare the username string, then test the host pointer
  (host pointer is undefined when the username string is one of the hard-coded values
  set by the parser). This is not a bug, old code is perfectly safe as the undefined
  host pointer is never dereferenced, but let's keep valgrind happy.
2014-09-17 19:38:42 +02:00
Sergei Golubchik
a006813fb1 merge 2014-09-16 14:08:05 +02:00
Sergei Golubchik
7e29c1b539 5.5 merge 2014-09-16 14:03:17 +02:00
Praveenkumar Hulakund
43d880b7e9 Bug#19070633 - POSSIBLE ACCESS TO FREED MEMORY IN IS_FREE_LOCK()
AND IS_USED_LOCK().

Analysis:
-----------
In functions Item_func_is_free_lock::val_int() and 
Item_func_is_used_lock::val_int(), for the specified user lock
name, pointer to its "User_level_lock" object is obtained from hash
"hash_user_locks". Mutex "LOCK_user_locks" is acquired for this
and released immediately. And we are accessing members of
User_level_lock after releasing the mutex. If same user lock is
deleted(released) from concurrent thread then accessing members
results in invalid(freed) memory access issue.

Deleting of user lock is also protected from the mutex
"LOCK_user_locks". Since this mutex is released in "val_int" 
functions mentioned above, delete operation proceeds while concurrent
thread tries to access its members.

With the test case, valgrind reports invalid read issues in val_int
functions.

Fix:
-----------
To fix this issue, in "val_int" function of classes
"Item_func_is_free_lock" and "Item_func_is_used_lock", now releasing
mutex "LOCK_user_locks" after accessing User_level_lock members.
2014-09-16 11:28:46 +05:30
Praveenkumar Hulakund
508c74ac25 Bug#19070633 - POSSIBLE ACCESS TO FREED MEMORY IN IS_FREE_LOCK()
AND IS_USED_LOCK().

Analysis:
-----------
In functions Item_func_is_free_lock::val_int() and 
Item_func_is_used_lock::val_int(), for the specified user lock
name, pointer to its "User_level_lock" object is obtained from hash
"hash_user_locks". Mutex "LOCK_user_locks" is acquired for this
and released immediately. And we are accessing members of
User_level_lock after releasing the mutex. If same user lock is
deleted(released) from concurrent thread then accessing members
results in invalid(freed) memory access issue.

Deleting of user lock is also protected from the mutex
"LOCK_user_locks". Since this mutex is released in "val_int" 
functions mentioned above, delete operation proceeds while concurrent
thread tries to access its members.

With the test case, valgrind reports invalid read issues in val_int
functions.

Fix:
-----------
To fix this issue, in "val_int" function of classes
"Item_func_is_free_lock" and "Item_func_is_used_lock", now releasing
mutex "LOCK_user_locks" after accessing User_level_lock members.
2014-09-16 11:28:46 +05:30
Michael Widenius
8e4566e912 Don't give warning if there are two unique keys used with INSERT .. ON DUPLICATE KEY UPDATE.
We should assume that the store engine will report the first duplicate key for this case.

Old code of suppression of unsafe logging error with LIMIT didn't work, because of wrong usage of my_interval_timer().

Suppress unsafe logging errors to the error log if we get too many unsafe logging errors in a short time.
This is to not overflow the error log with meaningless errors.

- Each error code is suppressed and counted separately.
- We do a 5 minute suppression of new errors if we get more than 10 errors in that time.

Only print unsafe logging errors if log_warnings > 1.



mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result:
  Update test results as INSERT ... ON DUPLICATE KEY UPDATE doesn't get logged anymore
mysql-test/suite/binlog/r/binlog_unsafe.result:
  Update test results as INSERT ... ON DUPLICATE KEY UPDATE doesn't get logged anymore
mysql-test/suite/engines/README:
  Fixed typos
mysql-test/suite/rpl/r/rpl_known_bugs_detection.result:
  Update test results as INSERT ... ON DUPLICATE KEY UPDATE doesn't get logged anymore
sql/sql_base.cc:
  Don't log warning if there are two unique keys used with INSERT .. ON DUPLICATE KEY UPDATE.
  We should assume that the store engine will report the first duplicate key for this case.
sql/sql_class.cc:
  Suppress error in binary log if we get too many unsafe logging errors in a short time.
  Only print unsafe logging errors if log_warnings > 1
2014-09-16 00:00:47 +03:00
Michael Widenius
7a50ce1d31 Use LOCK_show_status when we add things to all_status_vars
This was missing in my last commit for fixing possible lockups in SHOW STATUS.

sql/log.cc:
  Fixed comment
sql/sql_show.cc:
  Use LOCK_show_status when we add things to all_status_vars
sql/sql_test.cc:
  Remove not needed mutex_lock
2014-09-15 17:11:01 +03:00
Sergei Golubchik
c799d65baf 5.3 merge 2014-09-12 16:51:41 +02:00
Alexander Barkov
b23af85662 MDEV-6737 Stored routines do now work with swe7: "The table mysql.proc is missing, corrupt, or contains bad data"
Fixed the bug itself.
Also, added "SET NAMES swe7" which was forgotten in the previous commit,
so latin1 was actually tested lati1 instead of swe7 in a mistake.
Now it tests swe7.
2014-09-12 16:06:18 +04:00
Michael Widenius
fa51a22388 Fixed compiler warnings 2014-09-12 14:49:24 +03:00
Michael Widenius
e36d6f03a4 Don't use LOCK_status for the duration of SHOW STATUS because of possible lookups.
Instead we use LOCK_status only to protect summary of thread statistics and use a new mutex, LOCK_show_status
to protect concurrent SHOW STATUS.

sql/mysqld.cc:
  Add LOCK_show_status
  Don't free LOCK_status while calculating status variables.
sql/mysqld.h:
  Add LOCK_show_status
sql/sql_show.cc:
  Use LOCK_show_status to protect SHOW STATUS instead of LOCK_status.
2014-09-12 14:49:13 +03:00
Sergei Golubchik
269f0a6871 MDEV-6619 SHOW PROCESSLIST returns empty result set after KILL QUERY
don't send an OK packet if the SHOW PROCESSLIST was killed
2014-09-12 08:41:35 +02:00
Michael Widenius
c6051a4beb Automatic merge 2014-09-11 23:50:31 +03:00
Sergei Golubchik
3a91af9a92 MDEV-6647 MariaDB CLI client doesnt show CREATE INDEX progress
SQLCOM_CREATE_INDEX was missing CF_REPORT_PROGRESS flag
2014-09-10 17:45:09 +02:00
Sergei Golubchik
30d7860504 MDEV-6459 max_relay_log_size and sql_slave_skip_counter misbehave on PPC64
make slave_skip_counter and max_relay_log_size ulonglong
(sysvars should generally never be ulong)
2014-09-10 13:22:44 +02:00
Sergei Golubchik
b2c54a9a69 MDEV-6523 CONNECT temporary table created
check_engine() was not called for assisted discovery
2014-09-10 13:22:20 +02:00
Praveenkumar Hulakund
0b28d7e048 Bug#18790730 - CROSS-DATABASE FOREIGN KEY WITHOUT PERMISSIONS
CHECK.

Analysis:
----------
Issue here is, while creating or altering the InnoDB table,
if the foreign key defined on the table references a parent
table on which the user has no access privileges then the
table is created without reporting any error. 

Currently the privilege level REFERENCES_ACL is unused
and is not used for access evaluation while creating the
table with a foreign key constraint or adding the foreign
key constraint to a table. But when no privileges are granted
to user then also access evaluation on parent table is ignored.

Fix:
---------
For DMLs, irrelevant of the fact, support does not want any
changes to avoid permission checks on every operation.

So, as a fix, added a function "check_fk_parent_table_access" 
to check whether any of the SELECT_ACL, INSERT_ACL, UDPATE_ACL,
DELETE_ACL or REFERENCE_ACL privileges are granted for user
at table level. If none of them is granted then error is reported.
This function is called during the table creation and alter 
operation.
2014-09-10 10:50:17 +05:30
Praveenkumar Hulakund
cf4231a7f9 Bug#18790730 - CROSS-DATABASE FOREIGN KEY WITHOUT PERMISSIONS
CHECK.

Analysis:
----------
Issue here is, while creating or altering the InnoDB table,
if the foreign key defined on the table references a parent
table on which the user has no access privileges then the
table is created without reporting any error. 

Currently the privilege level REFERENCES_ACL is unused
and is not used for access evaluation while creating the
table with a foreign key constraint or adding the foreign
key constraint to a table. But when no privileges are granted
to user then also access evaluation on parent table is ignored.

Fix:
---------
For DMLs, irrelevant of the fact, support does not want any
changes to avoid permission checks on every operation.

So, as a fix, added a function "check_fk_parent_table_access" 
to check whether any of the SELECT_ACL, INSERT_ACL, UDPATE_ACL,
DELETE_ACL or REFERENCE_ACL privileges are granted for user
at table level. If none of them is granted then error is reported.
This function is called during the table creation and alter 
operation.
2014-09-10 10:50:17 +05:30
Igor Babaev
5023bb899d Fixed bug mdev-6292.
Avoided exponential recursive calls of JOIN_CACHE::join_records() in the case
of non-nested outer joins.
A different solution is required to resolve this performance problem for
nested outer joins.
2014-09-09 16:44:54 -07:00
Michael Widenius
2362d98470 MDEV-6698: safe_mutex: Found wrong usage of mutex 'log_space_lock' and 'LOCK_log'
Moved freeing of mutex earlier, as we don't need to have log_space_cond locked for doing rotate_relay_log()

sql/slave.cc:
  Moved freeing of mutex earlier, as we don't need to have log_space_cond locked for doing rotate_relay_log()
2014-09-09 17:37:08 +03:00
Michael Widenius
9c79227c96 Fixed two bugs with CREATE OR REPLACE and LOCK TABLES:
MDEV-6560 Assertion `! is_set() ' failed in Diagnostics_area::set_ok_status on killing CREATE OR REPLACE
MDEV-6525 Assertion `table->pos_in_locked _tables == __null || table->pos_in_locked_tables->table = table' failed in mark_used_tables_as_free_for_reuse, locking problems and binlogging problems on CREATE OR REPLACE under lock.
 

mysql-test/r/create_or_replace.result:
  Added test for MDEV-6560
mysql-test/t/create_or_replace.test:
  Added test for MDEV-6560
mysql-test/valgrind.supp:
  Added suppression for OpenSuse 12.3
sql/sql_base.cc:
  More DBUG
sql/sql_class.cc:
  Changed that thd_sqlcom_can_generate_row_events() does not report that CREATE OR REPLACE is generating row events.
  This is safe as this function is only used by InnoDB/XtraDB to check if a query is generating row events as part of another transaction. As CREATE is always run as it's own transaction, this isn't a problem.
  This fixed MDEV-6525.
sql/sql_table.cc:
  Remember if reopen_tables() generates an error (which can only happen in case of KILL).
  This fixed MDEV-6560
2014-09-08 20:56:56 +03:00
Sergei Golubchik
6b720ae4cb MDEV-6605 Multiple Clients Inserting Causing Error: Failed to read auto-increment value from storage engine
* handler::get_auto_increment() was not expecting any errors from the storage engine.
  That was wrong, errors could happen.
* ha_partition::get_auto_increment() was doing index lookups in partition under a mutex.
  This was redundant (engine transaction isolation was covering that anyway)
  and harmful (causing deadlocks).
2014-09-08 18:38:13 +02:00
Sergei Golubchik
4d4ce59d2b compilation fixes for WITH_ATOMIC_OPS=rwlocks 2014-09-08 12:59:57 +02:00
Sergei Golubchik
9f0bdda8ab MDEV-6580 Assertion `thd' failed in my_malloc_size_cb_func upon writing status report into error log
thd is NULL in the signal handler, display_table_locks() should expect that
2014-09-07 20:19:12 +02:00
Sergei Golubchik
0c148e413f MDEV-6610 Assertion `thd->is_error() || thd->killed' failed in mysql_execute_command on executing an SP with repeated CREATE TABLE .. SELECT
the bug was introduced by CREATE OR REPLACE implementation.
CREATE IF NOT EXISTS ... SELECT was returning an error status to the caller,
while sending an ok packet to the user. SP code was not prepared for that
and trusted that error status means an error.
2014-09-06 09:46:41 +02:00
Sergei Golubchik
3da761912a MDEV-6616 Server crashes in my_hash_first if shutdown is performed when FLUSH LOGS is running
master_info_index becomes zero during shutdown.
check that it's valid (under a mutex) before dereferencing.
2014-09-06 08:33:56 +02:00
Murthy Narkedimilli
7a4a0bf1c9 Applying the patch to remove WL#7219 which was by mistake included by the dev team. 2014-09-05 08:37:21 +02:00
Ramil Kalimullin
c8d49a8dab removed WL7219: Audit Log Filtering from mysql-5.5. 2014-09-05 09:26:57 +04:00
Ramil Kalimullin
958695b144 removed WL7219: Audit Log Filtering from mysql-5.5. 2014-09-05 09:26:57 +04:00
Alexander Barkov
9392d0e280 - MDEV-6695 Bad column name for UCS2 string literals
The Item_string constructors called set_name() on the source string,
  which was wrong because in case of UCS2/UTF16/UTF32 the source value
  might be a not well formed string (e.g. have incomplete leftmost character).
  Now set_name() is called on str_value after its copied 
  (with optionally left zero padding) from the source string.
- MDEV-6694 Illegal mix of collation with a PS parameter
  Item_param::convert_str_value() did not set repertoire.
  Introducing a new structure MY_STRING_METADATA to collect
  character length and repertoire of a string in a single loop,
  to avoid two separate loops. Adding a new class Item_basic_value::Metadata
  as a convenience wrapper around MY_STRING_METADATA, to reuse the
  code between Item_string and Item_param.
2014-09-04 21:58:48 +04:00
Alexander Barkov
bf4347eba0 Creating a new class in_string::Item_string_for_in_vector
and moving set_value() from Item_string to Item_string_for_in_vector,
as set_value() updates the members incompletely
(e.g. does not update max_length),
so it was dangerous to have set_value() available in Item_string.
2014-09-04 12:43:41 +04:00
Alexander Barkov
c9d3b27d29 Using more Item_string_sys 2014-09-04 12:15:05 +04:00
Alexander Barkov
58eb51d1cf MDEV-6044 MySQL BUG#12735829 - SPACE() FUNCTION WARNING REFERS TO REPEAT() IN ER_WARN_ALLOWED_PACKET_OVERFLOWED
Merged from 5.6
2014-09-04 08:50:06 +04:00
Alexander Barkov
1e66871713 Adding Item_string_sys and Item_string_ascii to reduce duplicate code 2014-09-03 18:24:31 +04:00
Alexander Barkov
e42f4e3199 MDEV-6688 Illegal mix of collation with bit string B'01100001' 2014-09-03 16:31:47 +04:00
Kristian Nielsen
36f50be970 MDEV-6462: Slave replicating using GTID doesn't recover correctly when master crashes in the middle of transaction
If the slave gets a reconnect in the middle of a GTID event group, normally
it will re-fetch that event group, skipping the first part that was already
queued for the SQL thread.

However, if the master crashed while writing the event group, the group is
incomplete. This patch detects this case and makes sure that the
transaction is rolled back and nothing is skipped from any following
event groups.

Similarly, a network proxy might cause the reconnect to end up on a
different master server. Detect this by noticing a different server_id,
and similarly in this case roll back the partially received group.
2014-09-02 14:07:01 +02:00
Alexander Barkov
fbaaf3688d Moving Item::str_value from public to protected. 2014-09-03 01:56:21 +04:00
Alexander Barkov
658a1e9420 MDEV-6683 A parameter and a string literal with the same values are not recognized as equal by the optimizer 2014-09-03 01:47:39 +04:00
Alexander Barkov
c70cacacfe MDEV-6679 Different optimizer plan for "a BETWEEN 'string' AND ?" and "a BETWEEN ? AND 'string'"
Item_string::eq() and Item_param::eq() in string context behaved differently.
Introducing a new class Item_basic_value to share the eq() code between
literals (Item_int, Item_double, Item_string, Item_null) and Item_param.
2014-09-02 22:04:48 +04:00
Alexander Barkov
b088609a62 A clean-up for the previous patch 2014-09-02 17:34:29 +04:00
Alexander Barkov
1427e1db99 MDEV-6661 PI() does not work well in UCS2/UTF16/UTF32 context
MDEV-6666 Malformed result for CONCAT(utf8_column, binary_string)

Item_static_string_func::safe_charset_converter() and 
Item_hex_string::safe_charset_converter() did not
handle character sets with mbminlen>1 properly, as well as
did not handle conversion from binary to multi-byte well.

Introducing Item::const_charset_converter(), to reuse it in a number
of Item_*::safe_charset_converter().
2014-09-01 20:57:32 +04:00
Sergei Golubchik
6389fd3c79 MDEV-6673 I_S.SESSION_VARIABLES shows global values
only look at lex->option_type if it's a SHOW command, not a SELECT
2014-08-31 19:55:11 +02:00
Venkatesh Duggirala
2b33138d00 Bug#19145712 USER AFTER FREE / DOUBLE FREE ISSUE
Problem: A corrupted header length in FORMAT_DESCRIPTION_LOG_EVENT
      can cause server to crash.
      Analysis: FORMAT_DESCRIPTION_EVENT will be considered invalid if
      header len is too small (i.e. below OLD_HEADER_LEN).
      
      Format_description_log_event:: Format_description_log_event(...)
      {
        ...
        if ((common_header_len=buf[ST_COMMON_HEADER_LEN_OFFSET]) < OLD_HEADER_LEN)
          DBUG_VOID_RETURN; /* sanity check */
        ...
        post_header_len= my_memdup(...)
      }
      
      In that case Format_description_log_event constructor will return early,
      without allocating any memory for post_header_len. Thence this variable is
      left uninitialized and making server to crash when server is trying
      to free the uninitialized value.
      
      Fix: When Format_description_log_event constructor returns early, assign
      NULL to post_header_len.
2014-08-28 14:29:54 +05:30
Venkatesh Duggirala
a797587029 Bug#19145712 USER AFTER FREE / DOUBLE FREE ISSUE
Problem: A corrupted header length in FORMAT_DESCRIPTION_LOG_EVENT
      can cause server to crash.
      Analysis: FORMAT_DESCRIPTION_EVENT will be considered invalid if
      header len is too small (i.e. below OLD_HEADER_LEN).
      
      Format_description_log_event:: Format_description_log_event(...)
      {
        ...
        if ((common_header_len=buf[ST_COMMON_HEADER_LEN_OFFSET]) < OLD_HEADER_LEN)
          DBUG_VOID_RETURN; /* sanity check */
        ...
        post_header_len= my_memdup(...)
      }
      
      In that case Format_description_log_event constructor will return early,
      without allocating any memory for post_header_len. Thence this variable is
      left uninitialized and making server to crash when server is trying
      to free the uninitialized value.
      
      Fix: When Format_description_log_event constructor returns early, assign
      NULL to post_header_len.
2014-08-28 14:29:54 +05:30
Sergei Golubchik
dd25e7f0ad MDEV-6601 Assertion `!thd->in_active_multi_stmt_transa ction() || thd->in_multi_stmt_transaction_mode()' failed on executing a stored procedure with commit
Don't restore the whole of thd->server_status after a routine invocation,
only restore SERVER_STATUS_CURSOR_EXISTS and SERVER_STATUS_LAST_ROW_SENT,
as --ps --embedded needs.
In particular, don't restore SERVER_STATUS_IN_TRANS.
2014-08-25 16:58:19 +02:00
Sergei Golubchik
57a43b8435 MDEV-6625 SHOW GRANTS for current_user_name@wrong_host_name 2014-08-21 21:25:22 +02:00
Tor Didriksen
ab727cec04 Bug#18928848 II. MALLOC OF UNINITIALIZED MEMORY SIZE
Several string functions have optimizations for constant
sub-expressions which lead to setting max_length == 0.

For subqueries, where we need a temporary table to holde the result,
we need to ensure that we use a VARCHAR(0) column rather than a
CHAR(0) column when such expressions take part in grouping.
With CHAR(0) end_update() may write garbage into the next field.
2014-08-21 16:42:04 +02:00
Tor Didriksen
63a6af3285 Bug#18928848 II. MALLOC OF UNINITIALIZED MEMORY SIZE
Several string functions have optimizations for constant
sub-expressions which lead to setting max_length == 0.

For subqueries, where we need a temporary table to holde the result,
we need to ensure that we use a VARCHAR(0) column rather than a
CHAR(0) column when such expressions take part in grouping.
With CHAR(0) end_update() may write garbage into the next field.
2014-08-21 16:42:04 +02:00
Sergei Golubchik
04eec20000 MDEV-5706 MariaDB does not build on hurd-i386
Followup. Don't compile threadpool_unix.cc when thread pool is disabled
2014-08-12 16:39:12 +02:00
Kristian Nielsen
c6a60f6d79 MDEV-6321: close_temporary_tables() in format description event not serialised correctly
After-review fixes.

Mainly catching if the wait in wait_for_workers_idle() is aborted due to kill.
In this case, we should return an error and not proceed to execute the format
description event, as other threads might still be running for a bit until the
error is caught in all threads.
2014-08-20 10:59:39 +02:00
Kristian Nielsen
453c29c3f7 MDEV-6321: close_temporary_tables() in format description event not serialised correctly
Follow-up patch, fixing a possible deadlock issue.

If the master crashes in the middle of an event group, there can be an active
transaction in a worker thread when we encounter the following master restart
format description event. In this case, we need to notify that worker thread
to abort and roll back the partial event group. Otherwise a deadlock occurs:
the worker thread waits for the commit that never arrives, and the SQL driver
thread waits for the worker thread to complete its event group, which it never
does.
2014-08-19 14:26:42 +02:00
Igor Babaev
20fff8e5bd Merge. 2014-08-04 10:05:51 -07:00
Sergei Golubchik
50e192a04f Bug#17638477 UNINSTALL AND INSTALL SEMI-SYNC PLUGIN CAUSES SLAVES TO BREAK
Fix the bug properly (plugin cannot be unloaded as long as it's locked).
Enable and fix the test case.
Significantly reduce number of LOCK_plugin locks for semisync
(practically all locks were removed)
2014-08-03 12:45:14 +02:00
Sergei Golubchik
1c6ad62a26 mysql-5.5.39 merge
~40% bugfixed(*) applied
~40$ bugfixed reverted (incorrect or we're not buggy)
~20% bugfixed applied, despite us being not buggy
(*) only changes in the server code, e.g. not cmakefiles
2014-08-02 21:26:16 +02:00
Sergei Golubchik
4b4de01fae 5.3 merge 2014-08-01 16:51:12 +02:00
Igor Babaev
f735822720 Fixed bug mdev-5721.
Do not define a look-up key for a temporary table if its length
exceeds the maximum length of such keys.
2014-07-31 22:17:43 -07:00
unknown
a270e8abc4 MDEV-6441: memory leak
mysql_derived_prepare() was executed on the statement memory.
Now it is executed on the runtime memory.
All bugs induced by this were fixed.
2014-07-31 10:11:10 +03:00
Sergei Golubchik
c1c6f6f161 MDEV-5924 MariaDB could crash after changing the query_cache size with SET GLOBAL
* remove incorrect assertion (it didn't take into account concurrent clients)
* fix the comment
2014-07-29 12:05:58 +02:00
Alexander Barkov
5b452ae027 MDEV-4511 Assertion `scale <= precision' fails on GROUP BY TIMEDIFF with incorrect types
MDEV-6302 Wrong result set when using GROUP BY FROM_UNIXTIME(...)+0
Fixed.
2014-07-28 13:47:55 +04:00