mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
[NOT] EXISTS to IN transformation.
This commit is contained in:
parent
a555ceb2fb
commit
e3ac306157
27 changed files with 9578 additions and 133 deletions
|
@ -498,8 +498,8 @@ The following options may be given as the first argument:
|
|||
mrr_cost_based, mrr_sort_keys, optimize_join_buffer_size,
|
||||
outer_join_with_cache, partial_match_rowid_merge,
|
||||
partial_match_table_scan, semijoin, semijoin_with_cache,
|
||||
subquery_cache, table_elimination, extended_keys } and
|
||||
val is one of {on, off, default}
|
||||
subquery_cache, table_elimination, extended_keys,
|
||||
exists_to_in } and val is one of {on, off, default}
|
||||
--performance-schema
|
||||
Enable the performance schema.
|
||||
--performance-schema-events-waits-history-long-size=#
|
||||
|
|
865
mysql-test/r/subselect_exists2in.result
Normal file
865
mysql-test/r/subselect_exists2in.result
Normal file
|
@ -0,0 +1,865 @@
|
|||
drop table if exists t1,t2,t3;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# LP BUG#884644 exists2in broke name resolution
|
||||
#
|
||||
CREATE TABLE t1 (f1 integer);
|
||||
SELECT * FROM t1 WHERE EXISTS (SELECT NO_SUCH_TABLE.NO_SUCH_FIELD FROM t1);
|
||||
ERROR 42S22: Unknown column 'NO_SUCH_TABLE.NO_SUCH_FIELD' in 'field list'
|
||||
drop table t1;
|
||||
#
|
||||
# LP BUG#884657 Wrong result with exists2in , correlated subquery
|
||||
#
|
||||
CREATE TABLE t1 ( a varchar(1)) ;
|
||||
INSERT INTO t1 VALUES ('c'),('b');
|
||||
CREATE TABLE t2 ( b varchar(1)) ;
|
||||
INSERT INTO t2 VALUES ('v'),('v'),('c'),(NULL),('x'),('i'),('e'),('p'),('s'),('j'),('z'),('c'),('a'),('q'),('y'),(NULL),('r'),('v'),(NULL),('r');
|
||||
CREATE TABLE t3 ( a int NOT NULL , b varchar(1)) ;
|
||||
INSERT INTO t3 VALUES (29,'c');
|
||||
SELECT *
|
||||
FROM t1, t2
|
||||
WHERE EXISTS (
|
||||
SELECT a
|
||||
FROM t3
|
||||
WHERE t3.b = t1.a
|
||||
AND t3.b <> t2.b
|
||||
);
|
||||
a b
|
||||
c v
|
||||
c v
|
||||
c x
|
||||
c i
|
||||
c e
|
||||
c p
|
||||
c s
|
||||
c j
|
||||
c z
|
||||
c a
|
||||
c q
|
||||
c y
|
||||
c r
|
||||
c v
|
||||
c r
|
||||
INSERT INTO t3 VALUES (2,'c');
|
||||
alter table t1 add index aa (a);
|
||||
alter table t3 add index bb (b);
|
||||
-- EXIST to IN then semijoin (has priority over IN to EXISTS)
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
a
|
||||
c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index aa aa 4 NULL 2 100.00 Using index
|
||||
1 PRIMARY t3 ALL bb NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join)
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3`) where (`test`.`t3`.`b` = `test`.`t1`.`a`)
|
||||
-- EXIST to IN then IN to EXISTS
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
a
|
||||
c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t3`.`b` from `test`.`t3` where (<cache>(`test`.`t1`.`a`) = `test`.`t3`.`b`)))
|
||||
-- EXIST2IN then MATERIALIZATION
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
a
|
||||
c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index
|
||||
2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t3`.`b` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`)))))
|
||||
-- NO EXIST2IN
|
||||
set optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
a
|
||||
c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select `test`.`t3`.`a` from `test`.`t3` where (`test`.`t3`.`b` = `test`.`t1`.`a`))
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop table t1,t2,t3;
|
||||
#
|
||||
# From group_min_max.test
|
||||
#
|
||||
create table t1 (
|
||||
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
|
||||
);
|
||||
insert into t1 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
|
||||
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
|
||||
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
|
||||
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
|
||||
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
|
||||
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
|
||||
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
|
||||
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
|
||||
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
|
||||
create index idx_t1_0 on t1 (a1);
|
||||
create index idx_t1_1 on t1 (a1,a2,b,c);
|
||||
create index idx_t1_2 on t1 (a1,a2,b);
|
||||
analyze table t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 analyze status Table is already up to date
|
||||
create table t2 (
|
||||
a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
|
||||
);
|
||||
insert into t2 select * from t1;
|
||||
insert into t2 (a1, a2, b, c, d) values
|
||||
('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
|
||||
('a','a','a',NULL,'xyz'),
|
||||
('a','a','b',NULL,'xyz'),
|
||||
('a','b','a',NULL,'xyz'),
|
||||
('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
|
||||
('d','b','b',NULL,'xyz'),
|
||||
('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
|
||||
('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),
|
||||
('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
|
||||
('a','a','a',NULL,'xyz'),
|
||||
('a','a','b',NULL,'xyz'),
|
||||
('a','b','a',NULL,'xyz'),
|
||||
('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
|
||||
('d','b','b',NULL,'xyz'),
|
||||
('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
|
||||
('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz');
|
||||
create index idx_t2_0 on t2 (a1);
|
||||
create index idx_t2_1 on t2 (a1,a2,b,c);
|
||||
create index idx_t2_2 on t2 (a1,a2,b);
|
||||
analyze table t2;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t2 analyze status Table is already up to date
|
||||
create table t3 (
|
||||
a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
|
||||
);
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
create index idx_t3_0 on t3 (a1);
|
||||
create index idx_t3_1 on t3 (a1,a2,b,c);
|
||||
create index idx_t3_2 on t3 (a1,a2,b);
|
||||
analyze table t3;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t3 analyze status Table is already up to date
|
||||
explain select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.b) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2); Using join buffer (flat, BNL join)
|
||||
select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.b) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
a1 a2 b c min(c) max(c)
|
||||
a a a a111 a111 d111
|
||||
a a b e112 e112 h112
|
||||
a b a i121 i121 l121
|
||||
a b b m122 m122 p122
|
||||
b a a a211 a211 d211
|
||||
b a b e212 e212 h212
|
||||
b b a i221 i221 l221
|
||||
b b b m222 m222 p222
|
||||
c a a a311 a311 d311
|
||||
c a b e312 e312 h312
|
||||
c b a i321 i321 l321
|
||||
c b b m322 m322 p322
|
||||
d a a a411 a411 d411
|
||||
d a b e412 e412 h412
|
||||
d b a i421 i421 l421
|
||||
d b b m422 m422 p422
|
||||
explain select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.c) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2); Using join buffer (flat, BNL join)
|
||||
select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.c) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
a1 a2 b c min(c) max(c)
|
||||
a a a a111 a111 d111
|
||||
a a b e112 e112 h112
|
||||
a b a i121 i121 l121
|
||||
a b b m122 m122 p122
|
||||
b a a a211 a211 d211
|
||||
b a b e212 e212 h212
|
||||
b b a i221 i221 l221
|
||||
b b b m222 m222 p222
|
||||
c a a a311 a311 d311
|
||||
c a b e312 e312 h312
|
||||
c b a i321 i321 l321
|
||||
c b b m322 m322 o322
|
||||
d a a a411 a411 d411
|
||||
d a b e412 e412 h412
|
||||
d b a i421 i421 l421
|
||||
d b b m422 m422 o422
|
||||
drop table t1, t2, t3;
|
||||
CREATE TABLE t1 ( a INT );
|
||||
INSERT INTO t1 VALUES (7),(0);
|
||||
CREATE TABLE t2 ( b INT );
|
||||
INSERT INTO t2 VALUES (0),(8);
|
||||
SELECT * FROM t1 WHERE
|
||||
EXISTS ( SELECT * FROM t2 WHERE b = a )
|
||||
OR a > 0;
|
||||
a
|
||||
7
|
||||
0
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE
|
||||
EXISTS ( SELECT * FROM t2 WHERE b = a )
|
||||
OR a > 0;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`b` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`)))))) or (`test`.`t1`.`a` > 0))
|
||||
drop tables t1,t2;
|
||||
CREATE TABLE t1 ( a INT );
|
||||
INSERT INTO t1 VALUES (1),(5);
|
||||
CREATE TABLE t2 ( b INT ) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (1);
|
||||
CREATE TABLE t3 ( c INT );
|
||||
INSERT INTO t3 VALUES (4),(5);
|
||||
SET optimizer_switch='exists_to_in=on,subquery_cache=off,materialization=on,in_to_exists=off,semijoin=off';
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00
|
||||
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2
|
||||
Note 1003 select (select 1 from dual where (not(((1 is not null) and <in_optimizer>(1,1 in ( <materialize> (select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` is not null) ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery3>`.`c`))))))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1`
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )
|
||||
1
|
||||
1
|
||||
SET optimizer_switch='exists_to_in=on,subquery_cache=off';
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00
|
||||
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2
|
||||
Note 1003 select (select 1 from dual where (not(((1 is not null) and <in_optimizer>(1,1 in ( <materialize> (select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` is not null) ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery3>`.`c`))))))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1`
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )
|
||||
1
|
||||
1
|
||||
SET optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00
|
||||
3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2
|
||||
Note 1003 select (select 1 from dual where (not(exists(select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` = 1))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1`
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )
|
||||
1
|
||||
1
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop table t1,t2,t3;
|
||||
# multi condition test
|
||||
CREATE TABLE t1 ( a varchar(1), a1 varchar(1)) ;
|
||||
INSERT INTO t1 VALUES ('c', 'c'), ('b', 'b');
|
||||
CREATE TABLE t3 ( a int NOT NULL , b varchar(1), b1 varchar(1)) ;
|
||||
INSERT INTO t3 VALUES (29,'c','c');
|
||||
INSERT INTO t3 VALUES (2,'c','c');
|
||||
alter table t1 add index aa (a,a1);
|
||||
alter table t3 add index bb (b,b1);
|
||||
-- EXIST to IN then semijoin (has priority over IN to EXISTS)
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
a a1
|
||||
c c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t3 index bb bb 8 NULL 2 100.00 Using where; Using index; LooseScan
|
||||
1 PRIMARY t1 ref aa aa 8 test.t3.b,test.t3.b1 2 100.00 Using index
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` semi join (`test`.`t3`) where ((`test`.`t1`.`a1` = `test`.`t3`.`b1`) and (`test`.`t1`.`a` = `test`.`t3`.`b`))
|
||||
-- EXIST to IN then IN to EXISTS
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
a a1
|
||||
c c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 index_subquery bb bb 8 func,func 2 100.00 Using index; Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a1`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t3 on bb where ((<cache>(`test`.`t1`.`a`) = `test`.`t3`.`b`) and (<cache>(`test`.`t1`.`a1`) = `test`.`t3`.`b1`)))))
|
||||
-- EXIST2IN then MATERIALIZATION
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
a a1
|
||||
c c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index
|
||||
2 MATERIALIZED t3 index NULL bb 8 NULL 2 100.00 Using index
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a1`),(`test`.`t1`.`a`,`test`.`t1`.`a1`) in ( <materialize> (select `test`.`t3`.`b`,`test`.`t3`.`b1` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`)))))
|
||||
-- NO EXIST2IN
|
||||
set optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
a a1
|
||||
c c
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index
|
||||
2 DEPENDENT SUBQUERY t3 ref bb bb 8 test.t1.a,test.t1.a1 2 100.00 Using index
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where exists(select 1 from `test`.`t3` where ((`test`.`t3`.`b` = `test`.`t1`.`a`) and (`test`.`t3`.`b1` = `test`.`t1`.`a1`)))
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop table t1,t3;
|
||||
#
|
||||
# MDEV-159 Assertion about not marked for read failed in
|
||||
# String* Field_varstring::val_str(String*, String*)
|
||||
#
|
||||
SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
|
||||
SET optimizer_switch='in_to_exists=on,exists_to_in=on';
|
||||
CREATE TABLE t1 ( a VARCHAR(1) );
|
||||
INSERT INTO t1 VALUES ('k'),('m');
|
||||
CREATE TABLE t2 ( b INT,
|
||||
c VARCHAR(1),
|
||||
d VARCHAR(1) NOT NULL );
|
||||
INSERT INTO t2 VALUES
|
||||
(4,'j','j'),(6,'v','v');
|
||||
CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t2 WHERE b < 1;
|
||||
SELECT c FROM v
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= v.d AND b = v.b
|
||||
);
|
||||
c
|
||||
explain extended
|
||||
SELECT c FROM v
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= v.d AND b = v.b
|
||||
);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'v.d' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'v.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t2`.`c` AS `c` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b`,<exists>(select `test`.`t2`.`b` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <= `test`.`t2`.`d`) and (<cache>(`test`.`t2`.`b`) = `test`.`t2`.`b`)))) and (`test`.`t2`.`b` < 1))
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop view v;
|
||||
drop table t1,t2;
|
||||
#
|
||||
# MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
|
||||
#
|
||||
SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (
|
||||
a VARCHAR(3) NOT NULL,
|
||||
b VARCHAR(50)
|
||||
);
|
||||
INSERT INTO t1 VALUES
|
||||
('USA','Chinese'),('USA','English'),
|
||||
('FRA','French'),('ITA','Italian');
|
||||
CREATE TABLE t2 ( c VARCHAR(3) );
|
||||
INSERT INTO t2 VALUES ('USA'),('FRA');
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
a b a b
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.a
|
||||
) OR alias1 .a = 'foo';
|
||||
a b a b
|
||||
USA Chinese USA Chinese
|
||||
USA English USA Chinese
|
||||
FRA French USA Chinese
|
||||
USA Chinese USA English
|
||||
USA English USA English
|
||||
FRA French USA English
|
||||
USA Chinese FRA French
|
||||
USA English FRA French
|
||||
FRA French FRA French
|
||||
USA Chinese ITA Italian
|
||||
USA English ITA Italian
|
||||
FRA French ITA Italian
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
|
||||
#
|
||||
SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (
|
||||
a VARCHAR(3) NOT NULL,
|
||||
b VARCHAR(50)
|
||||
);
|
||||
INSERT INTO t1 VALUES
|
||||
('USA','Chinese'),('USA','English'),
|
||||
('FRA','French'),('ITA','Italian');
|
||||
CREATE TABLE t2 ( c VARCHAR(3) );
|
||||
INSERT INTO t2 VALUES ('USA'),('FRA');
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
a b a b
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY alias1 ALL NULL NULL NULL NULL 4 100.00
|
||||
1 PRIMARY alias2 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join)
|
||||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join)
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.alias2.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.alias1.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias1`.`b` AS `b`,`test`.`alias2`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where (<expr_cache><`test`.`alias1`.`b`,`test`.`alias2`.`a`>(<in_optimizer>(`test`.`alias1`.`b`,<exists>(select `test`.`t2`.`c` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <= `test`.`alias2`.`a`) and (<cache>(`test`.`alias1`.`b`) = `test`.`t2`.`c`))))) or (`test`.`alias1`.`a` = 'foo'))
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-245 Exists2In: Wrong result (extra rows) with
|
||||
# exists_to_in=ON, materialization=OFF, NOT EXISTS subquery
|
||||
#
|
||||
SET optimizer_switch='materialization=off,exists_to_in=on';
|
||||
CREATE TABLE t1 ( a INT ) ;
|
||||
INSERT INTO t1 VALUES (0),(8),(1);
|
||||
CREATE TABLE t2 ( b INT ) ;
|
||||
INSERT INTO t2 VALUES (1),(2),(3);
|
||||
SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
a
|
||||
0
|
||||
8
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(((`test`.`t1`.`a` is not null) and <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` is not null) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`))))))))
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-243 Wrong result (extra or missing rows) with
|
||||
# exists_to_in + materialization, EXISTS subquery
|
||||
#
|
||||
SET optimizer_switch='index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on';
|
||||
CREATE TABLE t1 ( a VARCHAR(1), b VARCHAR(1) );
|
||||
INSERT INTO t1 VALUES ('v','v'),('s','v');
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
a b
|
||||
s v
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(alias); Using join buffer (flat, BNL join)
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`alias`.`b`) and (`test`.`alias`.`b` > `test`.`alias`.`a`))
|
||||
SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
|
||||
SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=off';
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
a b
|
||||
s v
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` where <in_optimizer>(`test`.`alias`.`b`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where ((`test`.`t1`.`a` > `test`.`alias`.`a`) and (<cache>(`test`.`alias`.`b`) = `test`.`t1`.`a`))))
|
||||
SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=on';
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
a b
|
||||
s v
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`alias`.`b`) and (`test`.`alias`.`b` > `test`.`alias`.`a`))
|
||||
drop table t1;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-403 Wrong result (missing rows) with subquery in
|
||||
# EXISTS and an OR condition outside
|
||||
#
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (2),(3);
|
||||
CREATE TABLE t2 (b INT);
|
||||
INSERT INTO t2 VALUES (1),(3);
|
||||
SET optimizer_switch = 'exists_to_in=off,in_to_exists=on';
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
a b
|
||||
3 1
|
||||
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
a b
|
||||
3 1
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 100.00
|
||||
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
|
||||
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t2` `alias2` where (<expr_cache><`test`.`alias1`.`a`,`test`.`alias2`.`b`>(<in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` > `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t2`.`b`))))) or (`test`.`alias1`.`a` = 5))
|
||||
drop table t1, t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-404: Wrong result (extra rows) with STRAIGHT_JOIN,
|
||||
# EXISTS subquery, NOT NULL column
|
||||
# (same as above)
|
||||
#
|
||||
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
|
||||
CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL);
|
||||
INSERT INTO t1 VALUES (1,'s'),(2,'e');
|
||||
SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a );
|
||||
a b a b
|
||||
2 e 1 s
|
||||
drop table t1;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-3800: ORDER BY doesn't work with exists_to_in=ON on
|
||||
# a query with EXISTS subquery and OR condition
|
||||
#
|
||||
SET optimizer_switch = 'in_to_exists=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (4,'j'),(6,'v'),(3,'c');
|
||||
CREATE TABLE t2 (c VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('b'),('y');
|
||||
SELECT a FROM t1
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE c = b
|
||||
) OR b NOT IN ('U')
|
||||
ORDER BY a;
|
||||
a
|
||||
3
|
||||
4
|
||||
6
|
||||
select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` in (select `test`.`t2`.`c` from `test`.`t2` where 1 ) or (`test`.`t1`.`b` <> 'U') order by `test`.`t1`.`a`;
|
||||
a
|
||||
3
|
||||
4
|
||||
6
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# correct calculation of reserved items (postreview-fix)
|
||||
#
|
||||
create table t1 (col1 int, col2 int, col3 int);
|
||||
insert into t1 values (1,2,3),(2,3,4),(4,5,6);
|
||||
create table t2 as select * from t1;
|
||||
explain extended
|
||||
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
|
||||
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00
|
||||
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00
|
||||
Warnings:
|
||||
Note 1276 Field or reference 'test.t1.col1' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1276 Field or reference 'test.t1.col2' of SELECT #2 was resolved in SELECT #1
|
||||
Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t1`.`col2` AS `col2`,`test`.`t1`.`col3` AS `col3` from `test`.`t1` semi join (`test`.`t2`) where 1
|
||||
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
|
||||
col1 col2 col3
|
||||
1 2 3
|
||||
2 3 4
|
||||
4 5 6
|
||||
drop table t1,t2;
|
||||
#
|
||||
# MDEV-3879: Exists2In: Wrong result (extra row) and unexpected
|
||||
# warning with exists_to_in=on and a NOT EXISTS subquery
|
||||
#
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (3,'y'),(6,'w');
|
||||
CREATE TABLE t2 (a2 INT, b2 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (3,'y'),(6,'d');
|
||||
SELECT * FROM t1
|
||||
WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b2 = b1 AND a2 = a1 );
|
||||
a1 b1
|
||||
6 w
|
||||
drop table t1, t2;
|
||||
#
|
||||
# MDEV-3880: Wrong result (missing rows) with exists_to_in=on,
|
||||
# LEFT JOIN and NOT EXISTS subquery.
|
||||
# (Duplicate of above MDEV-3879).
|
||||
#
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (4,'b'),(5,'y');
|
||||
CREATE TABLE t2 (b2 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('z'),('b');
|
||||
CREATE TABLE t3 (a3 INT, b3 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4,'j'),(6,'v');
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON ( b2 = b1 )
|
||||
WHERE NOT EXISTS ( SELECT * FROM t3 WHERE b3 = b2 AND a3 = a1 ) ;
|
||||
a1 b1 b2
|
||||
4 b b
|
||||
5 y NULL
|
||||
drop table t1, t2, t3;
|
||||
#
|
||||
# MDEV-3881: Endless loop and crash in Item_ref::real_item with
|
||||
# exists_to_in=on, NOT EXISTS subquery, merge view or from subquery,
|
||||
# constant table
|
||||
#
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (8);
|
||||
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2;
|
||||
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4),(6);
|
||||
SELECT * FROM t1, v1 WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
|
||||
a b
|
||||
drop view v1;
|
||||
drop table t1, t2, t3;
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (8);
|
||||
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4),(6);
|
||||
SELECT * FROM t1, ( SELECT * FROM t2 ) alias WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
|
||||
a b
|
||||
drop table t1, t2, t3;
|
||||
#
|
||||
# MDEV-3906: Server crashes in Dependency_marker::visit_field
|
||||
# on 2nd execution of PS with exists_to_in and NOT EXISTS subquery
|
||||
#
|
||||
SET optimizer_switch='exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
PREPARE stmt FROM '
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE NOT EXISTS ( SELECT * FROM t1 WHERE t1.a = alias.a )
|
||||
';
|
||||
EXECUTE stmt;
|
||||
a
|
||||
EXECUTE stmt;
|
||||
a
|
||||
drop table t1;
|
||||
#
|
||||
# MDEV-3904: Assertion `in_subs->has_strategy()' failed in
|
||||
# JOIN::choose_subquery_plan on 2nd execution of PS with
|
||||
# exists_to_in+semijoin, EXISTS subquery, MERGE view or FROM subquery
|
||||
#
|
||||
SET optimizer_switch='in_to_exists=on,semijoin=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (4),(6);
|
||||
CREATE ALGORITHM=MERGE VIEW v AS
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
PREPARE stmt FROM ' SELECT * FROM v ';
|
||||
EXECUTE stmt;
|
||||
a
|
||||
EXECUTE stmt;
|
||||
a
|
||||
drop view v;
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-3903: Server crashes in Item_cond::fix_fields on 2nd execution
|
||||
# of a prepared stmt with exists_to_in+materialization+semijoin,
|
||||
# EXISTS subquery, STRAIGHT_JOIN
|
||||
#
|
||||
SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (3),(4);
|
||||
PREPARE stmt FROM
|
||||
'SELECT STRAIGHT_JOIN * FROM t1
|
||||
WHERE EXISTS ( SELECT * FROM t2 WHERE b = a )';
|
||||
EXECUTE stmt;
|
||||
a
|
||||
EXECUTE stmt;
|
||||
a
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
#
|
||||
# MDEV-4152: Wrong result (missing rows) with exists_to_in=on,
|
||||
# inner joins
|
||||
#
|
||||
SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (i INT, c1 CHAR(5), c2 CHAR(5), t1_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1,'test1','test2','f'), (2,'test3','test4','d');
|
||||
CREATE TABLE t2 (t2_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('m'), ('b');
|
||||
CREATE TABLE t3 (t3_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES ('b'),('c');
|
||||
SELECT * FROM t1, t2 outer_t2
|
||||
WHERE EXISTS ( SELECT 1 FROM t2, t3 WHERE t3_field = outer_t2.t2_field AND t2_field <= t1_field );
|
||||
i c1 c2 t1_field t2_field
|
||||
1 test1 test2 f b
|
||||
2 test3 test4 d b
|
||||
drop table t1,t2,t3;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
set optimizer_switch=default;
|
103
mysql-test/r/subselect_exists2in_costmat.result
Normal file
103
mysql-test/r/subselect_exists2in_costmat.result
Normal file
|
@ -0,0 +1,103 @@
|
|||
set @subselect_mat_cost=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
|
||||
set long_query_time=0.1;
|
||||
drop database if exists world;
|
||||
set names utf8;
|
||||
create database world;
|
||||
use world;
|
||||
CREATE TABLE Country (
|
||||
Code char(3) NOT NULL default '',
|
||||
Name char(52) NOT NULL default '',
|
||||
SurfaceArea float(10,2) NOT NULL default '0.00',
|
||||
Population int(11) NOT NULL default '0',
|
||||
Capital int(11) default NULL,
|
||||
PRIMARY KEY (Code),
|
||||
UNIQUE INDEX (Name)
|
||||
);
|
||||
CREATE TABLE City (
|
||||
ID int(11) NOT NULL auto_increment,
|
||||
Name char(35) NOT NULL default '',
|
||||
Country char(3) NOT NULL default '',
|
||||
Population int(11) NOT NULL default '0',
|
||||
PRIMARY KEY (ID),
|
||||
INDEX (Population),
|
||||
INDEX (Country)
|
||||
);
|
||||
CREATE TABLE CountryLanguage (
|
||||
Country char(3) NOT NULL default '',
|
||||
Language char(30) NOT NULL default '',
|
||||
Percentage float(3,1) NOT NULL default '0.0',
|
||||
PRIMARY KEY (Country, Language),
|
||||
INDEX (Percentage)
|
||||
);
|
||||
Make the schema and data more diverse by adding more indexes, nullable
|
||||
columns, and NULL data.
|
||||
create index SurfaceArea on Country(SurfaceArea);
|
||||
create index Language on CountryLanguage(Language);
|
||||
create index CityName on City(Name);
|
||||
alter table City change population population int(11) null default 0;
|
||||
select max(id) from City into @max_city_id;
|
||||
insert into City values (@max_city_id + 1,'Kilifarevo','BGR',NULL);
|
||||
SELECT COUNT(*) FROM Country;
|
||||
COUNT(*)
|
||||
239
|
||||
SELECT COUNT(*) FROM City;
|
||||
COUNT(*)
|
||||
4080
|
||||
SELECT COUNT(*) FROM CountryLanguage;
|
||||
COUNT(*)
|
||||
984
|
||||
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
|
||||
|
||||
1. Subquery in a disjunctive WHERE clause of the outer query.
|
||||
|
||||
|
||||
Q1.1m:
|
||||
MATERIALIZATION: there are too many rows in the outer query
|
||||
to be looked up in the inner table.
|
||||
EXPLAIN
|
||||
SELECT Name FROM Country
|
||||
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
|
||||
Code = Country) OR
|
||||
Name LIKE 'L%') AND
|
||||
surfacearea > 1000000;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where
|
||||
2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4080 Using where
|
||||
SELECT Name FROM Country
|
||||
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
|
||||
Code = Country) OR
|
||||
Name LIKE 'L%') AND
|
||||
surfacearea > 1000000;
|
||||
Name
|
||||
Algeria
|
||||
Angola
|
||||
Argentina
|
||||
Australia
|
||||
Bolivia
|
||||
Brazil
|
||||
Egypt
|
||||
South Africa
|
||||
Ethiopia
|
||||
Indonesia
|
||||
India
|
||||
Iran
|
||||
Canada
|
||||
Kazakstan
|
||||
China
|
||||
Colombia
|
||||
Congo, The Democratic Republic of the
|
||||
Libyan Arab Jamahiriya
|
||||
Mali
|
||||
Mauritania
|
||||
Mexico
|
||||
Mongolia
|
||||
Niger
|
||||
Peru
|
||||
Saudi Arabia
|
||||
Sudan
|
||||
Chad
|
||||
Russian Federation
|
||||
United States
|
||||
drop database world;
|
||||
set optimizer_switch=@subselect_mat_cost;
|
7021
mysql-test/r/subselect_exists_to_in.result
Normal file
7021
mysql-test/r/subselect_exists_to_in.result
Normal file
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@ SELECT @global_start_value;
|
|||
select @old_session_opt_switch:=@@session.optimizer_switch,
|
||||
@old_global_opt_switch:=@@global.optimizer_switch;
|
||||
@old_session_opt_switch:=@@session.optimizer_switch @old_global_opt_switch:=@@global.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
'#--------------------FN_DYNVARS_028_01------------------------#'
|
||||
SET @@session.engine_condition_pushdown = 0;
|
||||
Warnings:
|
||||
|
@ -212,7 +212,7 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@session.engine_condition_pushdown = TRUE;
|
||||
Warnings:
|
||||
Warning 1287 '@@engine_condition_pushdown' is deprecated and will be removed in a future release. Please use '@@optimizer_switch' instead
|
||||
|
@ -220,7 +220,7 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
1 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
1 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@session.engine_condition_pushdown = FALSE;
|
||||
Warnings:
|
||||
Warning 1287 '@@engine_condition_pushdown' is deprecated and will be removed in a future release. Please use '@@optimizer_switch' instead
|
||||
|
@ -228,7 +228,7 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@global.engine_condition_pushdown = TRUE;
|
||||
Warnings:
|
||||
Warning 1287 '@@engine_condition_pushdown' is deprecated and will be removed in a future release. Please use '@@optimizer_switch' instead
|
||||
|
@ -236,7 +236,7 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@global.engine_condition_pushdown = FALSE;
|
||||
Warnings:
|
||||
Warning 1287 '@@engine_condition_pushdown' is deprecated and will be removed in a future release. Please use '@@optimizer_switch' instead
|
||||
|
@ -244,31 +244,31 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@session.optimizer_switch = "engine_condition_pushdown=on";
|
||||
select @@session.engine_condition_pushdown,
|
||||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
1 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
1 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@session.optimizer_switch = "engine_condition_pushdown=off";
|
||||
select @@session.engine_condition_pushdown,
|
||||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@global.optimizer_switch = "engine_condition_pushdown=on";
|
||||
select @@session.engine_condition_pushdown,
|
||||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set @@global.optimizer_switch = "engine_condition_pushdown=off";
|
||||
select @@session.engine_condition_pushdown,
|
||||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
SET @@session.engine_condition_pushdown = @session_start_value;
|
||||
Warnings:
|
||||
Warning 1287 '@@engine_condition_pushdown' is deprecated and will be removed in a future release. Please use '@@optimizer_switch' instead
|
||||
|
@ -287,4 +287,4 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
SET @start_global_value = @@global.optimizer_switch;
|
||||
SELECT @start_global_value;
|
||||
@start_global_value
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
select @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
select @@session.optimizer_switch;
|
||||
@@session.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
show global variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
show session variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
select * from information_schema.global_variables where variable_name='optimizer_switch';
|
||||
VARIABLE_NAME VARIABLE_VALUE
|
||||
OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
select * from information_schema.session_variables where variable_name='optimizer_switch';
|
||||
VARIABLE_NAME VARIABLE_VALUE
|
||||
OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
set global optimizer_switch=10;
|
||||
set session optimizer_switch=5;
|
||||
select @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=off,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
select @@session.optimizer_switch;
|
||||
@@session.optimizer_switch
|
||||
index_merge=on,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
index_merge=on,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
set global optimizer_switch="index_merge_sort_union=on";
|
||||
set session optimizer_switch="index_merge=off";
|
||||
select @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
select @@session.optimizer_switch;
|
||||
@@session.optimizer_switch
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
show global variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
optimizer_switch index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
show session variables like 'optimizer_switch';
|
||||
Variable_name Value
|
||||
optimizer_switch index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
optimizer_switch index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
select * from information_schema.global_variables where variable_name='optimizer_switch';
|
||||
VARIABLE_NAME VARIABLE_VALUE
|
||||
OPTIMIZER_SWITCH index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
OPTIMIZER_SWITCH index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
select * from information_schema.session_variables where variable_name='optimizer_switch';
|
||||
VARIABLE_NAME VARIABLE_VALUE
|
||||
OPTIMIZER_SWITCH index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
OPTIMIZER_SWITCH index_merge=off,index_merge_union=off,index_merge_sort_union=on,index_merge_intersection=off,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
set session optimizer_switch="default";
|
||||
select @@session.optimizer_switch;
|
||||
@@session.optimizer_switch
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off
|
||||
index_merge=off,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,optimize_join_buffer_size=off,table_elimination=off,extended_keys=off,exists_to_in=off
|
||||
set optimizer_switch = replace(@@optimizer_switch, '=off', '=on');
|
||||
select @@optimizer_switch;
|
||||
@@optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=on,mrr_cost_based=on,mrr_sort_keys=on,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on
|
||||
set global optimizer_switch=1.1;
|
||||
ERROR 42000: Incorrect argument type to variable 'optimizer_switch'
|
||||
set global optimizer_switch=1e1;
|
||||
|
@ -67,4 +67,4 @@ ERROR 42000: Variable 'optimizer_switch' can't be set to the value of 'foobar'
|
|||
SET @@global.optimizer_switch = @start_global_value;
|
||||
SELECT @@global.optimizer_switch;
|
||||
@@global.optimizer_switch
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
|
|
|
@ -2,4 +2,4 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
1 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
1 1 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=on,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
|
|
|
@ -2,4 +2,4 @@ select @@session.engine_condition_pushdown,
|
|||
@@global.engine_condition_pushdown,
|
||||
@@session.optimizer_switch, @@global.optimizer_switch;
|
||||
@@session.engine_condition_pushdown @@global.engine_condition_pushdown @@session.optimizer_switch @@global.optimizer_switch
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off
|
||||
0 0 index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=off
|
||||
|
|
739
mysql-test/t/subselect_exists2in.test
Normal file
739
mysql-test/t/subselect_exists2in.test
Normal file
|
@ -0,0 +1,739 @@
|
|||
|
||||
--disable_warnings
|
||||
drop table if exists t1,t2,t3;
|
||||
--enable_warnings
|
||||
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
--echo #
|
||||
--echo # LP BUG#884644 exists2in broke name resolution
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (f1 integer);
|
||||
|
||||
--error ER_BAD_FIELD_ERROR
|
||||
SELECT * FROM t1 WHERE EXISTS (SELECT NO_SUCH_TABLE.NO_SUCH_FIELD FROM t1);
|
||||
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # LP BUG#884657 Wrong result with exists2in , correlated subquery
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 ( a varchar(1)) ;
|
||||
INSERT INTO t1 VALUES ('c'),('b');
|
||||
|
||||
CREATE TABLE t2 ( b varchar(1)) ;
|
||||
INSERT INTO t2 VALUES ('v'),('v'),('c'),(NULL),('x'),('i'),('e'),('p'),('s'),('j'),('z'),('c'),('a'),('q'),('y'),(NULL),('r'),('v'),(NULL),('r');
|
||||
|
||||
CREATE TABLE t3 ( a int NOT NULL , b varchar(1)) ;
|
||||
INSERT INTO t3 VALUES (29,'c');
|
||||
|
||||
SELECT *
|
||||
FROM t1, t2
|
||||
WHERE EXISTS (
|
||||
SELECT a
|
||||
FROM t3
|
||||
WHERE t3.b = t1.a
|
||||
AND t3.b <> t2.b
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO t3 VALUES (2,'c');
|
||||
alter table t1 add index aa (a);
|
||||
alter table t3 add index bb (b);
|
||||
--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
--echo -- EXIST to IN then IN to EXISTS
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
--echo -- EXIST2IN then MATERIALIZATION
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
--echo -- NO EXIST2IN
|
||||
set optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a);
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
drop table t1,t2,t3;
|
||||
|
||||
--echo #
|
||||
--echo # From group_min_max.test
|
||||
--echo #
|
||||
create table t1 (
|
||||
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
|
||||
);
|
||||
|
||||
insert into t1 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
|
||||
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
|
||||
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
|
||||
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
|
||||
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
|
||||
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
|
||||
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
|
||||
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
|
||||
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
|
||||
|
||||
create index idx_t1_0 on t1 (a1);
|
||||
create index idx_t1_1 on t1 (a1,a2,b,c);
|
||||
create index idx_t1_2 on t1 (a1,a2,b);
|
||||
analyze table t1;
|
||||
|
||||
# t2 is the same as t1, but with some NULLs in the MIN/MAX column, and
|
||||
# one more nullable attribute
|
||||
|
||||
create table t2 (
|
||||
a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
|
||||
);
|
||||
insert into t2 select * from t1;
|
||||
# add few rows with NULL's in the MIN/MAX column
|
||||
insert into t2 (a1, a2, b, c, d) values
|
||||
('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
|
||||
('a','a','a',NULL,'xyz'),
|
||||
('a','a','b',NULL,'xyz'),
|
||||
('a','b','a',NULL,'xyz'),
|
||||
('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
|
||||
('d','b','b',NULL,'xyz'),
|
||||
('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
|
||||
('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),
|
||||
('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
|
||||
('a','a','a',NULL,'xyz'),
|
||||
('a','a','b',NULL,'xyz'),
|
||||
('a','b','a',NULL,'xyz'),
|
||||
('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'),
|
||||
('d','b','b',NULL,'xyz'),
|
||||
('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),
|
||||
('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz');
|
||||
|
||||
create index idx_t2_0 on t2 (a1);
|
||||
create index idx_t2_1 on t2 (a1,a2,b,c);
|
||||
create index idx_t2_2 on t2 (a1,a2,b);
|
||||
analyze table t2;
|
||||
|
||||
# Table t3 is the same as t1, but with smaller column lenghts.
|
||||
# This allows to test different branches of the cost computation procedure
|
||||
# when the number of keys per block are less than the number of keys in the
|
||||
# sub-groups formed by predicates over non-group attributes.
|
||||
|
||||
create table t3 (
|
||||
a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
|
||||
);
|
||||
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
insert into t3 (a1, a2, b, c, d) values
|
||||
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
|
||||
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
|
||||
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
|
||||
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
|
||||
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
|
||||
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
|
||||
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
|
||||
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
|
||||
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
|
||||
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
|
||||
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
|
||||
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4');
|
||||
|
||||
create index idx_t3_0 on t3 (a1);
|
||||
create index idx_t3_1 on t3 (a1,a2,b,c);
|
||||
create index idx_t3_2 on t3 (a1,a2,b);
|
||||
analyze table t3;
|
||||
|
||||
|
||||
explain select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.b) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
|
||||
select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.b) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
|
||||
explain select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.c) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
|
||||
select a1,a2,b,c,min(c), max(c) from t1
|
||||
where exists ( select * from t2
|
||||
where t2.c in (select c from t3 where t3.c > t1.c) and
|
||||
t2.c > 'b1' )
|
||||
group by a1,a2,b;
|
||||
|
||||
drop table t1, t2, t3;
|
||||
|
||||
#
|
||||
# LP BUG#901835 - incorrect semi-join conversion after exists2in
|
||||
#
|
||||
CREATE TABLE t1 ( a INT );
|
||||
INSERT INTO t1 VALUES (7),(0);
|
||||
CREATE TABLE t2 ( b INT );
|
||||
INSERT INTO t2 VALUES (0),(8);
|
||||
|
||||
SELECT * FROM t1 WHERE
|
||||
EXISTS ( SELECT * FROM t2 WHERE b = a )
|
||||
OR a > 0;
|
||||
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE
|
||||
EXISTS ( SELECT * FROM t2 WHERE b = a )
|
||||
OR a > 0;
|
||||
|
||||
drop tables t1,t2;
|
||||
|
||||
#
|
||||
# NOT EXISTS test
|
||||
#
|
||||
CREATE TABLE t1 ( a INT );
|
||||
INSERT INTO t1 VALUES (1),(5);
|
||||
CREATE TABLE t2 ( b INT ) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (1);
|
||||
|
||||
CREATE TABLE t3 ( c INT );
|
||||
INSERT INTO t3 VALUES (4),(5);
|
||||
|
||||
SET optimizer_switch='exists_to_in=on,subquery_cache=off,materialization=on,in_to_exists=off,semijoin=off';
|
||||
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
|
||||
SET optimizer_switch='exists_to_in=on,subquery_cache=off';
|
||||
|
||||
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
|
||||
SET optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
|
||||
explain extended
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1;
|
||||
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop table t1,t2,t3;
|
||||
|
||||
--echo # multi condition test
|
||||
CREATE TABLE t1 ( a varchar(1), a1 varchar(1)) ;
|
||||
INSERT INTO t1 VALUES ('c', 'c'), ('b', 'b');
|
||||
|
||||
CREATE TABLE t3 ( a int NOT NULL , b varchar(1), b1 varchar(1)) ;
|
||||
INSERT INTO t3 VALUES (29,'c','c');
|
||||
INSERT INTO t3 VALUES (2,'c','c');
|
||||
alter table t1 add index aa (a,a1);
|
||||
alter table t3 add index bb (b,b1);
|
||||
--echo -- EXIST to IN then semijoin (has priority over IN to EXISTS)
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
--echo -- EXIST to IN then IN to EXISTS
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
--echo -- EXIST2IN then MATERIALIZATION
|
||||
set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
--echo -- NO EXIST2IN
|
||||
set optimizer_switch='exists_to_in=off,subquery_cache=off';
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1);
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
drop table t1,t3;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-159 Assertion about not marked for read failed in
|
||||
--echo # String* Field_varstring::val_str(String*, String*)
|
||||
--echo #
|
||||
|
||||
SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
|
||||
SET optimizer_switch='in_to_exists=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 ( a VARCHAR(1) );
|
||||
INSERT INTO t1 VALUES ('k'),('m');
|
||||
|
||||
CREATE TABLE t2 ( b INT,
|
||||
c VARCHAR(1),
|
||||
d VARCHAR(1) NOT NULL );
|
||||
|
||||
INSERT INTO t2 VALUES
|
||||
(4,'j','j'),(6,'v','v');
|
||||
|
||||
CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t2 WHERE b < 1;
|
||||
|
||||
SELECT c FROM v
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= v.d AND b = v.b
|
||||
);
|
||||
|
||||
explain extended
|
||||
SELECT c FROM v
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= v.d AND b = v.b
|
||||
);
|
||||
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
drop view v;
|
||||
drop table t1,t2;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
|
||||
--echo #
|
||||
|
||||
SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (
|
||||
a VARCHAR(3) NOT NULL,
|
||||
b VARCHAR(50)
|
||||
);
|
||||
INSERT INTO t1 VALUES
|
||||
('USA','Chinese'),('USA','English'),
|
||||
('FRA','French'),('ITA','Italian');
|
||||
|
||||
CREATE TABLE t2 ( c VARCHAR(3) );
|
||||
INSERT INTO t2 VALUES ('USA'),('FRA');
|
||||
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.a
|
||||
) OR alias1 .a = 'foo';
|
||||
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON
|
||||
--echo #
|
||||
SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (
|
||||
a VARCHAR(3) NOT NULL,
|
||||
b VARCHAR(50)
|
||||
);
|
||||
INSERT INTO t1 VALUES
|
||||
('USA','Chinese'),('USA','English'),
|
||||
('FRA','French'),('ITA','Italian');
|
||||
|
||||
CREATE TABLE t2 ( c VARCHAR(3) );
|
||||
INSERT INTO t2 VALUES ('USA'),('FRA');
|
||||
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT * FROM t1, t2
|
||||
WHERE a <= alias2.a AND c = alias1.b
|
||||
) OR alias1 .a = 'foo';
|
||||
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-245 Exists2In: Wrong result (extra rows) with
|
||||
--echo # exists_to_in=ON, materialization=OFF, NOT EXISTS subquery
|
||||
--echo #
|
||||
SET optimizer_switch='materialization=off,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 ( a INT ) ;
|
||||
INSERT INTO t1 VALUES (0),(8),(1);
|
||||
|
||||
CREATE TABLE t2 ( b INT ) ;
|
||||
INSERT INTO t2 VALUES (1),(2),(3);
|
||||
|
||||
SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
explain extended
|
||||
SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-243 Wrong result (extra or missing rows) with
|
||||
--echo # exists_to_in + materialization, EXISTS subquery
|
||||
--echo #
|
||||
|
||||
SET optimizer_switch='index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 ( a VARCHAR(1), b VARCHAR(1) );
|
||||
INSERT INTO t1 VALUES ('v','v'),('s','v');
|
||||
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
|
||||
SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' );
|
||||
SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=off';
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=on';
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b );
|
||||
|
||||
drop table t1;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-403 Wrong result (missing rows) with subquery in
|
||||
--echo # EXISTS and an OR condition outside
|
||||
--echo #
|
||||
CREATE TABLE t1 (a INT);
|
||||
INSERT INTO t1 VALUES (2),(3);
|
||||
|
||||
CREATE TABLE t2 (b INT);
|
||||
INSERT INTO t2 VALUES (1),(3);
|
||||
SET optimizer_switch = 'exists_to_in=off,in_to_exists=on';
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
|
||||
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
|
||||
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
|
||||
explain extended
|
||||
SELECT * FROM t1 AS alias1, t2 AS alias2
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
|
||||
) OR a = 5;
|
||||
|
||||
drop table t1, t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-404: Wrong result (extra rows) with STRAIGHT_JOIN,
|
||||
--echo # EXISTS subquery, NOT NULL column
|
||||
--echo # (same as above)
|
||||
--echo #
|
||||
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
|
||||
|
||||
CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL);
|
||||
INSERT INTO t1 VALUES (1,'s'),(2,'e');
|
||||
|
||||
SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
|
||||
WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a );
|
||||
|
||||
drop table t1;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3800: ORDER BY doesn't work with exists_to_in=ON on
|
||||
--echo # a query with EXISTS subquery and OR condition
|
||||
--echo #
|
||||
SET optimizer_switch = 'in_to_exists=on,exists_to_in=on';
|
||||
CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (4,'j'),(6,'v'),(3,'c');
|
||||
|
||||
CREATE TABLE t2 (c VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('b'),('y');
|
||||
|
||||
SELECT a FROM t1
|
||||
WHERE EXISTS (
|
||||
SELECT 1 FROM t2 WHERE c = b
|
||||
) OR b NOT IN ('U')
|
||||
ORDER BY a;
|
||||
|
||||
select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` in (select `test`.`t2`.`c` from `test`.`t2` where 1 ) or (`test`.`t1`.`b` <> 'U') order by `test`.`t1`.`a`;
|
||||
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # correct calculation of reserved items (postreview-fix)
|
||||
--echo #
|
||||
create table t1 (col1 int, col2 int, col3 int);
|
||||
insert into t1 values (1,2,3),(2,3,4),(4,5,6);
|
||||
create table t2 as select * from t1;
|
||||
explain extended
|
||||
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
|
||||
select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2);
|
||||
drop table t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3879: Exists2In: Wrong result (extra row) and unexpected
|
||||
--echo # warning with exists_to_in=on and a NOT EXISTS subquery
|
||||
--echo #
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (3,'y'),(6,'w');
|
||||
|
||||
CREATE TABLE t2 (a2 INT, b2 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (3,'y'),(6,'d');
|
||||
|
||||
SELECT * FROM t1
|
||||
WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b2 = b1 AND a2 = a1 );
|
||||
|
||||
drop table t1, t2;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3880: Wrong result (missing rows) with exists_to_in=on,
|
||||
--echo # LEFT JOIN and NOT EXISTS subquery.
|
||||
--echo # (Duplicate of above MDEV-3879).
|
||||
--echo #
|
||||
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (4,'b'),(5,'y');
|
||||
|
||||
CREATE TABLE t2 (b2 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('z'),('b');
|
||||
|
||||
CREATE TABLE t3 (a3 INT, b3 CHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4,'j'),(6,'v');
|
||||
|
||||
SELECT * FROM t1 LEFT JOIN t2 ON ( b2 = b1 )
|
||||
WHERE NOT EXISTS ( SELECT * FROM t3 WHERE b3 = b2 AND a3 = a1 ) ;
|
||||
|
||||
drop table t1, t2, t3;
|
||||
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3881: Endless loop and crash in Item_ref::real_item with
|
||||
--echo # exists_to_in=on, NOT EXISTS subquery, merge view or from subquery,
|
||||
--echo # constant table
|
||||
--echo #
|
||||
SET optimizer_switch = 'exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (8);
|
||||
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2;
|
||||
|
||||
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4),(6);
|
||||
|
||||
SELECT * FROM t1, v1 WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
|
||||
|
||||
drop view v1;
|
||||
drop table t1, t2, t3;
|
||||
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (8);
|
||||
|
||||
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES (4),(6);
|
||||
|
||||
SELECT * FROM t1, ( SELECT * FROM t2 ) alias WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b;
|
||||
|
||||
drop table t1, t2, t3;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3906: Server crashes in Dependency_marker::visit_field
|
||||
--echo # on 2nd execution of PS with exists_to_in and NOT EXISTS subquery
|
||||
--echo #
|
||||
SET optimizer_switch='exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(7);
|
||||
|
||||
PREPARE stmt FROM '
|
||||
SELECT * FROM t1 AS alias
|
||||
WHERE NOT EXISTS ( SELECT * FROM t1 WHERE t1.a = alias.a )
|
||||
';
|
||||
|
||||
EXECUTE stmt;
|
||||
EXECUTE stmt;
|
||||
|
||||
drop table t1;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3904: Assertion `in_subs->has_strategy()' failed in
|
||||
--echo # JOIN::choose_subquery_plan on 2nd execution of PS with
|
||||
--echo # exists_to_in+semijoin, EXISTS subquery, MERGE view or FROM subquery
|
||||
--echo #
|
||||
SET optimizer_switch='in_to_exists=on,semijoin=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (4),(6);
|
||||
|
||||
CREATE ALGORITHM=MERGE VIEW v AS
|
||||
SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t2 WHERE b = a );
|
||||
|
||||
PREPARE stmt FROM ' SELECT * FROM v ';
|
||||
|
||||
EXECUTE stmt;
|
||||
EXECUTE stmt;
|
||||
|
||||
drop view v;
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-3903: Server crashes in Item_cond::fix_fields on 2nd execution
|
||||
--echo # of a prepared stmt with exists_to_in+materialization+semijoin,
|
||||
--echo # EXISTS subquery, STRAIGHT_JOIN
|
||||
--echo #
|
||||
|
||||
SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1),(2);
|
||||
|
||||
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES (3),(4);
|
||||
|
||||
PREPARE stmt FROM
|
||||
'SELECT STRAIGHT_JOIN * FROM t1
|
||||
WHERE EXISTS ( SELECT * FROM t2 WHERE b = a )';
|
||||
|
||||
EXECUTE stmt;
|
||||
EXECUTE stmt;
|
||||
|
||||
drop table t1,t2;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-4152: Wrong result (missing rows) with exists_to_in=on,
|
||||
--echo # inner joins
|
||||
--echo #
|
||||
SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on';
|
||||
|
||||
CREATE TABLE t1 (i INT, c1 CHAR(5), c2 CHAR(5), t1_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES (1,'test1','test2','f'), (2,'test3','test4','d');
|
||||
|
||||
CREATE TABLE t2 (t2_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES ('m'), ('b');
|
||||
|
||||
CREATE TABLE t3 (t3_field VARCHAR(1)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES ('b'),('c');
|
||||
|
||||
SELECT * FROM t1, t2 outer_t2
|
||||
WHERE EXISTS ( SELECT 1 FROM t2, t3 WHERE t3_field = outer_t2.t2_field AND t2_field <= t1_field );
|
||||
|
||||
drop table t1,t2,t3;
|
||||
set optimizer_switch=default;
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
#restore defaults
|
||||
set optimizer_switch=default;
|
83
mysql-test/t/subselect_exists2in_costmat.test
Normal file
83
mysql-test/t/subselect_exists2in_costmat.test
Normal file
|
@ -0,0 +1,83 @@
|
|||
#
|
||||
# Tests of cost-based choice between the materialization and in-to-exists
|
||||
# subquery execution strategies (MWL#89)
|
||||
#
|
||||
# The test file is divided into two groups of tests:
|
||||
# A. Typical cases when either of the two strategies is selected:
|
||||
# 1. Subquery in disjunctive WHERE clause of the outer query.
|
||||
# 2. NOT IN subqueries
|
||||
# 3. Subqueries with GROUP BY, HAVING, and aggregate functions
|
||||
# 4. Subqueries in the SELECT and HAVING clauses
|
||||
# 5. Subqueries with UNION
|
||||
# B. Reasonably exhaustive tests of the various combinations of optimizer
|
||||
# switches, data distribution, available indexes, and typical queries.
|
||||
#
|
||||
|
||||
set @subselect_mat_cost=@@optimizer_switch;
|
||||
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
|
||||
#
|
||||
# Test logging to slow log (there was some errors in the log files about
|
||||
# the slow log when running under valgrind, so better to get this tested)
|
||||
#
|
||||
set long_query_time=0.1;
|
||||
|
||||
|
||||
--disable_warnings
|
||||
drop database if exists world;
|
||||
--enable_warnings
|
||||
|
||||
set names utf8;
|
||||
|
||||
create database world;
|
||||
use world;
|
||||
|
||||
--source include/world_schema.inc
|
||||
--disable_query_log
|
||||
--disable_result_log
|
||||
--disable_warnings
|
||||
--source include/world.inc
|
||||
--enable_warnings
|
||||
--enable_result_log
|
||||
--enable_query_log
|
||||
|
||||
-- echo Make the schema and data more diverse by adding more indexes, nullable
|
||||
-- echo columns, and NULL data.
|
||||
create index SurfaceArea on Country(SurfaceArea);
|
||||
create index Language on CountryLanguage(Language);
|
||||
create index CityName on City(Name);
|
||||
alter table City change population population int(11) null default 0;
|
||||
|
||||
select max(id) from City into @max_city_id;
|
||||
insert into City values (@max_city_id + 1,'Kilifarevo','BGR',NULL);
|
||||
|
||||
|
||||
SELECT COUNT(*) FROM Country;
|
||||
SELECT COUNT(*) FROM City;
|
||||
SELECT COUNT(*) FROM CountryLanguage;
|
||||
|
||||
set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on';
|
||||
|
||||
-- echo
|
||||
-- echo 1. Subquery in a disjunctive WHERE clause of the outer query.
|
||||
-- echo
|
||||
|
||||
-- echo
|
||||
-- echo Q1.1m:
|
||||
-- echo MATERIALIZATION: there are too many rows in the outer query
|
||||
-- echo to be looked up in the inner table.
|
||||
EXPLAIN
|
||||
SELECT Name FROM Country
|
||||
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
|
||||
Code = Country) OR
|
||||
Name LIKE 'L%') AND
|
||||
surfacearea > 1000000;
|
||||
|
||||
SELECT Name FROM Country
|
||||
WHERE (EXISTS (select 1 from City where City.Population > 100000 and
|
||||
Code = Country) OR
|
||||
Name LIKE 'L%') AND
|
||||
surfacearea > 1000000;
|
||||
|
||||
drop database world;
|
||||
|
||||
set optimizer_switch=@subselect_mat_cost;
|
11
mysql-test/t/subselect_exists_to_in.test
Normal file
11
mysql-test/t/subselect_exists_to_in.test
Normal file
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# Run subselect.test with exists to in transformation
|
||||
#
|
||||
select @@optimizer_switch like '%exists_to_in=on%';
|
||||
set optimizer_switch='exists_to_in=on';
|
||||
|
||||
--source t/subselect.test
|
||||
|
||||
set optimizer_switch=default;
|
||||
select @@optimizer_switch like '%exists_to_in=on%';
|
||||
|
16
sql/item.cc
16
sql/item.cc
|
@ -807,10 +807,15 @@ bool Item_ident::remove_dependence_processor(uchar * arg)
|
|||
bool Item_ident::collect_outer_ref_processor(uchar *param)
|
||||
{
|
||||
Collect_deps_prm *prm= (Collect_deps_prm *)param;
|
||||
if (depended_from &&
|
||||
if (depended_from &&
|
||||
depended_from->nest_level_base == prm->nest_level_base &&
|
||||
depended_from->nest_level < prm->nest_level)
|
||||
prm->parameters->add_unique(this, &cmp_items);
|
||||
{
|
||||
if (prm->collect)
|
||||
prm->parameters->add_unique(this, &cmp_items);
|
||||
else
|
||||
prm->count++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -6481,6 +6486,13 @@ Item* Item::cache_const_expr_transformer(uchar *arg)
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
Find Item by reference in the expression
|
||||
*/
|
||||
bool Item::find_item_processor(uchar *arg)
|
||||
{
|
||||
return (this == ((Item *) arg));
|
||||
}
|
||||
|
||||
bool Item_field::send(Protocol *protocol, String *buffer)
|
||||
{
|
||||
|
|
27
sql/item.h
27
sql/item.h
|
@ -553,6 +553,8 @@ class COND_EQUAL;
|
|||
|
||||
class st_select_lex_unit;
|
||||
|
||||
class Item_func_not;
|
||||
|
||||
class Item {
|
||||
Item(const Item &); /* Prevent use of these */
|
||||
void operator=(Item &);
|
||||
|
@ -1153,6 +1155,7 @@ public:
|
|||
virtual bool collect_item_field_processor(uchar * arg) { return 0; }
|
||||
virtual bool add_field_to_set_processor(uchar * arg) { return 0; }
|
||||
virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
|
||||
virtual bool find_item_processor(uchar *arg);
|
||||
virtual bool change_context_processor(uchar *context) { return 0; }
|
||||
virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
|
||||
virtual bool is_expensive_processor(uchar *arg) { return 0; }
|
||||
|
@ -1167,9 +1170,10 @@ public:
|
|||
virtual bool eval_not_null_tables(uchar *opt_arg) { return 0; }
|
||||
virtual bool is_subquery_processor (uchar *opt_arg) { return 0; }
|
||||
virtual bool limit_index_condition_pushdown_processor(uchar *opt_arg)
|
||||
{
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
virtual bool exists2in_processor(uchar *opt_arg) { return 0; }
|
||||
|
||||
/* To call bool function for all arguments */
|
||||
struct bool_func_call_args
|
||||
|
@ -1186,6 +1190,7 @@ public:
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
The next function differs from the previous one that a bitmap to be updated
|
||||
is passed as uchar *arg.
|
||||
|
@ -1315,7 +1320,9 @@ public:
|
|||
List<Item> *parameters;
|
||||
/* unit from which we count nest_level */
|
||||
st_select_lex_unit *nest_level_base;
|
||||
uint count;
|
||||
int nest_level;
|
||||
bool collect;
|
||||
};
|
||||
/**
|
||||
Collect outer references
|
||||
|
@ -1478,6 +1485,15 @@ public:
|
|||
virtual void get_cache_parameters(List<Item> ¶meters) { };
|
||||
|
||||
virtual void mark_as_condition_AND_part(TABLE_LIST *embedding) {};
|
||||
|
||||
/* how much position should be reserved for Exists2In transformation */
|
||||
virtual uint exists2in_reserved_items() { return 0; };
|
||||
|
||||
/**
|
||||
Inform the item that it is located under a NOT, which is a top-level item.
|
||||
*/
|
||||
virtual void under_not(Item_func_not * upper
|
||||
__attribute__((unused))) {};
|
||||
};
|
||||
|
||||
|
||||
|
@ -2983,6 +2999,13 @@ public:
|
|||
alias_name_used_arg)
|
||||
{}
|
||||
|
||||
bool fix_fields(THD *thd, Item **it)
|
||||
{
|
||||
if ((!(*ref)->fixed && (*ref)->fix_fields(thd, ref)) ||
|
||||
(*ref)->check_cols(1))
|
||||
return TRUE;
|
||||
return Item_ref::fix_fields(thd, it);
|
||||
}
|
||||
void save_val(Field *to);
|
||||
double val_real();
|
||||
longlong val_int();
|
||||
|
@ -3202,7 +3225,7 @@ public:
|
|||
bool subst_argument_checker(uchar **arg);
|
||||
Item *equal_fields_propagator(uchar *arg);
|
||||
Item *replace_equal_field(uchar *arg);
|
||||
table_map used_tables() const;
|
||||
table_map used_tables() const;
|
||||
table_map not_null_tables() const;
|
||||
void update_used_tables();
|
||||
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
|
||||
|
|
|
@ -1434,7 +1434,7 @@ bool Item_in_optimizer::eval_not_null_tables(uchar *opt_arg)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
|
||||
bool Item_in_optimizer::fix_left(THD *thd)
|
||||
{
|
||||
if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
|
||||
(!cache && !(cache= Item_cache::get_cache(args[0]))))
|
||||
|
@ -1482,6 +1482,13 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
|
|||
cache->store(args[0]);
|
||||
cache->cache_value();
|
||||
}
|
||||
if (args[1]->fixed)
|
||||
{
|
||||
/* to avoid overriding is called to update left expression */
|
||||
used_tables_cache|= args[1]->used_tables();
|
||||
with_sum_func= with_sum_func || args[1]->with_sum_func;
|
||||
const_item_cache= const_item_cache && args[1]->const_item();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1489,15 +1496,17 @@ bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
|
|||
bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
|
||||
{
|
||||
DBUG_ASSERT(fixed == 0);
|
||||
if (fix_left(thd, ref))
|
||||
if (fix_left(thd))
|
||||
return TRUE;
|
||||
if (args[0]->maybe_null)
|
||||
maybe_null=1;
|
||||
|
||||
if (!args[1]->fixed && args[1]->fix_fields(thd, args+1))
|
||||
return TRUE;
|
||||
|
||||
Item_in_subselect * sub= (Item_in_subselect *)args[1];
|
||||
if (args[0]->cols() != sub->engine->cols())
|
||||
if (!invisible_mode() &&
|
||||
args[0]->cols() != sub->engine->cols())
|
||||
{
|
||||
my_error(ER_OPERAND_COLUMNS, MYF(0), args[0]->cols());
|
||||
return TRUE;
|
||||
|
@ -1513,6 +1522,30 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Check if Item_in_optimizer should work as a pass-through item for its
|
||||
arguments.
|
||||
|
||||
@note
|
||||
Item_in_optimizer should work as pass-through for
|
||||
- subqueries that were processed by ALL/ANY->MIN/MAX rewrite
|
||||
- subqueries taht were originally EXISTS subqueries (and were coverted by
|
||||
the EXISTS->IN rewrite)
|
||||
|
||||
When Item_in_optimizer is not not working as a pass-through, it
|
||||
- caches its "left argument", args[0].
|
||||
- makes adjustments to subquery item's return value for proper NULL
|
||||
value handling
|
||||
*/
|
||||
|
||||
bool Item_in_optimizer::invisible_mode()
|
||||
{
|
||||
/* MAX/MIN transformed or EXISTS->IN prepared => do nothing */
|
||||
return (args[1]->type() != Item::SUBSELECT_ITEM ||
|
||||
((Item_subselect *)args[1])->substype() ==
|
||||
Item_subselect::EXISTS_SUBS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Add an expression cache for this subquery if it is needed
|
||||
|
@ -1536,8 +1569,9 @@ Item *Item_in_optimizer::expr_cache_insert_transformer(uchar *thd_arg)
|
|||
{
|
||||
THD *thd= (THD*) thd_arg;
|
||||
DBUG_ENTER("Item_in_optimizer::expr_cache_insert_transformer");
|
||||
if (args[1]->type() != Item::SUBSELECT_ITEM)
|
||||
DBUG_RETURN(this); // MAX/MIN transformed => do nothing
|
||||
|
||||
if (invisible_mode())
|
||||
DBUG_RETURN(this);
|
||||
|
||||
if (expr_cache)
|
||||
DBUG_RETURN(expr_cache);
|
||||
|
@ -1560,13 +1594,16 @@ Item *Item_in_optimizer::expr_cache_insert_transformer(uchar *thd_arg)
|
|||
void Item_in_optimizer::get_cache_parameters(List<Item> ¶meters)
|
||||
{
|
||||
/* Add left expression to the list of the parameters of the subquery */
|
||||
if (args[0]->cols() == 1)
|
||||
parameters.add_unique(args[0], &cmp_items);
|
||||
else
|
||||
if (!invisible_mode())
|
||||
{
|
||||
for (uint i= 0; i < args[0]->cols(); i++)
|
||||
if (args[0]->cols() == 1)
|
||||
parameters.add_unique(args[0], &cmp_items);
|
||||
else
|
||||
{
|
||||
parameters.add_unique(args[0]->element_index(i), &cmp_items);
|
||||
for (uint i= 0; i < args[0]->cols(); i++)
|
||||
{
|
||||
parameters.add_unique(args[0]->element_index(i), &cmp_items);
|
||||
}
|
||||
}
|
||||
}
|
||||
args[1]->get_cache_parameters(parameters);
|
||||
|
@ -1649,17 +1686,19 @@ longlong Item_in_optimizer::val_int()
|
|||
DBUG_ASSERT(fixed == 1);
|
||||
cache->store(args[0]);
|
||||
cache->cache_value();
|
||||
DBUG_ENTER(" Item_in_optimizer::val_int");
|
||||
|
||||
if (args[1]->type() != Item::SUBSELECT_ITEM)
|
||||
if (invisible_mode())
|
||||
{
|
||||
/* MAX/MIN transformed => pass through */
|
||||
longlong res= args[1]->val_int();
|
||||
null_value= args[1]->null_value;
|
||||
return (res);
|
||||
DBUG_PRINT("info", ("pass trough"));
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
if (cache->null_value)
|
||||
{
|
||||
DBUG_PRINT("info", ("Left NULL..."));
|
||||
/*
|
||||
We're evaluating
|
||||
"<outer_value_list> [NOT] IN (SELECT <inner_value_list>...)"
|
||||
|
@ -1731,11 +1770,11 @@ longlong Item_in_optimizer::val_int()
|
|||
for (uint i= 0; i < ncols; i++)
|
||||
item_subs->set_cond_guard_var(i, TRUE);
|
||||
}
|
||||
return 0;
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
tmp= args[1]->val_bool_result();
|
||||
null_value= args[1]->null_value;
|
||||
return tmp;
|
||||
DBUG_RETURN(tmp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1786,7 +1825,8 @@ bool Item_in_optimizer::is_null()
|
|||
@retval NULL if an error occurred
|
||||
*/
|
||||
|
||||
Item *Item_in_optimizer::transform(Item_transformer transformer, uchar *argument)
|
||||
Item *Item_in_optimizer::transform(Item_transformer transformer,
|
||||
uchar *argument)
|
||||
{
|
||||
Item *new_item;
|
||||
|
||||
|
@ -1806,7 +1846,7 @@ Item *Item_in_optimizer::transform(Item_transformer transformer, uchar *argument
|
|||
if ((*args) != new_item)
|
||||
current_thd->change_item_tree(args, new_item);
|
||||
|
||||
if (args[1]->type() != Item::SUBSELECT_ITEM)
|
||||
if (invisible_mode())
|
||||
{
|
||||
/* MAX/MIN transformed => pass through */
|
||||
new_item= args[1]->transform(transformer, argument);
|
||||
|
@ -5350,6 +5390,7 @@ Item *Item_func_not::neg_transformer(THD *thd) /* NOT(x) -> x */
|
|||
|
||||
bool Item_func_not::fix_fields(THD *thd, Item **ref)
|
||||
{
|
||||
args[0]->under_not(this);
|
||||
if (args[0]->type() == FIELD_ITEM)
|
||||
{
|
||||
/* replace "NOT <field>" with "<filed> == 0" */
|
||||
|
|
|
@ -246,12 +246,12 @@ protected:
|
|||
*/
|
||||
int result_for_null_param;
|
||||
public:
|
||||
Item_in_optimizer(Item *a, Item_in_subselect *b):
|
||||
Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0), expr_cache(0),
|
||||
Item_in_optimizer(Item *a, Item *b):
|
||||
Item_bool_func(a, b), cache(0), expr_cache(0),
|
||||
save_cache(0), result_for_null_param(UNKNOWN)
|
||||
{ with_subselect= true; }
|
||||
bool fix_fields(THD *, Item **);
|
||||
bool fix_left(THD *thd, Item **ref);
|
||||
bool fix_left(THD *thd);
|
||||
table_map not_null_tables() const { return 0; }
|
||||
bool is_null();
|
||||
longlong val_int();
|
||||
|
@ -269,6 +269,8 @@ public:
|
|||
bool is_top_level_item();
|
||||
bool eval_not_null_tables(uchar *opt_arg);
|
||||
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
|
||||
bool invisible_mode();
|
||||
void reset_cache() { cache= NULL; }
|
||||
};
|
||||
|
||||
class Comp_creator
|
||||
|
@ -436,8 +438,11 @@ public:
|
|||
|
||||
class Item_func_not :public Item_bool_func
|
||||
{
|
||||
bool abort_on_null;
|
||||
public:
|
||||
Item_func_not(Item *a) :Item_bool_func(a) {}
|
||||
Item_func_not(Item *a) :Item_bool_func(a), abort_on_null(FALSE) {}
|
||||
virtual void top_level_item() { abort_on_null= 1; }
|
||||
bool is_top_level_item() { return abort_on_null; }
|
||||
longlong val_int();
|
||||
enum Functype functype() const { return NOT_FUNC; }
|
||||
const char *func_name() const { return "not"; }
|
||||
|
@ -495,16 +500,13 @@ class Item_func_not_all :public Item_func_not
|
|||
Item_sum_hybrid *test_sum_item;
|
||||
Item_maxmin_subselect *test_sub_item;
|
||||
|
||||
bool abort_on_null;
|
||||
public:
|
||||
bool show;
|
||||
|
||||
Item_func_not_all(Item *a)
|
||||
:Item_func_not(a), test_sum_item(0), test_sub_item(0), abort_on_null(0),
|
||||
:Item_func_not(a), test_sum_item(0), test_sub_item(0),
|
||||
show(0)
|
||||
{}
|
||||
virtual void top_level_item() { abort_on_null= 1; }
|
||||
bool is_top_level_item() { return abort_on_null; }
|
||||
table_map not_null_tables() const { return 0; }
|
||||
longlong val_int();
|
||||
enum Functype functype() const { return NOT_ALL_FUNC; }
|
||||
|
@ -550,6 +552,7 @@ public:
|
|||
- Otherwise, UINT_MAX
|
||||
*/
|
||||
uint in_equality_no;
|
||||
virtual uint exists2in_reserved_items() { return 1; };
|
||||
};
|
||||
|
||||
class Item_func_equal :public Item_bool_rowready_func2
|
||||
|
@ -1851,6 +1854,7 @@ public:
|
|||
}
|
||||
Item *neg_transformer(THD *thd);
|
||||
void mark_as_condition_AND_part(TABLE_LIST *embedding);
|
||||
virtual uint exists2in_reserved_items() { return list.elements; };
|
||||
};
|
||||
|
||||
inline bool is_cond_and(Item *item)
|
||||
|
|
|
@ -47,13 +47,13 @@ Item_row::Item_row(List<Item> &arg):
|
|||
items= (Item**) sql_alloc(sizeof(Item*)*arg_count);
|
||||
else
|
||||
items= 0;
|
||||
List_iterator<Item> li(arg);
|
||||
List_iterator_fast<Item> li(arg);
|
||||
uint i= 0;
|
||||
Item *item;
|
||||
while ((item= li++))
|
||||
{
|
||||
items[i]= item;
|
||||
i++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2489,10 +2489,12 @@ void Item_func_make_set::fix_length_and_dec()
|
|||
|
||||
void Item_func_make_set::update_used_tables()
|
||||
{
|
||||
DBUG_ENTER("Item_func_make_set::update_used_tables");
|
||||
Item_func::update_used_tables();
|
||||
item->update_used_tables();
|
||||
used_tables_cache|=item->used_tables();
|
||||
const_item_cache&=item->const_item();
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@
|
|||
|
||||
double get_post_group_estimate(JOIN* join, double join_op_rows);
|
||||
|
||||
const char *exists_outer_expr_name= "<exists outer expr>";
|
||||
|
||||
int check_and_do_in_subquery_rewrites(JOIN *join);
|
||||
|
||||
Item_subselect::Item_subselect():
|
||||
Item_result_field(), value_assigned(0), own_engine(0), thd(0), old_engine(0),
|
||||
|
@ -83,15 +86,24 @@ void Item_subselect::init(st_select_lex *select_lex,
|
|||
|
||||
if (unit->item)
|
||||
{
|
||||
/*
|
||||
Item can be changed in JOIN::prepare while engine in JOIN::optimize
|
||||
=> we do not copy old_engine here
|
||||
*/
|
||||
engine= unit->item->engine;
|
||||
own_engine= FALSE;
|
||||
parsing_place= unit->item->parsing_place;
|
||||
thd->change_item_tree((Item**)&unit->item, this);
|
||||
engine->change_result(this, result, TRUE);
|
||||
if (unit->item->substype() == EXISTS_SUBS &&
|
||||
((Item_exists_subselect *)unit->item)->exists_transformed)
|
||||
{
|
||||
/* it is permanent transformation of EXISTS to IN */
|
||||
unit->item= this;
|
||||
engine->change_result(this, result, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
Item can be changed in JOIN::prepare while engine in JOIN::optimize
|
||||
=> we do not copy old_engine here
|
||||
*/
|
||||
thd->change_item_tree((Item**)&unit->item, this);
|
||||
engine->change_result(this, result, TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -462,7 +474,7 @@ public:
|
|||
void Item_subselect::recalc_used_tables(st_select_lex *new_parent,
|
||||
bool after_pullout)
|
||||
{
|
||||
List_iterator<Ref_to_outside> it(upper_refs);
|
||||
List_iterator_fast<Ref_to_outside> it(upper_refs);
|
||||
Ref_to_outside *upper;
|
||||
|
||||
used_tables_cache= 0;
|
||||
|
@ -661,9 +673,12 @@ bool Item_subselect::exec()
|
|||
|
||||
void Item_subselect::get_cache_parameters(List<Item> ¶meters)
|
||||
{
|
||||
Collect_deps_prm prm= {¶meters,
|
||||
unit->first_select()->nest_level_base,
|
||||
unit->first_select()->nest_level};
|
||||
Collect_deps_prm prm= {¶meters, // parameters
|
||||
unit->first_select()->nest_level_base, // nest_level_base
|
||||
0, // count
|
||||
unit->first_select()->nest_level, // nest_level
|
||||
TRUE // collect
|
||||
};
|
||||
walk(&Item::collect_outer_ref_processor, TRUE, (uchar*)&prm);
|
||||
}
|
||||
|
||||
|
@ -1298,10 +1313,12 @@ bool Item_singlerow_subselect::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
|
|||
|
||||
|
||||
Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex):
|
||||
Item_subselect()
|
||||
Item_subselect(), upper_not(NULL), abort_on_null(0),
|
||||
emb_on_expr_nest(NULL), optimizer(0), exists_transformed(0)
|
||||
{
|
||||
DBUG_ENTER("Item_exists_subselect::Item_exists_subselect");
|
||||
bool val_bool();
|
||||
|
||||
init(select_lex, new select_exists_subselect(this));
|
||||
max_columns= UINT_MAX;
|
||||
null_value= FALSE; //can't be NULL
|
||||
|
@ -1335,21 +1352,19 @@ bool Item_in_subselect::test_limit(st_select_lex_unit *unit_arg)
|
|||
|
||||
Item_in_subselect::Item_in_subselect(Item * left_exp,
|
||||
st_select_lex *select_lex):
|
||||
Item_exists_subselect(),
|
||||
left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED),
|
||||
optimizer(0), pushed_cond_guards(NULL), emb_on_expr_nest(NULL),
|
||||
is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE),
|
||||
is_flattenable_semijoin(FALSE),
|
||||
is_registered_semijoin(FALSE),
|
||||
Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
|
||||
in_strategy(SUBS_NOT_TRANSFORMED),
|
||||
pushed_cond_guards(NULL), is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE),
|
||||
is_flattenable_semijoin(FALSE), is_registered_semijoin(FALSE),
|
||||
upper_item(0)
|
||||
{
|
||||
DBUG_ENTER("Item_in_subselect::Item_in_subselect");
|
||||
DBUG_PRINT("info", ("in_strategy: %u", (uint)in_strategy));
|
||||
left_expr= left_exp;
|
||||
func= &eq_creator;
|
||||
init(select_lex, new select_exists_subselect(this));
|
||||
max_columns= UINT_MAX;
|
||||
maybe_null= 1;
|
||||
abort_on_null= 0;
|
||||
reset();
|
||||
//if test_limit will fail then error will be reported to client
|
||||
test_limit(select_lex->master_unit());
|
||||
|
@ -1745,8 +1760,7 @@ Item_in_subselect::single_value_transformer(JOIN *join)
|
|||
SELECT_LEX *current= thd->lex->current_select;
|
||||
|
||||
thd->lex->current_select= current->return_after_parsing();
|
||||
//optimizer never use Item **ref => we can pass 0 as parameter
|
||||
if (!optimizer || optimizer->fix_left(thd, 0))
|
||||
if (!optimizer || optimizer->fix_left(thd))
|
||||
{
|
||||
thd->lex->current_select= current;
|
||||
DBUG_RETURN(true);
|
||||
|
@ -2125,8 +2139,7 @@ Item_in_subselect::row_value_transformer(JOIN *join)
|
|||
|
||||
SELECT_LEX *current= thd->lex->current_select;
|
||||
thd->lex->current_select= current->return_after_parsing();
|
||||
//optimizer never use Item **ref => we can pass 0 as parameter
|
||||
if (!optimizer || optimizer->fix_left(thd, 0))
|
||||
if (!optimizer || optimizer->fix_left(thd))
|
||||
{
|
||||
thd->lex->current_select= current;
|
||||
DBUG_RETURN(true);
|
||||
|
@ -2370,6 +2383,12 @@ Item_in_subselect::select_transformer(JOIN *join)
|
|||
return select_in_like_transformer(join);
|
||||
}
|
||||
|
||||
bool
|
||||
Item_exists_subselect::select_transformer(JOIN *join)
|
||||
{
|
||||
return select_prepare_to_be_in();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Create the predicates needed to transform an IN/ALL/ANY subselect into a
|
||||
|
@ -2505,6 +2524,437 @@ bool Item_in_subselect::inject_in_to_exists_cond(JOIN *join_arg)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
If this select can potentially be converted by EXISTS->IN conversion, wrap it
|
||||
in an Item_in_optimizer object. Final decision whether to do the conversion
|
||||
is done at a later phase.
|
||||
*/
|
||||
|
||||
bool Item_exists_subselect::select_prepare_to_be_in()
|
||||
{
|
||||
bool trans_res= FALSE;
|
||||
DBUG_ENTER("Item_exists_subselect::select_prepare_to_be_in");
|
||||
if (!optimizer &&
|
||||
thd->lex->sql_command == SQLCOM_SELECT &&
|
||||
!unit->first_select()->is_part_of_union() &&
|
||||
optimizer_flag(thd, OPTIMIZER_SWITCH_EXISTS_TO_IN) &&
|
||||
(is_top_level_item() ||
|
||||
(upper_not && upper_not->is_top_level_item())))
|
||||
{
|
||||
Query_arena *arena, backup;
|
||||
bool result;
|
||||
arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||
result= (!(optimizer= new Item_in_optimizer(new Item_int(1), this)));
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
if (result)
|
||||
trans_res= TRUE;
|
||||
else
|
||||
substitution= optimizer;
|
||||
}
|
||||
DBUG_RETURN(trans_res);
|
||||
}
|
||||
|
||||
/**
|
||||
Check if 'func' is an equality in form "inner_table.column = outer_expr"
|
||||
|
||||
@param func Expression to check
|
||||
@param local_field OUT Return "inner_table.column" here
|
||||
@param outer_expr OUT Return outer_expr here
|
||||
|
||||
@return true - 'func' is an Equality.
|
||||
*/
|
||||
|
||||
static bool check_equality_for_exist2in(Item_func *func,
|
||||
Item_ident **local_field,
|
||||
Item **outer_exp)
|
||||
{
|
||||
Item **args;
|
||||
if (func->functype() != Item_func::EQ_FUNC)
|
||||
return FALSE;
|
||||
DBUG_ASSERT(func->arg_count == 2);
|
||||
args= func->arguments();
|
||||
if (args[0]->real_type() == Item::FIELD_ITEM &&
|
||||
args[0]->all_used_tables() != OUTER_REF_TABLE_BIT &&
|
||||
args[1]->all_used_tables() == OUTER_REF_TABLE_BIT)
|
||||
{
|
||||
/* It is Item_field or Item_direct_view_ref) */
|
||||
DBUG_ASSERT(args[0]->type() == Item::FIELD_ITEM ||
|
||||
args[0]->type() == Item::REF_ITEM);
|
||||
*local_field= (Item_ident *)args[0];
|
||||
*outer_exp= args[1];
|
||||
return TRUE;
|
||||
}
|
||||
else if (args[1]->real_type() == Item::FIELD_ITEM &&
|
||||
args[1]->all_used_tables() != OUTER_REF_TABLE_BIT &&
|
||||
args[0]->all_used_tables() == OUTER_REF_TABLE_BIT)
|
||||
{
|
||||
/* It is Item_field or Item_direct_view_ref) */
|
||||
DBUG_ASSERT(args[0]->type() == Item::FIELD_ITEM ||
|
||||
args[0]->type() == Item::REF_ITEM);
|
||||
*local_field= (Item_ident *)args[1];
|
||||
*outer_exp= args[0];
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct st_eq_field_outer
|
||||
{
|
||||
Item_func **eq_ref;
|
||||
Item_ident *local_field;
|
||||
Item *outer_exp;
|
||||
} EQ_FIELD_OUTER;
|
||||
|
||||
|
||||
/**
|
||||
Check if 'conds' is a set of AND-ed outer_expr=inner_table.col equalities
|
||||
|
||||
@detail
|
||||
Check if 'conds' has form
|
||||
|
||||
outer1=inner_tbl1.col1 AND ... AND outer2=inner_tbl1.col2 AND remainder_cond
|
||||
|
||||
@param conds Condition to be checked
|
||||
@parm result Array to collect EQ_FIELD_OUTER elements describing
|
||||
inner-vs-outer equalities the function has found.
|
||||
@return
|
||||
false - some inner-vs-outer equalities were found
|
||||
true - otherwise.
|
||||
*/
|
||||
|
||||
static bool find_inner_outer_equalities(Item **conds,
|
||||
Dynamic_array<EQ_FIELD_OUTER> &result)
|
||||
{
|
||||
bool found= FALSE;
|
||||
EQ_FIELD_OUTER element;
|
||||
if (is_cond_and(*conds))
|
||||
{
|
||||
List_iterator<Item> li(*((Item_cond*)*conds)->argument_list());
|
||||
Item *item;
|
||||
while ((item= li++))
|
||||
{
|
||||
if (item->type() == Item::FUNC_ITEM &&
|
||||
check_equality_for_exist2in((Item_func *)item,
|
||||
&element.local_field,
|
||||
&element.outer_exp))
|
||||
{
|
||||
found= TRUE;
|
||||
element.eq_ref= (Item_func **)li.ref();
|
||||
if (result.append(element))
|
||||
goto alloc_err;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((*conds)->type() == Item::FUNC_ITEM &&
|
||||
check_equality_for_exist2in((Item_func *)*conds,
|
||||
&element.local_field,
|
||||
&element.outer_exp))
|
||||
{
|
||||
found= TRUE;
|
||||
element.eq_ref= (Item_func **)conds;
|
||||
if (result.append(element))
|
||||
goto alloc_err;
|
||||
}
|
||||
|
||||
return !found;
|
||||
alloc_err:
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
Converts EXISTS subquery to IN subquery if it is possible and has sense
|
||||
|
||||
@param opt_arg Pointer on THD
|
||||
|
||||
@return TRUE in case of error and FALSE otherwise.
|
||||
*/
|
||||
|
||||
bool Item_exists_subselect::exists2in_processor(uchar *opt_arg)
|
||||
{
|
||||
THD *thd= (THD *)opt_arg;
|
||||
SELECT_LEX *first_select=unit->first_select(), *save_select;
|
||||
JOIN *join= first_select->join;
|
||||
Item_func *eq= NULL, **eq_ref= NULL;
|
||||
Item_ident *local_field= NULL;
|
||||
Item *outer_exp= NULL;
|
||||
Item *left_exp= NULL; Item_in_subselect *in_subs;
|
||||
Query_arena *arena= NULL, backup;
|
||||
int res= FALSE;
|
||||
List<Item> outer;
|
||||
Dynamic_array<EQ_FIELD_OUTER> eqs(5, 5);
|
||||
bool will_be_correlated;
|
||||
DBUG_ENTER("Item_exists_subselect::exists2in_processor");
|
||||
|
||||
if (!optimizer ||
|
||||
!optimizer_flag(thd, OPTIMIZER_SWITCH_EXISTS_TO_IN) ||
|
||||
(!is_top_level_item() && (!upper_not ||
|
||||
!upper_not->is_top_level_item())) ||
|
||||
first_select->is_part_of_union() ||
|
||||
first_select->group_list.elements ||
|
||||
first_select->order_list.elements ||
|
||||
join->having ||
|
||||
first_select->with_sum_func ||
|
||||
!first_select->leaf_tables.elements||
|
||||
!join->conds)
|
||||
DBUG_RETURN(FALSE);
|
||||
|
||||
DBUG_ASSERT(first_select->order_list.elements == 0 &&
|
||||
first_select->group_list.elements == 0 &&
|
||||
first_select->having == NULL);
|
||||
|
||||
if (find_inner_outer_equalities(&join->conds, eqs))
|
||||
DBUG_RETURN(FALSE);
|
||||
|
||||
DBUG_ASSERT(eqs.elements() != 0);
|
||||
|
||||
save_select= thd->lex->current_select;
|
||||
thd->lex->current_select= first_select;
|
||||
|
||||
/* check that the subquery has only dependencies we are going pull out */
|
||||
{
|
||||
List<Item> unused;
|
||||
Collect_deps_prm prm= {&unused, // parameters
|
||||
unit->first_select()->nest_level_base, // nest_level_base
|
||||
0, // count
|
||||
unit->first_select()->nest_level, // nest_level
|
||||
FALSE // collect
|
||||
};
|
||||
walk(&Item::collect_outer_ref_processor, TRUE, (uchar*)&prm);
|
||||
DBUG_ASSERT(prm.count > 0);
|
||||
DBUG_ASSERT(prm.count >= (uint)eqs.elements());
|
||||
will_be_correlated= prm.count > (uint)eqs.elements();
|
||||
if (upper_not && will_be_correlated)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((uint)eqs.elements() > (first_select->item_list.elements +
|
||||
first_select->select_n_reserved))
|
||||
goto out;
|
||||
/* It is simple query */
|
||||
DBUG_ASSERT(first_select->join->all_fields.elements ==
|
||||
first_select->item_list.elements);
|
||||
|
||||
arena= thd->activate_stmt_arena_if_needed(&backup);
|
||||
|
||||
while (first_select->item_list.elements > (uint)eqs.elements())
|
||||
{
|
||||
first_select->item_list.pop();
|
||||
first_select->join->all_fields.elements--;
|
||||
}
|
||||
{
|
||||
List_iterator<Item> it(first_select->item_list);
|
||||
|
||||
for (uint i= 0; i < (uint)eqs.elements(); i++)
|
||||
{
|
||||
Item *item= it++;
|
||||
eq_ref= eqs.at(i).eq_ref;
|
||||
eq= *eq_ref;
|
||||
local_field= eqs.at(i).local_field;
|
||||
outer_exp= eqs.at(i).outer_exp;
|
||||
/* Add the field to the SELECT_LIST */
|
||||
if (item)
|
||||
it.replace(local_field);
|
||||
else
|
||||
{
|
||||
first_select->item_list.push_back(local_field);
|
||||
first_select->join->all_fields.elements++;
|
||||
}
|
||||
first_select->ref_pointer_array[i]= (Item *)local_field;
|
||||
|
||||
/* remove the parts from condition */
|
||||
if (!upper_not || !local_field->maybe_null)
|
||||
{
|
||||
eq->arguments()[0]= new Item_int(1);
|
||||
eq->arguments()[1]= new Item_int(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
*eq_ref= new Item_func_isnotnull(
|
||||
new Item_field(thd,
|
||||
((Item_field*)(local_field->real_item()))->context,
|
||||
((Item_field*)(local_field->real_item()))->field));
|
||||
if((*eq_ref)->fix_fields(thd, (Item **)eq_ref))
|
||||
{
|
||||
res= TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
outer_exp->fix_after_pullout(unit->outer_select(), &outer_exp);
|
||||
outer_exp->update_used_tables();
|
||||
outer.push_back(outer_exp);
|
||||
}
|
||||
}
|
||||
|
||||
join->conds->update_used_tables();
|
||||
|
||||
/* make IN SUBQUERY and put outer_exp as left part */
|
||||
if (eqs.elements() == 1)
|
||||
left_exp= outer_exp;
|
||||
else
|
||||
{
|
||||
if (!(left_exp= new Item_row(outer)))
|
||||
{
|
||||
res= TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* make EXISTS->IN permanet (see Item_subselect::init()) */
|
||||
set_exists_transformed();
|
||||
|
||||
first_select->select_limit= NULL;
|
||||
if (!(in_subs= new Item_in_subselect(left_exp, first_select)))
|
||||
{
|
||||
res= TRUE;
|
||||
goto out;
|
||||
}
|
||||
in_subs->set_exists_transformed();
|
||||
optimizer->arguments()[0]= left_exp;
|
||||
optimizer->arguments()[1]= in_subs;
|
||||
in_subs->optimizer= optimizer;
|
||||
DBUG_ASSERT(is_top_level_item() ||
|
||||
(upper_not && upper_not->is_top_level_item()));
|
||||
in_subs->top_level_item();
|
||||
{
|
||||
SELECT_LEX *current= thd->lex->current_select;
|
||||
optimizer->reset_cache(); // renew cache, and we will not keep it
|
||||
thd->lex->current_select= unit->outer_select();
|
||||
DBUG_ASSERT(optimizer);
|
||||
if (optimizer->fix_left(thd))
|
||||
{
|
||||
res= TRUE;
|
||||
/*
|
||||
We should not restore thd->lex->current_select because it will be
|
||||
reset on exit from this procedure
|
||||
*/
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
As far as Item_ref_in_optimizer do not substitute itself on fix_fields
|
||||
we can use same item for all selects.
|
||||
*/
|
||||
in_subs->expr= new Item_direct_ref(&first_select->context,
|
||||
(Item**)optimizer->get_cache(),
|
||||
(char *)"<no matter>",
|
||||
(char *)in_left_expr_name);
|
||||
if (in_subs->fix_fields(thd, optimizer->arguments() + 1))
|
||||
{
|
||||
res= TRUE;
|
||||
/*
|
||||
We should not restore thd->lex->current_select because it will be
|
||||
reset on exit from this procedure
|
||||
*/
|
||||
goto out;
|
||||
}
|
||||
{
|
||||
/* Move dependence list */
|
||||
List_iterator_fast<Ref_to_outside> it(upper_refs);
|
||||
Ref_to_outside *upper;
|
||||
while ((upper= it++))
|
||||
{
|
||||
uint i;
|
||||
for (i= 0; i < (uint)eqs.elements(); i++)
|
||||
if (eqs.at(i).outer_exp->
|
||||
walk(&Item::find_item_processor, TRUE, (uchar*)upper->item))
|
||||
break;
|
||||
if (i == (uint)eqs.elements() &&
|
||||
(in_subs->upper_refs.push_back(upper, thd->stmt_arena->mem_root)))
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
in_subs->update_used_tables();
|
||||
/*
|
||||
The engine of the subquery is fixed so above fix_fields() is not
|
||||
complete and should be fixed
|
||||
*/
|
||||
in_subs->upper_refs= upper_refs;
|
||||
upper_refs.empty();
|
||||
thd->lex->current_select= current;
|
||||
}
|
||||
|
||||
DBUG_ASSERT(unit->item == in_subs);
|
||||
DBUG_ASSERT(join == first_select->join);
|
||||
/*
|
||||
Fix dependency info
|
||||
*/
|
||||
in_subs->is_correlated= will_be_correlated;
|
||||
if (!will_be_correlated)
|
||||
{
|
||||
first_select->uncacheable&= ~UNCACHEABLE_DEPENDENT_GENERATED;
|
||||
unit->uncacheable&= ~UNCACHEABLE_DEPENDENT_GENERATED;
|
||||
}
|
||||
/*
|
||||
set possible optimization strategies
|
||||
*/
|
||||
in_subs->emb_on_expr_nest= emb_on_expr_nest;
|
||||
res= check_and_do_in_subquery_rewrites(join);
|
||||
first_select->join->prepare_stage2();
|
||||
|
||||
first_select->fix_prepare_information(thd, &join->conds, &join->having);
|
||||
|
||||
if (upper_not)
|
||||
{
|
||||
Item *exp;
|
||||
if (eqs.elements() == 1)
|
||||
{
|
||||
exp= (optimizer->arguments()[0]->maybe_null ?
|
||||
(Item*)
|
||||
new Item_cond_and(
|
||||
new Item_func_isnotnull(
|
||||
new Item_direct_ref(&unit->outer_select()->context,
|
||||
optimizer->arguments(),
|
||||
(char *)"<no matter>",
|
||||
(char *)exists_outer_expr_name)),
|
||||
optimizer) :
|
||||
(Item *)optimizer);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Item> *and_list= new List<Item>;
|
||||
if (!and_list)
|
||||
{
|
||||
res= TRUE;
|
||||
goto out;
|
||||
}
|
||||
for (int i= 0; i < eqs.elements(); i++)
|
||||
{
|
||||
if (optimizer->arguments()[0]->maybe_null)
|
||||
{
|
||||
and_list->
|
||||
push_front(
|
||||
new Item_func_isnotnull(
|
||||
new Item_direct_ref(&unit->outer_select()->context,
|
||||
optimizer->arguments()[0]->addr(i),
|
||||
(char *)"<no matter>",
|
||||
(char *)exists_outer_expr_name)));
|
||||
}
|
||||
}
|
||||
if (and_list->elements > 0)
|
||||
{
|
||||
and_list->push_front(optimizer);
|
||||
exp= new Item_cond_and(*and_list);
|
||||
}
|
||||
else
|
||||
exp= optimizer;
|
||||
}
|
||||
upper_not->arguments()[0]= exp;
|
||||
if (!exp->fixed && exp->fix_fields(thd, upper_not->arguments()))
|
||||
{
|
||||
res= TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
thd->lex->current_select= save_select;
|
||||
if (arena)
|
||||
thd->restore_active_arena(arena, &backup);
|
||||
DBUG_RETURN(res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Prepare IN/ALL/ANY/SOME subquery transformation and call the appropriate
|
||||
transformation function.
|
||||
|
@ -2621,14 +3071,23 @@ void Item_in_subselect::print(String *str, enum_query_type query_type)
|
|||
Item_subselect::print(str, query_type);
|
||||
}
|
||||
|
||||
bool Item_exists_subselect::fix_fields(THD *thd_arg, Item **ref)
|
||||
{
|
||||
DBUG_ENTER("Item_exists_subselect::fix_fields");
|
||||
if (exists_transformed)
|
||||
DBUG_RETURN( !( (*ref)= new Item_int(1)));
|
||||
DBUG_RETURN(Item_subselect::fix_fields(thd_arg, ref));
|
||||
}
|
||||
|
||||
|
||||
bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
|
||||
{
|
||||
uint outer_cols_num;
|
||||
List<Item> *inner_cols;
|
||||
DBUG_ENTER("Item_in_subselect::fix_fields");
|
||||
|
||||
if (test_strategy(SUBS_SEMI_JOIN))
|
||||
return !( (*ref)= new Item_int(1));
|
||||
DBUG_RETURN( !( (*ref)= new Item_int(1)) );
|
||||
|
||||
/*
|
||||
Check if the outer and inner IN operands match in those cases when we
|
||||
|
@ -2660,7 +3119,7 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
|
|||
if (outer_cols_num != inner_cols->elements)
|
||||
{
|
||||
my_error(ER_OPERAND_COLUMNS, MYF(0), outer_cols_num);
|
||||
return TRUE;
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (outer_cols_num > 1)
|
||||
{
|
||||
|
@ -2670,7 +3129,7 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
|
|||
{
|
||||
inner_col= inner_col_it++;
|
||||
if (inner_col->check_cols(left_expr->element_index(i)->cols()))
|
||||
return TRUE;
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2678,12 +3137,12 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
|
|||
if (thd_arg->lex->is_view_context_analysis() &&
|
||||
left_expr && !left_expr->fixed &&
|
||||
left_expr->fix_fields(thd_arg, &left_expr))
|
||||
return TRUE;
|
||||
DBUG_RETURN(TRUE);
|
||||
else
|
||||
if (Item_subselect::fix_fields(thd_arg, ref))
|
||||
return TRUE;
|
||||
DBUG_RETURN(TRUE);
|
||||
fixed= TRUE;
|
||||
return FALSE;
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3811,6 +4270,7 @@ subselect_single_select_engine::change_result(Item_subselect *si,
|
|||
select_result_interceptor *res,
|
||||
bool temp)
|
||||
{
|
||||
DBUG_ENTER("subselect_single_select_engine::change_result");
|
||||
item= si;
|
||||
if (temp)
|
||||
{
|
||||
|
@ -3831,7 +4291,7 @@ subselect_single_select_engine::change_result(Item_subselect *si,
|
|||
that would not require a lot of extra code that would be harder to manage
|
||||
than the current code.
|
||||
*/
|
||||
return select_lex->join->change_result(res);
|
||||
DBUG_RETURN(select_lex->join->change_result(res));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -244,6 +244,7 @@ public:
|
|||
virtual bool expr_cache_is_needed(THD *);
|
||||
virtual void get_cache_parameters(List<Item> ¶meters);
|
||||
virtual bool is_subquery_processor (uchar *opt_arg) { return 1; }
|
||||
bool exists2in_processor(uchar *opt_arg) { return 0; }
|
||||
bool limit_index_condition_pushdown_processor(uchar *opt_arg)
|
||||
{
|
||||
return TRUE;
|
||||
|
@ -338,13 +339,35 @@ public:
|
|||
class Item_exists_subselect :public Item_subselect
|
||||
{
|
||||
protected:
|
||||
Item_func_not *upper_not;
|
||||
bool value; /* value of this item (boolean: exists/not-exists) */
|
||||
bool abort_on_null;
|
||||
|
||||
void init_length_and_dec();
|
||||
bool select_prepare_to_be_in();
|
||||
|
||||
public:
|
||||
/*
|
||||
Used by subquery optimizations to keep track about in which clause this
|
||||
subquery predicate is located:
|
||||
NO_JOIN_NEST - the predicate is an AND-part of the WHERE
|
||||
join nest pointer - the predicate is an AND-part of ON expression
|
||||
of a join nest
|
||||
NULL - for all other locations
|
||||
*/
|
||||
TABLE_LIST *emb_on_expr_nest;
|
||||
/**
|
||||
Reference on the Item_in_optimizer wrapper of this subquery
|
||||
*/
|
||||
Item_in_optimizer *optimizer;
|
||||
/* true if we got this from EXISTS or to IN */
|
||||
bool exists_transformed;
|
||||
|
||||
Item_exists_subselect(st_select_lex *select_lex);
|
||||
Item_exists_subselect(): Item_subselect() {}
|
||||
Item_exists_subselect()
|
||||
:Item_subselect(), upper_not(NULL),abort_on_null(0),
|
||||
emb_on_expr_nest(NULL), optimizer(0), exists_transformed(0)
|
||||
{}
|
||||
|
||||
subs_type substype() { return EXISTS_SUBS; }
|
||||
void reset()
|
||||
|
@ -360,11 +383,24 @@ public:
|
|||
String *val_str(String*);
|
||||
my_decimal *val_decimal(my_decimal *);
|
||||
bool val_bool();
|
||||
bool fix_fields(THD *thd, Item **ref);
|
||||
void fix_length_and_dec();
|
||||
virtual void print(String *str, enum_query_type query_type);
|
||||
bool select_transformer(JOIN *join);
|
||||
void top_level_item() { abort_on_null=1; }
|
||||
inline bool is_top_level_item() { return abort_on_null; }
|
||||
bool exists2in_processor(uchar *opt_arg);
|
||||
|
||||
Item* expr_cache_insert_transformer(uchar *thd_arg);
|
||||
|
||||
void mark_as_condition_AND_part(TABLE_LIST *embedding)
|
||||
{
|
||||
emb_on_expr_nest= embedding;
|
||||
}
|
||||
virtual void under_not(Item_func_not *upper) { upper_not= upper; };
|
||||
|
||||
void set_exists_transformed() { exists_transformed= TRUE; }
|
||||
|
||||
friend class select_exists_subselect;
|
||||
friend class subselect_uniquesubquery_engine;
|
||||
friend class subselect_indexsubquery_engine;
|
||||
|
@ -424,11 +460,8 @@ protected:
|
|||
*/
|
||||
Item *expr;
|
||||
bool was_null;
|
||||
bool abort_on_null;
|
||||
/* A bitmap of possible execution strategies for an IN predicate. */
|
||||
uchar in_strategy;
|
||||
public:
|
||||
Item_in_optimizer *optimizer;
|
||||
protected:
|
||||
/* Used to trigger on/off conditions that were pushed down to subselect */
|
||||
bool *pushed_cond_guards;
|
||||
|
@ -450,15 +483,6 @@ public:
|
|||
Item *left_expr;
|
||||
/* Priority of this predicate in the convert-to-semi-join-nest process. */
|
||||
int sj_convert_priority;
|
||||
/*
|
||||
Used by subquery optimizations to keep track about in which clause this
|
||||
subquery predicate is located:
|
||||
NO_JOIN_NEST - the predicate is an AND-part of the WHERE
|
||||
join nest pointer - the predicate is an AND-part of ON expression
|
||||
of a join nest
|
||||
NULL - for all other locations
|
||||
*/
|
||||
TABLE_LIST *emb_on_expr_nest;
|
||||
/*
|
||||
Types of left_expr and subquery's select list allow to perform subquery
|
||||
materialization. Currently, we set this to FALSE when it as well could
|
||||
|
@ -527,7 +551,9 @@ public:
|
|||
*/
|
||||
Item *original_item()
|
||||
{
|
||||
return is_flattenable_semijoin ? (Item*)this : (Item*)optimizer;
|
||||
return (is_flattenable_semijoin && !exists_transformed ?
|
||||
(Item*)this :
|
||||
(Item*)optimizer);
|
||||
}
|
||||
|
||||
bool *get_cond_guard(int i)
|
||||
|
@ -546,11 +572,9 @@ public:
|
|||
Item_in_subselect(Item * left_expr, st_select_lex *select_lex);
|
||||
Item_in_subselect()
|
||||
:Item_exists_subselect(), left_expr_cache(0), first_execution(TRUE),
|
||||
abort_on_null(0), in_strategy(SUBS_NOT_TRANSFORMED), optimizer(0),
|
||||
pushed_cond_guards(NULL), func(NULL), emb_on_expr_nest(NULL),
|
||||
is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE),
|
||||
upper_item(0)
|
||||
{}
|
||||
in_strategy(SUBS_NOT_TRANSFORMED),
|
||||
pushed_cond_guards(NULL), func(NULL), is_jtbm_merged(FALSE),
|
||||
is_jtbm_const_tab(FALSE), upper_item(0) {}
|
||||
void cleanup();
|
||||
subs_type substype() { return IN_SUBS; }
|
||||
void reset()
|
||||
|
@ -571,8 +595,6 @@ public:
|
|||
my_decimal *val_decimal(my_decimal *);
|
||||
void update_null_value () { (void) val_bool(); }
|
||||
bool val_bool();
|
||||
void top_level_item() { abort_on_null=1; }
|
||||
inline bool is_top_level_item() { return abort_on_null; }
|
||||
bool test_limit(st_select_lex_unit *unit);
|
||||
virtual void print(String *str, enum_query_type query_type);
|
||||
bool fix_fields(THD *thd, Item **ref);
|
||||
|
@ -589,19 +611,14 @@ public:
|
|||
void set_first_execution() { if (first_execution) first_execution= FALSE; }
|
||||
bool expr_cache_is_needed(THD *thd);
|
||||
inline bool left_expr_has_null();
|
||||
|
||||
|
||||
int optimize(double *out_rows, double *cost);
|
||||
/*
|
||||
/*
|
||||
Return the identifier that we could use to identify the subquery for the
|
||||
user.
|
||||
*/
|
||||
int get_identifier();
|
||||
|
||||
void mark_as_condition_AND_part(TABLE_LIST *embedding)
|
||||
{
|
||||
emb_on_expr_nest= embedding;
|
||||
}
|
||||
|
||||
bool test_strategy(uchar strategy)
|
||||
{ return test(in_strategy & strategy); }
|
||||
|
||||
|
@ -630,6 +647,9 @@ public:
|
|||
|
||||
void add_strategy (uchar strategy)
|
||||
{
|
||||
DBUG_ENTER("Item_in_subselect::add_strategy");
|
||||
DBUG_PRINT("enter", ("current: %u add: %u",
|
||||
(uint) in_strategy, (uint) strategy));
|
||||
DBUG_ASSERT(strategy != SUBS_NOT_TRANSFORMED);
|
||||
DBUG_ASSERT(!(strategy & SUBS_STRATEGY_CHOSEN));
|
||||
/*
|
||||
|
@ -639,16 +659,25 @@ public:
|
|||
DBUG_ASSERT(!(in_strategy & SUBS_STRATEGY_CHOSEN));
|
||||
*/
|
||||
in_strategy|= strategy;
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
void reset_strategy(uchar strategy)
|
||||
{
|
||||
DBUG_ENTER("Item_in_subselect::reset_strategy");
|
||||
DBUG_PRINT("enter", ("current: %u new: %u",
|
||||
(uint) in_strategy, (uint) strategy));
|
||||
DBUG_ASSERT(strategy != SUBS_NOT_TRANSFORMED);
|
||||
in_strategy= strategy;
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
void set_strategy(uchar strategy)
|
||||
{
|
||||
DBUG_ENTER("Item_in_subselect::set_strategy");
|
||||
DBUG_PRINT("enter", ("current: %u set: %u",
|
||||
(uint) in_strategy,
|
||||
(uint) (SUBS_STRATEGY_CHOSEN | strategy)));
|
||||
/* Check that only one strategy is set for execution. */
|
||||
DBUG_ASSERT(strategy == SUBS_SEMI_JOIN ||
|
||||
strategy == SUBS_IN_TO_EXISTS ||
|
||||
|
@ -658,7 +687,12 @@ public:
|
|||
strategy == SUBS_MAXMIN_INJECTED ||
|
||||
strategy == SUBS_MAXMIN_ENGINE);
|
||||
in_strategy= (SUBS_STRATEGY_CHOSEN | strategy);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
bool exists2in_processor(uchar *opt_arg __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
friend class Item_ref_null_helper;
|
||||
friend class Item_is_not_null_test;
|
||||
|
@ -666,6 +700,7 @@ public:
|
|||
friend class subselect_indexsubquery_engine;
|
||||
friend class subselect_hash_sj_engine;
|
||||
friend class subselect_partial_match_engine;
|
||||
friend class Item_exists_subselect;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -375,7 +375,12 @@ bool Item_sum::collect_outer_ref_processor(uchar *param)
|
|||
if ((ds= depended_from()) &&
|
||||
ds->nest_level_base == prm->nest_level_base &&
|
||||
ds->nest_level < prm->nest_level)
|
||||
prm->parameters->add_unique(this, &cmp_items);
|
||||
{
|
||||
if (prm->collect)
|
||||
prm->parameters->add_unique(this, &cmp_items);
|
||||
else
|
||||
prm->count++;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -666,6 +666,9 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
|
|||
8. No execution method was already chosen (by a prepared statement)
|
||||
9. Parent select is not a table-less select
|
||||
10. Neither parent nor child select have STRAIGHT_JOIN option.
|
||||
11. It is first optimisation (the subquery could be moved from ON
|
||||
clause during first optimisation and then be considered for SJ
|
||||
on the second when it is too late)
|
||||
*/
|
||||
if (optimizer_flag(thd, OPTIMIZER_SWITCH_SEMIJOIN) &&
|
||||
in_subs && // 1
|
||||
|
@ -679,7 +682,8 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
|
|||
select_lex->outer_select()->leaf_tables.elements && // 9
|
||||
!((join->select_options | // 10
|
||||
select_lex->outer_select()->join->select_options) // 10
|
||||
& SELECT_STRAIGHT_JOIN)) // 10
|
||||
& SELECT_STRAIGHT_JOIN) && // 10
|
||||
select_lex->first_cond_optimization) // 11
|
||||
{
|
||||
DBUG_PRINT("info", ("Subquery is semi-join conversion candidate"));
|
||||
|
||||
|
|
|
@ -4639,7 +4639,7 @@ void xid_cache_delete(XID_STATE *xid_state)
|
|||
int THD::decide_logging_format(TABLE_LIST *tables)
|
||||
{
|
||||
DBUG_ENTER("THD::decide_logging_format");
|
||||
DBUG_PRINT("info", ("query: %s", query()));
|
||||
DBUG_PRINT("info", ("Query: %s", query()));
|
||||
DBUG_PRINT("info", ("variables.binlog_format: %lu",
|
||||
variables.binlog_format));
|
||||
DBUG_PRINT("info", ("lex->get_stmt_unsafe_flags(): 0x%x",
|
||||
|
|
|
@ -1876,6 +1876,7 @@ void st_select_lex::init_query()
|
|||
max_equal_elems= 0;
|
||||
ref_pointer_array= 0;
|
||||
select_n_where_fields= 0;
|
||||
select_n_reserved= 0;
|
||||
select_n_having_items= 0;
|
||||
n_child_sum_items= 0;
|
||||
subquery_in_having= explicit_limit= 0;
|
||||
|
@ -2321,6 +2322,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
|
|||
ref_pointer_array=
|
||||
(Item **)thd->stmt_arena->alloc(sizeof(Item*) * (n_child_sum_items +
|
||||
item_list.elements +
|
||||
select_n_reserved +
|
||||
select_n_having_items +
|
||||
select_n_where_fields +
|
||||
order_group_num)*5);
|
||||
|
|
|
@ -819,6 +819,8 @@ public:
|
|||
and all inner subselects.
|
||||
*/
|
||||
uint select_n_where_fields;
|
||||
/* reserved for exists 2 in */
|
||||
uint select_n_reserved;
|
||||
enum_parsing_place parsing_place; /* where we are parsing expression */
|
||||
bool with_sum_func; /* sum function indicator */
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ template <class T> bool valid_buffer_range(T jump,
|
|||
#define OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE (1ULL << 25)
|
||||
#define OPTIMIZER_SWITCH_TABLE_ELIMINATION (1ULL << 26)
|
||||
#define OPTIMIZER_SWITCH_EXTENDED_KEYS (1ULL << 27)
|
||||
#define OPTIMIZER_SWITCH_LAST (1ULL << 27)
|
||||
#define OPTIMIZER_SWITCH_EXISTS_TO_IN (1ULL << 28)
|
||||
|
||||
#define OPTIMIZER_SWITCH_DEFAULT (OPTIMIZER_SWITCH_INDEX_MERGE | \
|
||||
OPTIMIZER_SWITCH_INDEX_MERGE_UNION | \
|
||||
|
|
|
@ -602,7 +602,9 @@ inline int setup_without_group(THD *thd, Item **ref_pointer_array,
|
|||
List<Item> &all_fields,
|
||||
COND **conds,
|
||||
ORDER *order,
|
||||
ORDER *group, bool *hidden_group_fields)
|
||||
ORDER *group,
|
||||
bool *hidden_group_fields,
|
||||
uint *reserved)
|
||||
{
|
||||
int res;
|
||||
nesting_map save_allow_sum_func=thd->lex->allow_sum_func ;
|
||||
|
@ -616,6 +618,13 @@ inline int setup_without_group(THD *thd, Item **ref_pointer_array,
|
|||
|
||||
thd->lex->allow_sum_func&= ~(1 << thd->lex->current_select->nest_level);
|
||||
res= setup_conds(thd, tables, leaves, conds);
|
||||
if (thd->lex->current_select->first_cond_optimization)
|
||||
{
|
||||
if (!res && *conds)
|
||||
(*reserved)= (*conds)->exists2in_reserved_items();
|
||||
else
|
||||
(*reserved)= 0;
|
||||
}
|
||||
|
||||
/* it's not wrong to have non-aggregated columns in a WHERE */
|
||||
thd->lex->current_select->set_non_agg_field_used(saved_non_agg_field_used);
|
||||
|
@ -763,7 +772,7 @@ JOIN::prepare(Item ***rref_pointer_array,
|
|||
setup_without_group(thd, (*rref_pointer_array), tables_list,
|
||||
select_lex->leaf_tables, fields_list,
|
||||
all_fields, &conds, order, group_list,
|
||||
&hidden_group_fields))
|
||||
&hidden_group_fields, &select_lex->select_n_reserved))
|
||||
DBUG_RETURN(-1); /* purecov: inspected */
|
||||
|
||||
ref_pointer_array= *rref_pointer_array;
|
||||
|
@ -1043,6 +1052,23 @@ JOIN::optimize_inner()
|
|||
table_count= select_lex->leaf_tables.elements;
|
||||
select_lex->update_used_tables();
|
||||
}
|
||||
/*
|
||||
In fact we transform underlying subqueries after their 'prepare' phase and
|
||||
before 'optimize' from upper query 'optimize' to allow semijoin
|
||||
conversion happened (which done in the same way.
|
||||
*/
|
||||
if(select_lex->first_cond_optimization &&
|
||||
conds && conds->walk(&Item::exists2in_processor, 0, (uchar *)thd))
|
||||
DBUG_RETURN(1);
|
||||
/*
|
||||
TODO: make view to decide if it is possible to write to WHERE directly or make Semi-Joins able to process ON condition if it is possible
|
||||
for (TABLE_LIST *tbl= tables_list; tbl; tbl= tbl->next_local)
|
||||
{
|
||||
if (tbl->on_expr &&
|
||||
tbl->on_expr->walk(&Item::exists2in_processor, 0, (uchar *)thd))
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
*/
|
||||
|
||||
if (transform_max_min_subquery())
|
||||
DBUG_RETURN(1); /* purecov: inspected */
|
||||
|
@ -6004,6 +6030,7 @@ static void choose_initial_table_order(JOIN *join)
|
|||
TABLE_LIST *emb_subq;
|
||||
JOIN_TAB **tab= join->best_ref + join->const_tables;
|
||||
JOIN_TAB **tabs_end= tab + join->table_count - join->const_tables;
|
||||
DBUG_ENTER("choose_initial_table_order");
|
||||
/* Find where the top-level JOIN_TABs end and subquery JOIN_TABs start */
|
||||
for (; tab != tabs_end; tab++)
|
||||
{
|
||||
|
@ -6013,7 +6040,7 @@ static void choose_initial_table_order(JOIN *join)
|
|||
uint n_subquery_tabs= tabs_end - tab;
|
||||
|
||||
if (!n_subquery_tabs)
|
||||
return;
|
||||
DBUG_VOID_RETURN;
|
||||
|
||||
/* Copy the subquery JOIN_TABs to a separate array */
|
||||
JOIN_TAB *subquery_tabs[MAX_TABLES];
|
||||
|
@ -6068,6 +6095,7 @@ static void choose_initial_table_order(JOIN *join)
|
|||
subq_tab += n_subquery_tables - 1;
|
||||
}
|
||||
}
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16373,7 +16401,9 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
|
|||
DBUG_ENTER("evaluate_join_record");
|
||||
DBUG_PRINT("enter",
|
||||
("evaluate_join_record join: %p join_tab: %p"
|
||||
" cond: %p error: %d", join, join_tab, select_cond, error));
|
||||
" cond: %p error: %d alias %s",
|
||||
join, join_tab, select_cond, error,
|
||||
join_tab->table->alias.ptr()));
|
||||
if (error > 0 || (join->thd->is_error())) // Fatal error
|
||||
DBUG_RETURN(NESTED_LOOP_ERROR);
|
||||
if (error < 0)
|
||||
|
@ -16486,6 +16516,7 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
|
|||
if (join_tab->check_weed_out_table && found)
|
||||
{
|
||||
int res= join_tab->check_weed_out_table->sj_weedout_check_row(join->thd);
|
||||
DBUG_PRINT("info", ("weedout_check: %d", res));
|
||||
if (res == -1)
|
||||
DBUG_RETURN(NESTED_LOOP_ERROR);
|
||||
else if (res == 1)
|
||||
|
@ -16506,8 +16537,8 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
|
|||
(See above join->return_tab= tab).
|
||||
*/
|
||||
join->examined_rows++;
|
||||
DBUG_PRINT("counts", ("join->examined_rows++: %lu",
|
||||
(ulong) join->examined_rows));
|
||||
DBUG_PRINT("counts", ("join->examined_rows++: %lu found: %d",
|
||||
(ulong) join->examined_rows, (int) found));
|
||||
|
||||
if (found)
|
||||
{
|
||||
|
|
|
@ -1473,6 +1473,7 @@ export const char *optimizer_switch_names[]=
|
|||
"optimize_join_buffer_size",
|
||||
"table_elimination",
|
||||
"extended_keys",
|
||||
"exists_to_in",
|
||||
"default", NullS
|
||||
};
|
||||
/** propagates changes to @@engine_condition_pushdown */
|
||||
|
@ -1514,7 +1515,8 @@ static Sys_var_flagset Sys_optimizer_switch(
|
|||
"semijoin_with_cache, "
|
||||
"subquery_cache, "
|
||||
"table_elimination, "
|
||||
"extended_keys "
|
||||
"extended_keys, "
|
||||
"exists_to_in "
|
||||
"} and val is one of {on, off, default}",
|
||||
SESSION_VAR(optimizer_switch), CMD_LINE(REQUIRED_ARG),
|
||||
optimizer_switch_names, DEFAULT(OPTIMIZER_SWITCH_DEFAULT),
|
||||
|
|
Loading…
Reference in a new issue