Commit 92b2a911 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24818 Concurrent use of InnoDB table is impossible until the first transaction is finished

In MDEV-515, we enabled an optimization where an insert into an
empty table will use table-level locking and undo logging.
This may break applications that expect row-level locking.

The SQL statements created by the mysqldump utility will include the
following:

    SET unique_checks=0, foreign_key_checks=0;

We will use these flags to enable the table-level locked and logged
insert. Unless the parameters are set, INSERT will be executed in
the old way, with row-level undo logging and implicit record locks.
parent 8dd35a25
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
-- connect (con2,localhost,root,,) -- connect (con2,localhost,root,,)
-- connection con1 -- connection con1
# Enable MDEV-515 table-level undo logging for insert into empty table
SET foreign_key_checks=0, unique_checks=0;
SET autocommit=0; SET autocommit=0;
SELECT * FROM t1 FOR UPDATE; SELECT * FROM t1 FOR UPDATE;
-- if ($con1_extra_sql_present) { -- if ($con1_extra_sql_present) {
...@@ -9,6 +11,8 @@ SELECT * FROM t1 FOR UPDATE; ...@@ -9,6 +11,8 @@ SELECT * FROM t1 FOR UPDATE;
-- } -- }
-- connection con2 -- connection con2
# Enable MDEV-515 table-level undo logging for insert into empty table
SET foreign_key_checks=0, unique_checks=0;
SET autocommit=0; SET autocommit=0;
SELECT * FROM t2 FOR UPDATE; SELECT * FROM t2 FOR UPDATE;
-- if ($con2_extra_sql_present) { -- if ($con2_extra_sql_present) {
......
SET foreign_key_checks=0, unique_checks=0;
# #
# MDEV-24715 Assertion !node->table->skip_alter_undo # MDEV-24715 Assertion !node->table->skip_alter_undo
# #
......
...@@ -22,10 +22,6 @@ SET default_storage_engine=InnoDB; ...@@ -22,10 +22,6 @@ SET default_storage_engine=InnoDB;
# if someone runs ./mysql-test-run.pl --ps-protocol # if someone runs ./mysql-test-run.pl --ps-protocol
-- disable_ps_protocol -- disable_ps_protocol
-- disable_warnings
DROP TABLE IF EXISTS t1, t2, t3, t4, t5_nontrans;
-- enable_warnings
# we will create a simple deadlock with t1, t2 and two connections # we will create a simple deadlock with t1, t2 and two connections
CREATE TABLE t1 (a INT); CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT); CREATE TABLE t2 (a INT);
......
--source include/have_innodb.inc --source include/have_innodb.inc
--source include/have_sequence.inc --source include/have_sequence.inc
# Enable MDEV-515 table-level undo logging for insert into empty table
SET foreign_key_checks=0, unique_checks=0;
--echo # --echo #
--echo # MDEV-24715 Assertion !node->table->skip_alter_undo --echo # MDEV-24715 Assertion !node->table->skip_alter_undo
--echo # --echo #
......
...@@ -115,6 +115,7 @@ title VARCHAR(200), ...@@ -115,6 +115,7 @@ title VARCHAR(200),
body TEXT, body TEXT,
FULLTEXT (title, body) WITH PARSER simple_parser FULLTEXT (title, body) WITH PARSER simple_parser
) ENGINE=InnoDB; ) ENGINE=InnoDB;
SET unique_checks=0, foreign_key_checks=0;
BEGIN; BEGIN;
INSERT INTO articles (title, body) VALUES INSERT INTO articles (title, body) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'), ('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
......
...@@ -125,6 +125,8 @@ CREATE TABLE articles ( ...@@ -125,6 +125,8 @@ CREATE TABLE articles (
FULLTEXT (title, body) WITH PARSER simple_parser FULLTEXT (title, body) WITH PARSER simple_parser
) ENGINE=InnoDB; ) ENGINE=InnoDB;
# Enable MDEV-515 table-level undo logging when inserting into empty table
SET unique_checks=0, foreign_key_checks=0;
BEGIN; BEGIN;
INSERT INTO articles (title, body) VALUES INSERT INTO articles (title, body) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'), ('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
......
...@@ -2660,6 +2660,7 @@ row_ins_clust_index_entry_low( ...@@ -2660,6 +2660,7 @@ row_ins_clust_index_entry_low(
if (!(flags & BTR_NO_UNDO_LOG_FLAG) if (!(flags & BTR_NO_UNDO_LOG_FLAG)
&& page_is_empty(block->frame) && page_is_empty(block->frame)
&& !entry->is_metadata() && !trx->duplicates && !entry->is_metadata() && !trx->duplicates
&& !trx->check_unique_secondary && !trx->check_foreigns
&& !trx->ddl && !trx->internal && !trx->ddl && !trx->internal
&& block->page.id().page_no() == index->page && block->page.id().page_no() == index->page
&& !index->table->skip_alter_undo && !index->table->skip_alter_undo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment