From 29476d879f85a81c9376b556ad9c233f2a5e073b Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 19 Feb 2009 17:30:03 +0200 Subject: Bug #42419: Server crash with "Pure virtual method called" on two concurrent connections The problem is that tables can enter open table cache for a thread without being properly cleaned up. This can happen if make_join_statistics() fails to read a const table because of e.g. a deadlock. It does set a member of TABLE structure to a value it allocates, but doesn't clean-up this setting on error nor does it set the rest of the members in JOIN to allow for automatic cleanup. As a result when such an error occurs and the next statement depends re-uses the table from the open tables cache it will get it with this TABLE::reginfo.join_tab pointing to a memory area that's freed. Fixed by making sure make_join_statistics() cleans up TABLE::reginfo.join_tab on error. mysql-test/r/innodb_mysql.result: Bug #42419: test case mysql-test/t/innodb_mysql-master.opt: Bug #42419: increase the timeout so it covers te conservative sleep 3 in the test mysql-test/t/innodb_mysql.test: Bug #42419: test case sql/sql_select.cc: Bug #42419: clean up the members of TABLE on failure in make_join_statisitcs() --- mysql-test/r/innodb_mysql.result | 16 +++++++++++ mysql-test/t/innodb_mysql-master.opt | 2 +- mysql-test/t/innodb_mysql.test | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) (limited to 'mysql-test') diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 682cc2e82e2..78a56cddb08 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1267,4 +1267,20 @@ CREATE INDEX i1 on t1 (a(3)); SELECT * FROM t1 WHERE a = 'abcde'; a DROP TABLE t1; +CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT) +ENGINE=InnoDB; +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +SET AUTOCOMMIT = 0; +CREATE TEMPORARY TABLE t1_tmp (b INT); +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 3; +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 2; +SET AUTOCOMMIT = 0; +CREATE TEMPORARY TABLE t2_tmp ( a INT, new_a INT); +INSERT INTO t2_tmp VALUES (1,51),(2,52),(3,53); +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 1; +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 2; +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 1; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 3; +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/innodb_mysql-master.opt b/mysql-test/t/innodb_mysql-master.opt index 205c733455d..c8613e0ccd5 100644 --- a/mysql-test/t/innodb_mysql-master.opt +++ b/mysql-test/t/innodb_mysql-master.opt @@ -1 +1 @@ ---innodb-lock-wait-timeout=2 +--innodb-lock-wait-timeout=3 diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index b4fc425cb7c..eb23739386e 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -1025,4 +1025,55 @@ CREATE INDEX i1 on t1 (a(3)); SELECT * FROM t1 WHERE a = 'abcde'; DROP TABLE t1; +# +# Bug #42419: Server crash with "Pure virtual method called" on two +# concurrent connections +# + +connect (c1, localhost, root,,); +connect (c2, localhost, root,,); + +CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT) + ENGINE=InnoDB; + +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); + +connection c1; + +SET AUTOCOMMIT = 0; + +CREATE TEMPORARY TABLE t1_tmp (b INT); + +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 3; +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 2; + +connection c2; + +SET AUTOCOMMIT = 0; + +CREATE TEMPORARY TABLE t2_tmp ( a INT, new_a INT); +INSERT INTO t2_tmp VALUES (1,51),(2,52),(3,53); + +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 1; + +--send +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 2; + +--sleep 3 + +connection c1; + +--error ER_LOCK_DEADLOCK +INSERT INTO t1_tmp SELECT b FROM t1 WHERE a = 1; + +connection c2; + +--reap +UPDATE t1 SET a = (SELECT new_a FROM t2_tmp WHERE t2_tmp.a = t1.a) WHERE a = 3; + +connection default; +disconnect c1; +disconnect c2; +DROP TABLE t1; + --echo End of 5.0 tests -- cgit v1.2.1