#At file:///data0/martin/bzrroot/bug58690/5.1/ based on revid:georgi.kodinov@stripped
3591 Martin Hansson 2011-02-15
Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
The WHERE condition in a query block may be replaced with a different
expression tree if the top expression is optimized away. Subquery "engines"
were not aware of this, however, and failed to update the WHERE in the
subquery expression to the new condition. This caused problems in filesort, as
it processes nested query block expressions and expects to find a valid
condition.
Fixed by making the "engine" update the pointer after optimizing the query
block.
modified:
mysql-test/r/subselect_innodb.result
mysql-test/t/subselect_innodb.test
sql/item_subselect.cc
sql/item_subselect.h
sql/sql_lex.h
=== modified file 'mysql-test/r/subselect_innodb.result'
--- a/mysql-test/r/subselect_innodb.result 2006-01-26 16:54:34 +0000
+++ b/mysql-test/r/subselect_innodb.result 2011-02-15 10:30:06 +0000
@@ -245,3 +245,21 @@ x
NULL
drop procedure p1;
drop tables t1,t2,t3;
+#
+# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
+# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
+#
+CREATE TABLE t1( a INT );
+INSERT INTO t1 VALUES (0), (1);
+CREATE TABLE t2( b TEXT, c INT, PRIMARY KEY (b( 1 )) ) ENGINE = INNODB;
+INSERT INTO t2 VALUES ('a', ''), ('b', '');
+Warnings:
+Warning 1366 Incorrect integer value: '' for column 'c' at row 1
+Warning 1366 Incorrect integer value: '' for column 'c' at row 2
+SELECT 1 FROM t1 WHERE a =
+(SELECT 1 FROM t2 WHERE b =
+(SELECT 1 FROM t1 t11 WHERE c = 1 OR t1.a = 1 AND 1 = 2)
+GROUP BY b
+);
+1
+DROP TABLE t1, t2;
=== modified file 'mysql-test/t/subselect_innodb.test'
--- a/mysql-test/t/subselect_innodb.test 2006-01-26 16:54:34 +0000
+++ b/mysql-test/t/subselect_innodb.test 2011-02-15 10:30:06 +0000
@@ -238,3 +238,22 @@ call p1();
call p1();
drop procedure p1;
drop tables t1,t2,t3;
+--echo #
+--echo # Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET ||
+--echo # BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX
+--echo #
+--source include/have_innodb.inc
+
+CREATE TABLE t1( a INT );
+INSERT INTO t1 VALUES (0), (1);
+
+CREATE TABLE t2( b TEXT, c INT, PRIMARY KEY (b( 1 )) ) ENGINE = INNODB;
+INSERT INTO t2 VALUES ('a', ''), ('b', '');
+
+SELECT 1 FROM t1 WHERE a =
+ (SELECT 1 FROM t2 WHERE b =
+ (SELECT 1 FROM t1 t11 WHERE c = 1 OR t1.a = 1 AND 1 = 2)
+ GROUP BY b
+ );
+
+DROP TABLE t1, t2;
=== modified file 'sql/item_subselect.cc'
--- a/sql/item_subselect.cc 2010-12-28 23:47:05 +0000
+++ b/sql/item_subselect.cc 2011-02-15 10:30:06 +0000
@@ -1893,6 +1893,9 @@ int subselect_single_select_engine::exec
thd->lex->current_select= save_select;
DBUG_RETURN(join->error ? join->error : 1);
}
+ /* The WHERE condition may have been replaced during JOIN::optimize */
+ item->get_unit()->first_select()->where = join->conds;
+
if (!select_lex->uncacheable && thd->lex->describe &&
!(join->select_options & SELECT_DESCRIBE))
{
=== modified file 'sql/item_subselect.h'
--- a/sql/item_subselect.h 2010-12-14 09:33:03 +0000
+++ b/sql/item_subselect.h 2011-02-15 10:30:06 +0000
@@ -68,6 +68,8 @@ public:
Item_subselect();
+ const st_select_lex_unit *get_unit() const { return unit; }
+
virtual subs_type substype() { return UNKNOWN_SUBS; }
/*
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2011-01-26 07:32:41 +0000
+++ b/sql/sql_lex.h 2011-02-15 10:30:06 +0000
@@ -533,7 +533,7 @@ public:
void init_query();
st_select_lex_unit* master_unit();
st_select_lex* outer_select();
- st_select_lex* first_select()
+ st_select_lex* first_select() const
{
return my_reinterpret_cast(st_select_lex*)(slave);
}
Attachment: [text/bzr-bundle] bzr/martin.hansson@oracle.com-20110215103006-6t6nyxnc5b4g5y3u.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (martin.hansson:3591) | Martin Hansson | 15 Feb |