mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
8280fdd3c3
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.
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
#
|
|
# SUMMARY
|
|
# Check if statement reading table '$table' takes shared locks
|
|
# on some of its rows.
|
|
#
|
|
# PARAMETERS
|
|
# $table Table for which presence of row locks should be checked.
|
|
# $con_aux Name of auxiliary connection to be used by this script.
|
|
# $statement Statement to be checked.
|
|
# $wait_statement Sub-statement which is supposed to acquire locks (should
|
|
# be the same as $statement for ordinary statements).
|
|
#
|
|
# EXAMPLE
|
|
# innodb_mysql_lock2.test
|
|
#
|
|
--disable_result_log
|
|
--disable_query_log
|
|
|
|
connection default;
|
|
begin;
|
|
--eval select * from $table for update;
|
|
|
|
connection $con_aux;
|
|
begin;
|
|
--send_eval $statement;
|
|
|
|
--enable_result_log
|
|
--enable_query_log
|
|
|
|
connection default;
|
|
# Wait until statement is successfully blocked because
|
|
# all rows in table are X-locked. This means that at
|
|
# least it acquires S-locks on some of rows.
|
|
let $wait_condition=
|
|
select count(*) = 1 from information_schema.processlist
|
|
where state in ("Sending data","statistics", "preparing") and
|
|
info = "$wait_statement";
|
|
--source include/wait_condition.inc
|
|
|
|
--disable_result_log
|
|
--disable_query_log
|
|
|
|
rollback;
|
|
|
|
connection $con_aux;
|
|
--reap
|
|
rollback;
|
|
|
|
connection default;
|
|
--enable_result_log
|
|
--enable_query_log
|
|
|
|
if ($success)
|
|
{
|
|
--echo Success: '$statement' takes shared row locks on '$table'.
|
|
}
|
|
|
|
if (!$success)
|
|
{
|
|
--echo Error: '$statement' hasn't taken shared row locks on '$table'!
|
|
}
|