Commit 62e7ab3a authored by unknown's avatar unknown

Fix bugs lp:833777, lp:894397

Analysis:
lp:894397 was a consequence of a prior incorrect fix of lp:833777
which didn't take into account that even when all tables are
constant there may be correlated conditions, and the where clause
is not equivalent to the constant conditions.

Solution:
When there are constant tables only, evaluate only the conditions
that reference outer fields, because the constant conditions are
already checked, and the where clause doesn't have other conditions
than constant ones, and outer referencing ones. The fix for
lp:894397 also fixes lp:833777.
parent 5412e82c
...@@ -5686,8 +5686,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer ...@@ -5686,8 +5686,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
a a
1 1
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
# #
# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
#
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
a
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
#
# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
# with view , UNION and prepared statement (rewriting fake_select # with view , UNION and prepared statement (rewriting fake_select
# condition). # condition).
......
...@@ -5685,8 +5685,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer ...@@ -5685,8 +5685,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
a a
1 1
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
# #
# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
#
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
a
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
#
# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
# with view , UNION and prepared statement (rewriting fake_select # with view , UNION and prepared statement (rewriting fake_select
# condition). # condition).
......
...@@ -5681,8 +5681,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer ...@@ -5681,8 +5681,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
a a
1 1
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
# #
# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
#
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
a
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
#
# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
# with view , UNION and prepared statement (rewriting fake_select # with view , UNION and prepared statement (rewriting fake_select
# condition). # condition).
......
...@@ -5690,8 +5690,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer ...@@ -5690,8 +5690,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
a a
1 1
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
# #
# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
#
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
a
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
#
# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
# with view , UNION and prepared statement (rewriting fake_select # with view , UNION and prepared statement (rewriting fake_select
# condition). # condition).
......
...@@ -5681,8 +5681,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer ...@@ -5681,8 +5681,21 @@ set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquer
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
a a
1 1
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
# #
# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
#
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
a
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
#
# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
# with view , UNION and prepared statement (rewriting fake_select # with view , UNION and prepared statement (rewriting fake_select
# condition). # condition).
......
...@@ -4782,8 +4782,22 @@ create table t1 (a int not null, b char(10) not null); ...@@ -4782,8 +4782,22 @@ create table t1 (a int not null, b char(10) not null);
insert into t1 values (1, 'a'); insert into t1 values (1, 'a');
set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off'; set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1)))))))))))))))))))))))))))));
set @@optimizer_switch=@subselect_tmp;
drop table t1; drop table t1;
--echo #
--echo # LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF
--echo #
CREATE TABLE t1 (a varchar(3));
INSERT INTO t1 VALUES ('AAA'),('BBB');
CREATE TABLE t2 (a varchar(3));
INSERT INTO t2 VALUES ('CCC');
set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ');
set @@optimizer_switch=@subselect_tmp;
drop table t1, t2;
--echo # --echo #
--echo # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize --echo # LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize
--echo # with view , UNION and prepared statement (rewriting fake_select --echo # with view , UNION and prepared statement (rewriting fake_select
......
...@@ -14775,15 +14775,15 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure) ...@@ -14775,15 +14775,15 @@ do_select(JOIN *join,List<Item> *fields,TABLE *table,Procedure *procedure)
{ {
/* /*
HAVING will be checked after processing aggregate functions, HAVING will be checked after processing aggregate functions,
But WHERE should checkd here (we alredy have read tables). But WHERE should checked here (we alredy have read tables).
If there is join->exec_const_cond, and all tables are constant, then it Notice that make_join_select() splits all conditions into three groups -
is equivalent to join->conds. exec_const_cond is already checked in the exec_const_cond, outer_ref_cond, and conditions attached to non-constant
beginning of JOIN::exec. If it is false, JOIN::exec returns zero tables. Within this IF the latter do not exist. At the same time
result already there, therefore execution reaches this point only if exec_const_cond is already checked either by make_join_select or in the
exec_const_cond is TRUE. Since it is equvalent to join->conds, then beginning of JOIN::exec. Therefore here it is sufficient to check only
join->conds is also TRUE. outer_ref_cond.
*/ */
if (!join->conds || join->exec_const_cond || join->conds->val_int()) if (!join->outer_ref_cond || join->outer_ref_cond->val_int())
{ {
error= (*end_select)(join, 0, 0); error= (*end_select)(join, 0, 0);
if (error == NESTED_LOOP_OK || error == NESTED_LOOP_QUERY_LIMIT) if (error == NESTED_LOOP_OK || error == NESTED_LOOP_QUERY_LIMIT)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment