diff options
author | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2011-06-01 10:06:55 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2011-06-01 10:06:55 +0200 |
commit | 9b076952ec83b455b3730990c78fb78c2d689674 (patch) | |
tree | 250d4171faac82b1092b588097b1a32c82ea4336 /mysql-test | |
parent | 9e2b7fa7d5f0cbe4920be5567314b6de1af660a4 (diff) | |
download | mariadb-git-9b076952ec83b455b3730990c78fb78c2d689674.tar.gz |
Bug#11853126 RE-ENABLE CONCURRENT READS WHILE CREATING
SECONDARY INDEX IN INNODB
The patches for Bug#11751388 and Bug#11784056 enabled concurrent
reads while creating secondary indexes in InnoDB. However, they
introduced a regression. This regression occured if ALTER TABLE
failed after the index had been added, for example during the
lock upgrade needed to update .FRM. If this happened, InnoDB
and the server got out of sync with regards to which indexes
actually existed. Therefore the patch for Bug#11815600 again
disabled concurrent reads.
This patch re-enables concurrent reads. The original regression
is fixed by splitting the ADD INDEX operation into two parts.
First the new index is created but not made active. This is
done while concurrent reads are allowed. The second part of
the operation makes the index active (or reverts the change).
This is done after lock upgrade, which prevents the original
regression.
In order to implement this change, the patch changes the storage
API for in-place index creation. handler::add_index() is split
into two functions, handler_add_index() and
handler::final_add_index(). The former for creating indexes without
making them visible and the latter for commiting (i.e. making
visible) new indexes or reverting the changes.
Large parts of this patch were written by Marko Mäkelä.
Test case added to innodb_mysql_lock.test.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/innodb_mysql_lock.result | 20 | ||||
-rw-r--r-- | mysql-test/r/innodb_mysql_sync.result | 74 | ||||
-rw-r--r-- | mysql-test/t/innodb_mysql_lock.test | 22 | ||||
-rw-r--r-- | mysql-test/t/innodb_mysql_sync.test | 248 |
4 files changed, 235 insertions, 129 deletions
diff --git a/mysql-test/r/innodb_mysql_lock.result b/mysql-test/r/innodb_mysql_lock.result index cd9487721b6..4fdcf2383a8 100644 --- a/mysql-test/r/innodb_mysql_lock.result +++ b/mysql-test/r/innodb_mysql_lock.result @@ -153,6 +153,7 @@ DROP VIEW v1; # KEY NO 0 FOR TABLE IN ERROR LOG # DROP TABLE IF EXISTS t1; +# Test 1: Secondary index # Connection default CREATE TABLE t1 (id INT PRIMARY KEY, value INT) ENGINE = InnoDB; INSERT INTO t1 VALUES (1, 12345); @@ -164,9 +165,28 @@ id value SET lock_wait_timeout=1; ALTER TABLE t1 ADD INDEX idx(value); ERROR HY000: Lock wait timeout exceeded; try restarting transaction +ALTER TABLE t1 ADD INDEX idx(value); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction # Connection default SELECT * FROM t1; id value 1 12345 COMMIT; DROP TABLE t1; +# Test 2: Primary index +CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; +INSERT INTO t1 VALUES (1, 12345), (2, 23456); +# Connection con1 +SET SESSION debug= "+d,alter_table_rollback_new_index"; +ALTER TABLE t1 ADD PRIMARY KEY(a); +ERROR HY000: Unknown error +SELECT * FROM t1; +a b +1 12345 +2 23456 +# Connection default +SELECT * FROM t1; +a b +1 12345 +2 23456 +DROP TABLE t1; diff --git a/mysql-test/r/innodb_mysql_sync.result b/mysql-test/r/innodb_mysql_sync.result index 71f567a4ad2..8e210a7e205 100644 --- a/mysql-test/r/innodb_mysql_sync.result +++ b/mysql-test/r/innodb_mysql_sync.result @@ -94,6 +94,74 @@ SET DEBUG_SYNC= 'RESET'; # Bug#42230 during add index, cannot do queries on storage engines # that implement add_index # -# -# DISABLED due to Bug#11815600 -# +DROP DATABASE IF EXISTS db1; +DROP TABLE IF EXISTS t1; +# Test 1: Secondary index, should not block reads (original test case). +# Connection default +CREATE DATABASE db1; +CREATE TABLE db1.t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, value INT) engine=innodb; +INSERT INTO db1.t1(value) VALUES (1), (2); +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +# Sending: +ALTER TABLE db1.t1 ADD INDEX(value); +# Connection con1 +SET DEBUG_SYNC= "now WAIT_FOR manage"; +USE db1; +SELECT * FROM t1; +id value +1 1 +2 2 +SET DEBUG_SYNC= "now SIGNAL query"; +# Connection default +# Reaping: ALTER TABLE db1.t1 ADD INDEX(value) +DROP DATABASE db1; +# Test 2: Primary index (implicit), should block reads. +CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +# Sending: +ALTER TABLE t1 ADD UNIQUE INDEX(a); +# Connection con1 +SET DEBUG_SYNC= "now WAIT_FOR manage"; +USE test; +# Sending: +SELECT * FROM t1; +# Connection con2 +# Waiting for SELECT to be blocked by the metadata lock on t1 +SET DEBUG_SYNC= "now SIGNAL query"; +# Connection default +# Reaping: ALTER TABLE t1 ADD UNIQUE INDEX(a) +# Connection con1 +# Reaping: SELECT * FROM t1 +a b +# Test 3: Primary index (explicit), should block reads. +# Connection default +ALTER TABLE t1 DROP INDEX a; +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +# Sending: +ALTER TABLE t1 ADD PRIMARY KEY (a); +# Connection con1 +SET DEBUG_SYNC= "now WAIT_FOR manage"; +# Sending: +SELECT * FROM t1; +# Connection con2 +# Waiting for SELECT to be blocked by the metadata lock on t1 +SET DEBUG_SYNC= "now SIGNAL query"; +# Connection default +# Reaping: ALTER TABLE t1 ADD PRIMARY KEY (a) +# Connection con1 +# Reaping: SELECT * FROM t1 +a b +# Test 4: Secondary unique index, should not block reads. +# Connection default +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +# Sending: +ALTER TABLE t1 ADD UNIQUE (b); +# Connection con1 +SET DEBUG_SYNC= "now WAIT_FOR manage"; +SELECT * FROM t1; +a b +SET DEBUG_SYNC= "now SIGNAL query"; +# Connection default +# Reaping: ALTER TABLE t1 ADD UNIQUE (b) +SET DEBUG_SYNC= "RESET"; +DROP TABLE t1; diff --git a/mysql-test/t/innodb_mysql_lock.test b/mysql-test/t/innodb_mysql_lock.test index f1dc0d52484..a5dcb4d31bf 100644 --- a/mysql-test/t/innodb_mysql_lock.test +++ b/mysql-test/t/innodb_mysql_lock.test @@ -290,6 +290,8 @@ DROP TABLE IF EXISTS t1; --connect (con1,localhost,root) +--echo # Test 1: Secondary index + --echo # Connection default connection default; CREATE TABLE t1 (id INT PRIMARY KEY, value INT) ENGINE = InnoDB; @@ -300,6 +302,10 @@ SELECT * FROM t1; --echo # Connection con1 --connection con1 SET lock_wait_timeout=1; +# Test with two timeouts, as the first version of this patch +# only worked with one timeout. +--error ER_LOCK_WAIT_TIMEOUT +ALTER TABLE t1 ADD INDEX idx(value); --error ER_LOCK_WAIT_TIMEOUT ALTER TABLE t1 ADD INDEX idx(value); @@ -308,6 +314,22 @@ ALTER TABLE t1 ADD INDEX idx(value); SELECT * FROM t1; COMMIT; DROP TABLE t1; + +--echo # Test 2: Primary index +CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; +INSERT INTO t1 VALUES (1, 12345), (2, 23456); + +--echo # Connection con1 +--connection con1 +SET SESSION debug= "+d,alter_table_rollback_new_index"; +--error ER_UNKNOWN_ERROR +ALTER TABLE t1 ADD PRIMARY KEY(a); +SELECT * FROM t1; + +--echo # Connection default +--connection default +SELECT * FROM t1; +DROP TABLE t1; disconnect con1; diff --git a/mysql-test/t/innodb_mysql_sync.test b/mysql-test/t/innodb_mysql_sync.test index 13c854d6b61..bf1e5de1587 100644 --- a/mysql-test/t/innodb_mysql_sync.test +++ b/mysql-test/t/innodb_mysql_sync.test @@ -152,133 +152,129 @@ disconnect con1; --echo # that implement add_index --echo # ---echo # ---echo # DISABLED due to Bug#11815600 ---echo # +--disable_warnings +DROP DATABASE IF EXISTS db1; +DROP TABLE IF EXISTS t1; +--enable_warnings -#--disable_warnings -#DROP DATABASE IF EXISTS db1; -#DROP TABLE IF EXISTS t1; -#--enable_warnings -# -#connect(con1,localhost,root); -#connect(con2,localhost,root); -# -#--echo # Test 1: Secondary index, should not block reads (original test case). -# -#--echo # Connection default -#connection default; -#CREATE DATABASE db1; -#CREATE TABLE db1.t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, value INT) engine=innodb; -#INSERT INTO db1.t1(value) VALUES (1), (2); -#SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; -#--echo # Sending: -#--send ALTER TABLE db1.t1 ADD INDEX(value) -# -#--echo # Connection con1 -#connection con1; -#SET DEBUG_SYNC= "now WAIT_FOR manage"; -# # Neither of these two statements should be blocked -#USE db1; -#SELECT * FROM t1; -#SET DEBUG_SYNC= "now SIGNAL query"; -# -#--echo # Connection default -#connection default; -#--echo # Reaping: ALTER TABLE db1.t1 ADD INDEX(value) -#--reap -#DROP DATABASE db1; -# -#--echo # Test 2: Primary index (implicit), should block reads. -# -#CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; -#SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; -#--echo # Sending: -#--send ALTER TABLE t1 ADD UNIQUE INDEX(a) -# -#--echo # Connection con1 -#connection con1; -#SET DEBUG_SYNC= "now WAIT_FOR manage"; -#USE test; -#--echo # Sending: -#--send SELECT * FROM t1 -# -#--echo # Connection con2 -#connection con2; -#--echo # Waiting for SELECT to be blocked by the metadata lock on t1 -#let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist -# WHERE state= 'Waiting for table metadata lock' -# AND info='SELECT * FROM t1'; -#--source include/wait_condition.inc -#SET DEBUG_SYNC= "now SIGNAL query"; -# -#--echo # Connection default -#connection default; -#--echo # Reaping: ALTER TABLE t1 ADD UNIQUE INDEX(a) -#--reap -# -#--echo # Connection con1 -#connection con1; -#--echo # Reaping: SELECT * FROM t1 -#--reap -# -#--echo # Test 3: Primary index (explicit), should block reads. -# -#--echo # Connection default -#connection default; -#ALTER TABLE t1 DROP INDEX a; -#SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; -#--echo # Sending: -#--send ALTER TABLE t1 ADD PRIMARY KEY (a) -# -#--echo # Connection con1 -#connection con1; -#SET DEBUG_SYNC= "now WAIT_FOR manage"; -#--echo # Sending: -#--send SELECT * FROM t1 -# -#--echo # Connection con2 -#connection con2; -#--echo # Waiting for SELECT to be blocked by the metadata lock on t1 -#let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist -# WHERE state= 'Waiting for table metadata lock' -# AND info='SELECT * FROM t1'; -#--source include/wait_condition.inc -#SET DEBUG_SYNC= "now SIGNAL query"; -# -#--echo # Connection default -#connection default; -#--echo # Reaping: ALTER TABLE t1 ADD PRIMARY KEY (a) -#--reap -# -#--echo # Connection con1 -#connection con1; -#--echo # Reaping: SELECT * FROM t1 -#--reap -# -#--echo # Test 4: Secondary unique index, should not block reads. -# -#--echo # Connection default -#connection default; -#SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; -#--echo # Sending: -#--send ALTER TABLE t1 ADD UNIQUE (b) -# -#--echo # Connection con1 -#connection con1; -#SET DEBUG_SYNC= "now WAIT_FOR manage"; -#SELECT * FROM t1; -#SET DEBUG_SYNC= "now SIGNAL query"; -# -#--echo # Connection default -#connection default; -#--echo # Reaping: ALTER TABLE t1 ADD UNIQUE (b) -#--reap -# -#disconnect con1; -#disconnect con2; -#SET DEBUG_SYNC= "RESET"; -#DROP TABLE t1; +connect(con1,localhost,root); +connect(con2,localhost,root); + +--echo # Test 1: Secondary index, should not block reads (original test case). + +--echo # Connection default +connection default; +CREATE DATABASE db1; +CREATE TABLE db1.t1(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, value INT) engine=innodb; +INSERT INTO db1.t1(value) VALUES (1), (2); +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +--echo # Sending: +--send ALTER TABLE db1.t1 ADD INDEX(value) + +--echo # Connection con1 +connection con1; +SET DEBUG_SYNC= "now WAIT_FOR manage"; +# Neither of these two statements should be blocked +USE db1; +SELECT * FROM t1; +SET DEBUG_SYNC= "now SIGNAL query"; + +--echo # Connection default +connection default; +--echo # Reaping: ALTER TABLE db1.t1 ADD INDEX(value) +--reap +DROP DATABASE db1; + +--echo # Test 2: Primary index (implicit), should block reads. + +CREATE TABLE t1(a INT NOT NULL, b INT NOT NULL) engine=innodb; +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +--echo # Sending: +--send ALTER TABLE t1 ADD UNIQUE INDEX(a) + +--echo # Connection con1 +connection con1; +SET DEBUG_SYNC= "now WAIT_FOR manage"; +USE test; +--echo # Sending: +--send SELECT * FROM t1 + +--echo # Connection con2 +connection con2; +--echo # Waiting for SELECT to be blocked by the metadata lock on t1 +let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist + WHERE state= 'Waiting for table metadata lock' + AND info='SELECT * FROM t1'; +--source include/wait_condition.inc +SET DEBUG_SYNC= "now SIGNAL query"; + +--echo # Connection default +connection default; +--echo # Reaping: ALTER TABLE t1 ADD UNIQUE INDEX(a) +--reap + +--echo # Connection con1 +connection con1; +--echo # Reaping: SELECT * FROM t1 +--reap + +--echo # Test 3: Primary index (explicit), should block reads. + +--echo # Connection default +connection default; +ALTER TABLE t1 DROP INDEX a; +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +--echo # Sending: +--send ALTER TABLE t1 ADD PRIMARY KEY (a) + +--echo # Connection con1 +connection con1; +SET DEBUG_SYNC= "now WAIT_FOR manage"; +--echo # Sending: +--send SELECT * FROM t1 + +--echo # Connection con2 +connection con2; +--echo # Waiting for SELECT to be blocked by the metadata lock on t1 +let $wait_condition= SELECT COUNT(*)= 1 FROM information_schema.processlist + WHERE state= 'Waiting for table metadata lock' + AND info='SELECT * FROM t1'; +--source include/wait_condition.inc +SET DEBUG_SYNC= "now SIGNAL query"; + +--echo # Connection default +connection default; +--echo # Reaping: ALTER TABLE t1 ADD PRIMARY KEY (a) +--reap + +--echo # Connection con1 +connection con1; +--echo # Reaping: SELECT * FROM t1 +--reap + +--echo # Test 4: Secondary unique index, should not block reads. + +--echo # Connection default +connection default; +SET DEBUG_SYNC= "alter_table_manage_keys SIGNAL manage WAIT_FOR query"; +--echo # Sending: +--send ALTER TABLE t1 ADD UNIQUE (b) + +--echo # Connection con1 +connection con1; +SET DEBUG_SYNC= "now WAIT_FOR manage"; +SELECT * FROM t1; +SET DEBUG_SYNC= "now SIGNAL query"; + +--echo # Connection default +connection default; +--echo # Reaping: ALTER TABLE t1 ADD UNIQUE (b) +--reap + +disconnect con1; +disconnect con2; +SET DEBUG_SYNC= "RESET"; +DROP TABLE t1; # Check that all connections opened by test cases in this file are really |