mirror of
https://github.com/MariaDB/server.git
synced 2025-08-30 11:22:14 +03:00
Committing on behalf or Dmitry Lenev:
Fix for bug #46947 "Embedded SELECT without FOR UPDATE is causing a lock", with after-review fixes. SELECT statements with subqueries referencing InnoDB tables were acquiring shared locks on rows in these tables when they were executed in REPEATABLE-READ mode and with statement or mixed mode binary logging turned on. This was a regression which were introduced when fixing bug 39843. The problem was that for tables belonging to subqueries parser set TL_READ_DEFAULT as a lock type. In cases when statement/mixed binary logging at open_tables() time this type of lock was converted to TL_READ_NO_INSERT lock at open_tables() time and caused InnoDB engine to acquire shared locks on reads from these tables. Although in some cases such behavior was correct (e.g. for subqueries in DELETE) in case of SELECT it has caused unnecessary locking. This patch tries to solve this problem by rethinking our approach to how we handle locking for SELECT and subqueries. Now we always set TL_READ_DEFAULT lock type for all cases when we read data. When at open_tables() time this lock is interpreted as TL_READ_NO_INSERT or TL_READ depending on whether this statement as a whole or call to function which uses particular table should be written to the binary log or not (if yes then statement should be properly serialized with concurrent statements and stronger lock should be acquired). Test coverage is added for both InnoDB and MyISAM. This patch introduces an "incompatible" change in locking scheme for subqueries used in SELECT ... FOR UPDATE and SELECT .. IN SHARE MODE. In 4.1 the server would use a snapshot InnoDB read for subqueries in SELECT FOR UPDATE and SELECT .. IN SHARE MODE statements, regardless of whether the binary log is on or off. If the user required a different type of read (i.e. locking read), he/she could request so explicitly by providing FOR UPDATE/IN SHARE MODE clause for each individual subquery. On of the patches for 5.0 broke this behaviour (which was not documented or tested), and started to use locking reads fora all subqueries in SELECT ... FOR UPDATE/IN SHARE MODE. This patch restored 4.1 behaviour.
This commit is contained in:
90
mysql-test/include/check_concurrent_insert.inc
Normal file
90
mysql-test/include/check_concurrent_insert.inc
Normal file
@@ -0,0 +1,90 @@
|
||||
#
|
||||
# SUMMARY
|
||||
# Check if statement reading table '$table' allows concurrent
|
||||
# inserts in it.
|
||||
#
|
||||
# PARAMETERS
|
||||
# $table Table in which concurrent inserts should be allowed.
|
||||
# $con_aux1 Name of the first auxiliary connection to be used by this
|
||||
# script.
|
||||
# $con_aux2 Name of the second auxiliary connection to be used by this
|
||||
# script.
|
||||
# $statement Statement to be checked.
|
||||
# $restore_table Table which might be modified affected by statement to be
|
||||
# checked and thus needs backing up before its execution
|
||||
# and restoring after it (can be empty).
|
||||
#
|
||||
# EXAMPLE
|
||||
# lock_sync.test
|
||||
#
|
||||
--disable_result_log
|
||||
--disable_query_log
|
||||
|
||||
if (`SELECT '$restore_table' <> ''`)
|
||||
{
|
||||
--eval create table t_backup select * from $restore_table;
|
||||
}
|
||||
|
||||
connection $con_aux1;
|
||||
set debug_sync='after_lock_tables_takes_lock SIGNAL parked WAIT_FOR go';
|
||||
--send_eval $statement;
|
||||
|
||||
connection $con_aux2;
|
||||
set debug_sync='now WAIT_FOR parked';
|
||||
--send_eval insert into $table values (0);
|
||||
|
||||
--enable_result_log
|
||||
--enable_query_log
|
||||
connection default;
|
||||
# Wait until concurrent insert is successfully executed while
|
||||
# statement being checked has its tables locked.
|
||||
# We use wait_condition.inc instead of simply executing
|
||||
# concurrent insert here in order to avoid deadlocks if test
|
||||
# fails and timing out instead.
|
||||
let $wait_condition=
|
||||
select count(*) = 0 from information_schema.processlist
|
||||
where info = "insert into $table values (0)";
|
||||
--source include/wait_condition.inc
|
||||
|
||||
--disable_result_log
|
||||
--disable_query_log
|
||||
|
||||
if ($success)
|
||||
{
|
||||
# Apparently concurrent insert was successfully executed.
|
||||
# To be safe against wait_condition.inc succeeding due to
|
||||
# races let us first reap concurrent insert to ensure that
|
||||
# it has really been successfully executed.
|
||||
connection $con_aux2;
|
||||
--reap
|
||||
connection default;
|
||||
set debug_sync= 'now SIGNAL go';
|
||||
connection $con_aux1;
|
||||
--reap
|
||||
connection default;
|
||||
--echo Success: '$statement' allows concurrent inserts into '$table'.
|
||||
}
|
||||
if (!$success)
|
||||
{
|
||||
# Waiting has timed out. Apparently concurrent insert was blocked.
|
||||
# So to be able to continue we need to end our statement first.
|
||||
set debug_sync= 'now SIGNAL go';
|
||||
connection $con_aux1;
|
||||
--reap
|
||||
connection $con_aux2;
|
||||
--reap
|
||||
connection default;
|
||||
--echo Error: '$statement' doesn't allow concurrent inserts into '$table'!
|
||||
}
|
||||
|
||||
--eval delete from $table where i = 0;
|
||||
|
||||
if (`SELECT '$restore_table' <> ''`)
|
||||
{
|
||||
--eval truncate table $restore_table;
|
||||
--eval insert into $restore_table select * from t_backup;
|
||||
drop table t_backup;
|
||||
}
|
||||
|
||||
--enable_result_log
|
||||
--enable_query_log
|
Reference in New Issue
Block a user