Skip to content

Commit

Permalink
MDEV-24818 Concurrent use of InnoDB table is impossible until the fir…
Browse files Browse the repository at this point in the history
…st 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.
  • Loading branch information
dr-m committed Mar 16, 2021
1 parent 8dd35a2 commit 92b2a91
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions mysql-test/include/innodb_trx_weight.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
-- connect (con2,localhost,root,,)

-- 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;
SELECT * FROM t1 FOR UPDATE;
-- if ($con1_extra_sql_present) {
-- eval $con1_extra_sql
-- }

-- 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;
SELECT * FROM t2 FOR UPDATE;
-- if ($con2_extra_sql_present) {
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/innodb/r/insert_into_empty.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SET foreign_key_checks=0, unique_checks=0;
#
# MDEV-24715 Assertion !node->table->skip_alter_undo
#
Expand Down
4 changes: 0 additions & 4 deletions mysql-test/suite/innodb/t/innodb_trx_weight.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ SET default_storage_engine=InnoDB;
# if someone runs ./mysql-test-run.pl --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
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/innodb/t/insert_into_empty.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
--source include/have_innodb.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 # MDEV-24715 Assertion !node->table->skip_alter_undo
--echo #
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/innodb_fts/r/innodb_fts_plugin.result
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ title VARCHAR(200),
body TEXT,
FULLTEXT (title, body) WITH PARSER simple_parser
) ENGINE=InnoDB;
SET unique_checks=0, foreign_key_checks=0;
BEGIN;
INSERT INTO articles (title, body) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb_fts/t/innodb_fts_plugin.test
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ CREATE TABLE articles (
FULLTEXT (title, body) WITH PARSER simple_parser
) ENGINE=InnoDB;

# Enable MDEV-515 table-level undo logging when inserting into empty table
SET unique_checks=0, foreign_key_checks=0;
BEGIN;
INSERT INTO articles (title, body) VALUES
('MySQL Tutorial','DBMS stands for MySQL DataBase ...'),
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/row/row0ins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,7 @@ row_ins_clust_index_entry_low(
if (!(flags & BTR_NO_UNDO_LOG_FLAG)
&& page_is_empty(block->frame)
&& !entry->is_metadata() && !trx->duplicates
&& !trx->check_unique_secondary && !trx->check_foreigns
&& !trx->ddl && !trx->internal
&& block->page.id().page_no() == index->page
&& !index->table->skip_alter_undo
Expand Down

0 comments on commit 92b2a91

Please sign in to comment.