#At file:///work/bzrroot/wl5274-next-mr-bugfixing/ based on revid:epotemkin@stripped
3004 Evgeny Potemkin 2011-02-21
Bug#11791677: ASSERTION FAILED IN JOIN_MATERIALIZE_TABLE IN SQL_SELECT.CC ON
NESTED SUBQUERY
Derived tables materialization mechanism substitutes table's read_first_record
with the join_materialize_table function to materialize table on the first read,
after this is done the original read_first_record is restored and called.
Subqueries in WHERE clause could reinitialize join and restore
join_materialize_table as the read_first_record function. Assertion is thrown
on attempt to materialize a derived table second time.
Now original read_first_record function is restored in saved copy also to
prevent second materialization attempt.
@ mysql-test/r/derived.result
Added a test case for the bug#11791677.
@ mysql-test/t/derived.test
Added a test case for the bug#11791677.
modified:
mysql-test/r/derived.result
mysql-test/t/derived.test
sql/sql_select.cc
=== modified file 'mysql-test/r/derived.result'
--- a/mysql-test/r/derived.result 2011-02-21 14:17:57 +0000
+++ b/mysql-test/r/derived.result 2011-02-21 16:28:03 +0000
@@ -1455,3 +1455,63 @@ col_int_nokey
DROP TABLE t1;
DROP TABLE t2;
#
+#
+# Bug#11791677 - ASSERTION FAILED IN JOIN_MATERIALIZE_TABLE IN
+# SQL_SELECT.CC ON NESTED SUBQUERY
+#
+CREATE TABLE t1 (
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_nokey int(11) DEFAULT NULL,
+col_int_key int(11) DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+(10,7,8,'01:27:35','v'),
+(28,5,6,'21:44:25','m'),
+(29,NULL,4,'22:43:58','c')
+;
+CREATE TABLE t2 (
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_nokey int(11) DEFAULT NULL,
+col_int_key int(11) DEFAULT NULL,
+col_time_key time DEFAULT NULL,
+col_varchar_key varchar(1) DEFAULT NULL,
+PRIMARY KEY (pk),
+KEY col_int_key (col_int_key),
+KEY col_time_key (col_time_key),
+KEY col_varchar_key (col_varchar_key,col_int_key)
+) ENGINE=InnoDB;
+INSERT INTO t2 VALUES
+(8,8,8,'11:32:06','u'),
+(10,5,53,'15:19:25','o'),
+(16,1,1,'04:56:48','c'),
+(17,0,9,'19:56:05','m'),
+(18,9,5,'19:35:19','y'),
+(20,4,2,'18:38:59','d')
+;
+CREATE TABLE `t3` (
+`field1` varchar(1) DEFAULT NULL,
+`field2` int(11) DEFAULT NULL
+);
+INSERT INTO t3 VALUES ('m', 6),('c',4);
+SELECT *
+FROM t3
+WHERE (field1, field2) IN (
+SELECT alias1.col_varchar_key AS field1,
+alias1.col_int_key AS field2
+FROM ( t1 AS alias1
+INNER JOIN (
+SELECT SQ1_alias1.*
+FROM t2 AS SQ1_alias1
+WHERE SQ1_alias1.col_int_nokey < SQ1_alias1.pk ) AS alias2
+ON (alias2.col_varchar_key = alias1.col_varchar_key )))
+GROUP BY field1, field2
+;
+field1 field2
+c 4
+m 6
+DROP TABLE t1,t2,t3;
+#
=== modified file 'mysql-test/t/derived.test'
--- a/mysql-test/t/derived.test 2011-02-21 14:17:57 +0000
+++ b/mysql-test/t/derived.test 2011-02-21 16:28:03 +0000
@@ -806,3 +806,68 @@ DROP TABLE t1;
DROP TABLE t2;
--echo #
+--echo #
+--echo # Bug#11791677 - ASSERTION FAILED IN JOIN_MATERIALIZE_TABLE IN
+--echo # SQL_SELECT.CC ON NESTED SUBQUERY
+--echo #
+CREATE TABLE t1 (
+ pk int(11) NOT NULL AUTO_INCREMENT,
+ col_int_nokey int(11) DEFAULT NULL,
+ col_int_key int(11) DEFAULT NULL,
+ col_time_key time DEFAULT NULL,
+ col_varchar_key varchar(1) DEFAULT NULL,
+ PRIMARY KEY (pk),
+ KEY col_varchar_key (col_varchar_key,col_int_key)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES
+ (10,7,8,'01:27:35','v'),
+ (28,5,6,'21:44:25','m'),
+ (29,NULL,4,'22:43:58','c')
+;
+
+CREATE TABLE t2 (
+ pk int(11) NOT NULL AUTO_INCREMENT,
+ col_int_nokey int(11) DEFAULT NULL,
+ col_int_key int(11) DEFAULT NULL,
+ col_time_key time DEFAULT NULL,
+ col_varchar_key varchar(1) DEFAULT NULL,
+ PRIMARY KEY (pk),
+ KEY col_int_key (col_int_key),
+ KEY col_time_key (col_time_key),
+ KEY col_varchar_key (col_varchar_key,col_int_key)
+) ENGINE=InnoDB;
+
+INSERT INTO t2 VALUES
+ (8,8,8,'11:32:06','u'),
+ (10,5,53,'15:19:25','o'),
+ (16,1,1,'04:56:48','c'),
+ (17,0,9,'19:56:05','m'),
+ (18,9,5,'19:35:19','y'),
+ (20,4,2,'18:38:59','d')
+;
+
+CREATE TABLE `t3` (
+ `field1` varchar(1) DEFAULT NULL,
+ `field2` int(11) DEFAULT NULL
+);
+
+INSERT INTO t3 VALUES ('m', 6),('c',4);
+
+SELECT *
+FROM t3
+WHERE (field1, field2) IN (
+ SELECT alias1.col_varchar_key AS field1,
+ alias1.col_int_key AS field2
+ FROM ( t1 AS alias1
+ INNER JOIN (
+ SELECT SQ1_alias1.*
+ FROM t2 AS SQ1_alias1
+ WHERE SQ1_alias1.col_int_nokey < SQ1_alias1.pk ) AS alias2
+ ON (alias2.col_varchar_key = alias1.col_varchar_key )))
+ GROUP BY field1, field2
+;
+
+DROP TABLE t1,t2,t3;
+--echo #
+
=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc 2011-02-21 14:17:57 +0000
+++ b/sql/sql_select.cc 2011-02-21 16:28:03 +0000
@@ -18520,6 +18520,13 @@ join_materialize_table(JOIN_TAB *tab)
return -1;
tab->read_first_record=
(READ_RECORD::Setup_func)tab->save_read_first_record.pop();
+ // Adjust read_first_record in saved tab too
+ if (tab->join->join_tab_save)
+ {
+ JOIN *join= tab->join;
+ uint idx= tab - join->join_tab;
+ join->join_tab_save[idx].read_first_record= tab->read_first_record;
+ }
return (*tab->read_first_record)(tab);
}
Attachment: [text/bzr-bundle] bzr/epotemkin@mysql.com-20110221162803-kz2vi212oue9lcsl.bundle