mirror of
https://github.com/MariaDB/server.git
synced 2025-01-21 22:34:18 +01:00
674e3388ad
The bug was fixed by the patch for mdev-10882.
7768 lines
247 KiB
Text
7768 lines
247 KiB
Text
create table t1 (a int, b int, c int);
|
|
create table t2 (a int, b int, c int, d decimal);
|
|
insert into t1 values
|
|
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
|
|
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
|
|
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
|
|
(7,11,708), (6,20,214);
|
|
insert into t2 values
|
|
(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
|
|
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
|
|
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
|
|
Warnings:
|
|
Note 1265 Data truncated for column 'd' at row 5
|
|
create table t1_double(a int, b double, c double);
|
|
insert into t1_double values
|
|
(1,23.4,14.3333), (1,12.5,18.9), (3,12.5,18.9),
|
|
(4,33.4,14.3333), (4,14.3333,13.65), (5,17.89,7.22),
|
|
(6,33.4,14.3), (10,33.4,13.65), (11,33.4,13.65);
|
|
create table t2_double(a int, b double, c double);
|
|
insert into t2_double values
|
|
(1,22.4,14.3333), (1,12.5,18.9), (2,22.4,18.9),
|
|
(4,33.4,14.3333), (5,22.4,13.65), (7,17.89,18.9),
|
|
(6,33.4,14.3333), (10,31.4,13.65), (12,33.4,13.65);
|
|
create table t1_char(a char, b char(8), c int);
|
|
insert into t1_char values
|
|
('a','Ivan',1), ('b','Vika',2), ('b','Inga',6), ('c','Vika',7),
|
|
('b','Ivan',7), ('a','Alex',6), ('b','Inga',5), ('d','Ron',9),
|
|
('d','Harry',2), ('d','Hermione',3), ('c','Ivan',3), ('c','Harry',4);
|
|
create table t2_char(a char, b char(8), c int);
|
|
insert into t2_char values
|
|
('b','Ivan',1), ('c','Vinny',3), ('c','Inga',9), ('a','Vika',1),
|
|
('c','Ivan',2), ('b','Ali',6), ('c','Inga',2), ('a','Ron',9),
|
|
('d','Harry',1), ('b','Hermes',3), ('b','Ivan',11), ('b','Harry',4);
|
|
create table t1_decimal (a decimal(3,1), b decimal(3,1), c int);
|
|
insert into t1_decimal values
|
|
(1,1,23),(2,2,11),(3,3,16),
|
|
(1,1,12),(1,1,14),(2,3,15),
|
|
(2,1,13),(2,3,11),(3,3,16);
|
|
create table t2_decimal (a decimal(3,1), b decimal(3,1), c int);
|
|
insert into t2_decimal values
|
|
(2,1,13),(2,2,11),(3,3,16),
|
|
(1,3,22),(1,3,14),(2,2,15),
|
|
(2,1,43),(2,3,11),(2,3,16);
|
|
create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707;
|
|
create view v2 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707;
|
|
create view v3 as select a, b, min(c) as min_c from t1
|
|
where t1.a<10 group by a,b having min_c > 109;
|
|
create view v4 as
|
|
select a, b, min(max_c) as min_c from v1
|
|
where (v1.a<15) group by a,b;
|
|
create view v_union as
|
|
select a, b, min(c) as c from t1
|
|
where t1.a<10 group by a,b having c > 109
|
|
union
|
|
select a, b, max(c) as c from t1
|
|
where t1.b>10 group by a,b having c < 300;
|
|
create view v2_union as
|
|
select a, b, min(c) as c from t1
|
|
where t1.a<10 group by a,b having c > 109
|
|
union
|
|
select a, b, max(c) as c from t1
|
|
where t1.b>10 group by a,b having c < 300
|
|
union
|
|
select a, b, avg(c) as c from t1
|
|
where t1.c>300 group by a,b having c < 707;
|
|
create view v3_union as
|
|
select a, b, (a+1) as c from t1
|
|
where t1.a<10
|
|
union
|
|
select a, b, c from t1
|
|
where t1.b>10 and t1.c>100;
|
|
create view v4_union as
|
|
select a, b, max(c)-100 as c from t1
|
|
where t1.a<10 group by a,b having c > 109
|
|
union
|
|
select a, b, (c+100) as c from t1
|
|
where t1.b>10;
|
|
create view v_double as
|
|
select a, avg(a/4) as avg_a, b, c from t1_double
|
|
where (b>12.2) group by b,c having (avg_a<22.333);
|
|
create view v_char as
|
|
select a, b, max(c) as max_c from t1_char
|
|
group by a,b having max_c < 9;
|
|
create view v_decimal as
|
|
select a, b, avg(c) as avg_c from t1_decimal
|
|
group by a,b having (avg_c>12);
|
|
# conjunctive subformula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 8 64 248 107
|
|
6 20 315 279.3333 8 80 800 314
|
|
select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 8 64 248 107
|
|
6 20 315 279.3333 8 80 800 314
|
|
explain select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.max_c>214) and (t2.a>v1.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c > 214)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(t2.a > v1.a)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 214))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
6 20 315 279.3333 6 23 303 909
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
6 20 315 279.3333 6 23 303 909
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c > 300)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
5 27 132 132.0000 1 19 203 107
|
|
5 27 132 132.0000 3 12 231 190
|
|
select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
5 27 132 132.0000 1 19 203 107
|
|
5 27 132 132.0000 3 12 231 190
|
|
explain select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 400) or (v1.max_c < 135))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.max_c > 400) and (t2.a > v1.a)) or ((v1.max_c < 135) and (t2.a < v1.a)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((max_c > 400) or (max_c < 135)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
|
|
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279
|
|
select * from v1,t2 where
|
|
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
|
|
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279
|
|
explain select * from v1,t2 where
|
|
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
|
|
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
|
|
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 300) or (v1.max_c < 135))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.b = t2.b) and (v1.max_c > 300) and (v1.avg_c > t2.d)) or ((v1.a = t2.a) and (v1.max_c < 135) and (v1.max_c < t2.c)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((max_c > 300) or (max_c < 135)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
explain select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a>6) and (t2.b>v1.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a > 6)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(t2.b > v1.b)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 6)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v2,t2 where (v2.b>25) and (t2.a<v2.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.b > 25)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(t2.a < v2.a)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b > 25))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 3 12 231 190
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where
|
|
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 3 12 231 190
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where
|
|
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a>7) and (t2.c<v1.max_c)) or ((v1.a<2) and (t2.b<v1.b));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a > 7) or (v1.a < 2))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a > 7) and (t2.c < v1.max_c)) or ((v1.a < 2) and (t2.b < v1.b)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 7) or (t1.a < 2))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2,t2 where
|
|
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 2 3 207 207
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 1 19 203 107
|
|
6 20 315 279.3333 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v2,t2 where
|
|
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 2 3 207 207
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 1 19 203 107
|
|
6 20 315 279.3333 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v2,t2 where
|
|
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v2,t2 where
|
|
((v2.a>7) and (t2.c<v2.max_c)) or ((v2.a>5) and (t2.b<v2.b));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v2.a > 7) or (v2.a > 5))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v2.a > 7) and (t2.c < v2.max_c)) or ((v2.a > 5) and (t2.b < v2.b)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and ((t1.a > 7) or (t1.a > 5)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
|
|
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
select * from v1,t2 where
|
|
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
|
|
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
explain select * from v1,t2 where
|
|
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
|
|
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a>4) and (v1.b>t2.b) and (v1.max_c=t2.d)) or
|
|
((v1.a<2) and (v1.max_c<t2.c) and (v1.max_c=t2.d));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a > 4) or (v1.a < 2))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a > 4) and (v1.b > t2.b) and (v1.max_c = t2.d)) or ((v1.a < 2) and (v1.max_c < t2.c) and (v1.max_c = t2.d)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 4) or (t1.a < 2))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformulas : pushing into HAVING and WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 6 23 303 909
|
|
select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 6 23 303 909
|
|
explain select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a<2) and (v1.max_c>400) and (t2.b>v1.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 2) and (v1.max_c > 400))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(t2.b > v1.b)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 400))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a < 2)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_double as v,t2_double as t where
|
|
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
|
|
a avg_a b c a b c
|
|
1 0.50000000 12.5 18.9 1 22.4 14.3333
|
|
1 0.50000000 12.5 18.9 1 12.5 18.9
|
|
4 1.00000000 33.4 14.3333 4 33.4 14.3333
|
|
4 1.00000000 14.3333 13.65 4 33.4 14.3333
|
|
5 1.25000000 17.89 7.22 5 22.4 13.65
|
|
6 1.50000000 33.4 14.3 6 33.4 14.3333
|
|
10 2.62500000 33.4 13.65 10 31.4 13.65
|
|
select * from v_double as v,t2_double as t where
|
|
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
|
|
a avg_a b c a b c
|
|
1 0.50000000 12.5 18.9 1 22.4 14.3333
|
|
1 0.50000000 12.5 18.9 1 12.5 18.9
|
|
4 1.00000000 33.4 14.3333 4 33.4 14.3333
|
|
4 1.00000000 14.3333 13.65 4 33.4 14.3333
|
|
5 1.25000000 17.89 7.22 5 22.4 13.65
|
|
6 1.50000000 33.4 14.3 6 33.4 14.3333
|
|
10 2.62500000 33.4 13.65 10 31.4 13.65
|
|
explain select * from v_double as v,t2_double as t where
|
|
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t.a 2 Using where
|
|
2 DERIVED t1_double ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_double as v,t2_double as t where
|
|
(v.a=t.a) and (v.avg_a>0.45) and (v.b>10);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.avg_a > 0.45) and (v.b > 10))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((avg_a < 22.333) and (avg_a > 0.45))",
|
|
"filesort": {
|
|
"sort_key": "t1_double.b, t1_double.c",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_double",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_double.b > 12.2) and (t1_double.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
|
|
a b avg_c a b c
|
|
3.0 3.0 16.0000 3.0 3.0 16
|
|
select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
|
|
a b avg_c a b c
|
|
3.0 3.0 16.0000 3.0 3.0 16
|
|
explain select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 3 test.t.a 2 Using where
|
|
2 DERIVED t1_decimal ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=t.a) and (v.avg_c>15) and (v.b>1);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "3",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.avg_c > 15) and (v.b > 1))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((avg_c > 12) and (avg_c > 15))",
|
|
"filesort": {
|
|
"sort_key": "t1_decimal.a, t1_decimal.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_decimal",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1_decimal.b > 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into HAVING and WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
|
|
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where
|
|
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
|
|
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 3 12 231 190
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where
|
|
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
|
|
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a>7) and (v1.max_c>300) and (t2.c<v1.max_c)) or
|
|
((v1.a<4) and (v1.max_c<500) and (t2.b<v1.b));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a > 7) and (v1.max_c > 300)) or ((v1.a < 4) and (v1.max_c < 500)))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a > 7) and (v1.max_c > 300) and (t2.c < v1.max_c)) or ((v1.a < 4) and (v1.max_c < 500) and (t2.b < v1.b)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (((t1.a > 7) and (max_c > 300)) or ((t1.a < 4) and (max_c < 500))))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 7) or (t1.a < 4))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where ((v1.a<2) and (v1.max_c>120)) or (v1.a>7);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a < 2) and (v1.max_c > 120)) or (v1.a > 7))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a < 2) and (v1.max_c > 120)) or (v1.a > 7))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (((t1.a < 2) and (max_c > 120)) or (t1.a > 7)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 2) or (t1.a > 7))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formulas : pushing into WHERE and HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c>120) and (v1.b=t2.b)) or (v1.a>7);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a < 2) and (v1.max_c > 120)) or (v1.a > 7))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.b = t2.b) and (v1.a < 2) and (v1.max_c > 120)) or (v1.a > 7))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (((t1.a < 2) and (max_c > 120)) or (t1.a > 7)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 2) or (t1.a > 7))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or
|
|
((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or
|
|
((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
explain select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or
|
|
((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a<2) and (v1.max_c<200) and (t2.c>v1.max_c) and (v1.max_c=t2.d)) or
|
|
((v1.a>4) and (v1.max_c<500) and (t2.b<v1.b) and (v1.max_c=t2.c));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a < 2) and (v1.max_c < 200)) or (v1.a > 4))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a < 2) and (v1.max_c < 200) and (t2.c > v1.max_c) and (v1.max_c = t2.d)) or ((v1.max_c = t2.c) and (v1.a > 4) and (t2.c < 500) and (t2.b < v1.b)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (((t1.a < 2) and (max_c < 200)) or ((t1.a > 4) and (max_c < 500))))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 2) or (t1.a > 4))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# prepare of a query containing extracted or formula
|
|
prepare stmt from "select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
|
|
execute stmt;
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
5 27 132 132.0000 1 19 203 107
|
|
5 27 132 132.0000 3 12 231 190
|
|
execute stmt;
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
5 27 132 132.0000 1 19 203 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
5 27 132 132.0000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
deallocate prepare stmt;
|
|
prepare stmt from
|
|
"explain format=json select * from v1,t2 where
|
|
((v1.max_c>400) and (t2.a>v1.a)) or ((v1.max_c<135) and (t2.a<v1.a));";
|
|
execute stmt;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 400) or (v1.max_c < 135))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.max_c > 400) and (t2.a > v1.a)) or ((v1.max_c < 135) and (t2.a < v1.a)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((max_c > 400) or (max_c < 135)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
execute stmt;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 400) or (v1.max_c < 135))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.max_c > 400) and (t2.a > v1.a)) or ((v1.max_c < 135) and (t2.a < v1.a)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((max_c > 400) or (max_c < 135)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
deallocate prepare stmt;
|
|
# conjunctive subformula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
explain select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.b 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (t2.a=v1.a) and (v1.b=t2.b) and (v1.a=1);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a = 1) and (t2.b is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["test.t2.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a = 1)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
explain select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.d 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a=5) and (v1.max_c=t2.d);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.d is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["max_c"],
|
|
"ref": ["test.t2.d"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 5) and (v1.max_c = t2.d))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformula : pushing into WHERE using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (t2.a<5) and (v1.a=t2.a);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
select * from v1,t2 where (t2.a<5) and (v1.a=t2.a);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 19 107 107.0000 1 19 203 107
|
|
explain select * from v1,t2 where (t2.a<5) and (v1.a=t2.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 2
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (t2.a<5) and (v1.a=t2.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a < 5) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a < 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a);
|
|
a b max_c avg_c a b c d
|
|
select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a);
|
|
a b max_c avg_c a b c d
|
|
explain select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 10 test.t2.a,test.t2.a 2
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "10",
|
|
"used_key_parts": ["a", "b"],
|
|
"ref": ["test.t2.a", "test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.b = t1.a)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformula : pushing into HAVING using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279
|
|
select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279
|
|
explain select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.c 2
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (t2.c>150) and (v1.max_c=t2.c);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.c > 150) and (t2.c is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["max_c"],
|
|
"ref": ["test.t2.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 150))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted and formula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
|
|
a b max_c avg_c a b c d
|
|
select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
|
|
a b max_c avg_c a b c d
|
|
explain select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
|
|
explain format=json select * from v1,t2 where (v1.a=v1.b) and (v1.a=t2.a) and (v1.a=3);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 3)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 3) and (v1.b = 3))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 3) and (t1.b = 3))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 2 3 207 207
|
|
explain select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
|
|
explain format=json select * from v1,t2 where (v1.a=1) and (v1.b=21) and (t2.a=2);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 2)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 1) and (v1.b = 21))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 1) and (t1.b = 21))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
|
|
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
|
|
a b max_c a b c
|
|
c Harry 4 d Harry 1
|
|
c Harry 4 b Harry 4
|
|
select * from v_char as v,t2_char as t where
|
|
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
|
|
a b max_c a b c
|
|
c Harry 4 d Harry 1
|
|
c Harry 4 b Harry 4
|
|
explain select * from v_char as v,t2_char as t where
|
|
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 Using where
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_char as v,t2_char as t where
|
|
(v.a='c') and (v.b<'Hermes') and ((v.b=t.b) or (v.max_c>20));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.a = 'c') and (v.b < 'Hermes'))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 9)",
|
|
"filesort": {
|
|
"sort_key": "t1_char.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_char",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_char.a = 'c') and (t1_char.b < 'Hermes'))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((t.b = v.b) or (v.max_c > 20))"
|
|
}
|
|
}
|
|
}
|
|
# extracted and formula : pushing into WHERE using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1));
|
|
a b avg_c a b c
|
|
1.0 1.0 16.3333 2.0 1.0 13
|
|
3.0 3.0 16.0000 3.0 3.0 16
|
|
3.0 3.0 16.0000 1.0 3.0 22
|
|
3.0 3.0 16.0000 1.0 3.0 14
|
|
1.0 1.0 16.3333 2.0 1.0 43
|
|
3.0 3.0 16.0000 2.0 3.0 11
|
|
3.0 3.0 16.0000 2.0 3.0 16
|
|
select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1));
|
|
a b avg_c a b c
|
|
1.0 1.0 16.3333 2.0 1.0 13
|
|
3.0 3.0 16.0000 3.0 3.0 16
|
|
3.0 3.0 16.0000 1.0 3.0 22
|
|
3.0 3.0 16.0000 1.0 3.0 14
|
|
1.0 1.0 16.3333 2.0 1.0 43
|
|
3.0 3.0 16.0000 2.0 3.0 11
|
|
3.0 3.0 16.0000 2.0 3.0 16
|
|
explain select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 6 test.t.b,test.t.b 2
|
|
2 DERIVED t1_decimal ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_decimal as v,t2_decimal as t where
|
|
(v.a=v.b) and (v.b=t.b) and ((t.b>1) or (v.a=1));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(((t.b > 1) or (t.b = 1)) and (t.b is not null) and (t.b is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "6",
|
|
"used_key_parts": ["a", "b"],
|
|
"ref": ["test.t.b", "test.t.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(avg_c > 12)",
|
|
"filesort": {
|
|
"sort_key": "t1_decimal.a, t1_decimal.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_decimal",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_decimal.b = t1_decimal.a) and ((t1_decimal.a > 1) or (t1_decimal.a = 1)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into HAVING using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2
|
|
where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279
|
|
select * from v1,t2
|
|
where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
5 16 207 207.0000 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279
|
|
explain select * from v1,t2
|
|
where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2
|
|
where ((t2.a<4) and (v1.a=t2.a)) or ((t2.c>150) and (v1.max_c=t2.c));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a < 4) or (t2.c > 150))"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a = t2.a) and (t2.a < 4)) or ((v1.max_c = t2.c) and (t2.c > 150)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((t1.a < 4) or (max_c > 150)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformulas : pushing into WHERE and HAVING using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2
|
|
where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279
|
|
select * from v1,t2
|
|
where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c));
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279
|
|
explain select * from v1,t2
|
|
where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 10 test.t2.a,test.t2.c 2
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2
|
|
where ((t2.a>5) and (v1.a=t2.a)) and ((t2.c>250) and (v1.max_c=t2.c));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a > 5) and (t2.c > 250) and (t2.a is not null) and (t2.c is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "10",
|
|
"used_key_parts": ["a", "max_c"],
|
|
"ref": ["test.t2.a", "test.t2.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 250))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformulas : pushing into WHERE and HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
|
|
a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=8) and (v1.a=t2.a) and (v1.max_c=404);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 8)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 8) and (v1.max_c = 404))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c = 404)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 8)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformulas : pushing into WHERE and HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
select * from v1,t2 where
|
|
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
|
|
a b max_c avg_c a b c d
|
|
5 16 207 207.0000 2 3 207 207
|
|
explain select * from v1,t2 where
|
|
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.d 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
(v1.a>3) and (v1.max_c>200) and (t2.b<v1.b) and (t2.d=v1.max_c);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.d is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["max_c"],
|
|
"ref": ["test.t2.d"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a > 3) and (v1.max_c > 200) and (t2.b < v1.b) and (t2.d = v1.max_c))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 3)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformula : pushing into WHERE
|
|
# extracted or formula : pushing into HAVING using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_double as v,t2_double as t where
|
|
(v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1));
|
|
a avg_a b c a b c
|
|
select * from v_double as v,t2_double as t where
|
|
(v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1));
|
|
a avg_a b c a b c
|
|
explain select * from v_double as v,t2_double as t where
|
|
(v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 18 test.t.c,test.t.c 2 Using where
|
|
2 DERIVED t1_double ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_double as v,t2_double as t where
|
|
(v.b=v.c) and (v.c=t.c) and ((t.c>10) or (v.a=1));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t.c is not null) and (t.c is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "18",
|
|
"used_key_parts": ["b", "c"],
|
|
"ref": ["test.t.c", "test.t.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((t.c > 10) or (v.a = 1))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((avg_a < 22.333) and ((t1_double.b > 10) or (t1_double.a = 1)))",
|
|
"filesort": {
|
|
"sort_key": "t1_double.b, t1_double.c",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_double",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_double.c = t1_double.b) and (t1_double.b > 12.2))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# conjunctive subformula : pushing into WHERE
|
|
# extracted or formula : pushing into HAVING using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_double as v,t2_double as t where
|
|
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
|
|
a avg_a b c a b c
|
|
1 0.50000000 12.5 18.9 1 12.5 18.9
|
|
1 0.50000000 12.5 18.9 2 22.4 18.9
|
|
1 0.50000000 12.5 18.9 7 17.89 18.9
|
|
select * from v_double as v,t2_double as t where
|
|
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
|
|
a avg_a b c a b c
|
|
1 0.50000000 12.5 18.9 1 12.5 18.9
|
|
1 0.50000000 12.5 18.9 2 22.4 18.9
|
|
1 0.50000000 12.5 18.9 7 17.89 18.9
|
|
explain select * from v_double as v,t2_double as t where
|
|
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 9 test.t.c 2 Using where
|
|
2 DERIVED t1_double ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_double as v,t2_double as t where
|
|
(((v.a>0.2) or (v.b<17)) or (t.c>17)) and (t.c=v.c) and (v.c>18);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t.c > 18) and (t.c is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "9",
|
|
"used_key_parts": ["c"],
|
|
"ref": ["test.t.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.a > 0.2) or (v.b < 17) or (t.c > 17))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((avg_a < 22.333) and ((t1_double.a > 0.2) or (t1_double.b < 17) or (t1_double.c > 17)))",
|
|
"filesort": {
|
|
"sort_key": "t1_double.b, t1_double.c",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_double",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_double.b > 12.2) and (t1_double.c > 18))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_decimal as v,t2_decimal as t where
|
|
(((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
|
|
a b avg_c a b c
|
|
2.0 1.0 13.0000 2.0 1.0 13
|
|
2.0 3.0 13.0000 2.0 1.0 13
|
|
2.0 1.0 13.0000 2.0 2.0 11
|
|
2.0 3.0 13.0000 2.0 2.0 11
|
|
2.0 1.0 13.0000 3.0 3.0 16
|
|
2.0 3.0 13.0000 3.0 3.0 16
|
|
2.0 1.0 13.0000 1.0 3.0 22
|
|
2.0 3.0 13.0000 1.0 3.0 22
|
|
2.0 1.0 13.0000 1.0 3.0 14
|
|
2.0 3.0 13.0000 1.0 3.0 14
|
|
2.0 1.0 13.0000 2.0 2.0 15
|
|
2.0 3.0 13.0000 2.0 2.0 15
|
|
2.0 1.0 13.0000 2.0 1.0 43
|
|
2.0 3.0 13.0000 2.0 1.0 43
|
|
2.0 1.0 13.0000 2.0 3.0 11
|
|
2.0 3.0 13.0000 2.0 3.0 11
|
|
2.0 1.0 13.0000 2.0 3.0 16
|
|
2.0 3.0 13.0000 2.0 3.0 16
|
|
select * from v_decimal as v,t2_decimal as t where
|
|
(((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
|
|
a b avg_c a b c
|
|
2.0 1.0 13.0000 2.0 1.0 13
|
|
2.0 3.0 13.0000 2.0 1.0 13
|
|
2.0 1.0 13.0000 2.0 2.0 11
|
|
2.0 3.0 13.0000 2.0 2.0 11
|
|
2.0 1.0 13.0000 3.0 3.0 16
|
|
2.0 3.0 13.0000 3.0 3.0 16
|
|
2.0 1.0 13.0000 1.0 3.0 22
|
|
2.0 3.0 13.0000 1.0 3.0 22
|
|
2.0 1.0 13.0000 1.0 3.0 14
|
|
2.0 3.0 13.0000 1.0 3.0 14
|
|
2.0 1.0 13.0000 2.0 2.0 15
|
|
2.0 3.0 13.0000 2.0 2.0 15
|
|
2.0 1.0 13.0000 2.0 1.0 43
|
|
2.0 3.0 13.0000 2.0 1.0 43
|
|
2.0 1.0 13.0000 2.0 3.0 11
|
|
2.0 3.0 13.0000 2.0 3.0 11
|
|
2.0 1.0 13.0000 2.0 3.0 16
|
|
2.0 3.0 13.0000 2.0 3.0 16
|
|
explain select * from v_decimal as v,t2_decimal as t where
|
|
(((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 9 Using join buffer (flat, BNL join)
|
|
2 DERIVED t1_decimal ALL NULL NULL NULL NULL 9 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_decimal as v,t2_decimal as t where
|
|
(((v.a>4) or (v.a=2)) or (v.b>3)) and (v.avg_c=13);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v.a > 4) or (v.a = 2) or (v.b > 3)) and (v.avg_c = 13))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((avg_c > 12) and (avg_c = 13))",
|
|
"filesort": {
|
|
"sort_key": "t1_decimal.a, t1_decimal.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_decimal",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_decimal.a > 4) or (t1_decimal.a = 2) or (t1_decimal.b > 3))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL"
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
|
|
a b max_c avg_c a b c d
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
|
|
a b max_c avg_c a b c d
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 10 test.t2.a,test.t2.a 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.a=v1.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "10",
|
|
"used_key_parts": ["a", "b"],
|
|
"ref": ["test.t2.a", "test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c > 300)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b = t1.a) and (t1.a > 5))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# nothing to push
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (t2.a<2) and (t2.c>900);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 21 909 12
|
|
5 16 207 207.0000 1 21 909 12
|
|
5 27 132 132.0000 1 21 909 12
|
|
6 20 315 279.3333 1 21 909 12
|
|
8 33 404 213.6667 1 21 909 12
|
|
select * from v1,t2 where (t2.a<2) and (t2.c>900);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 21 909 12
|
|
5 16 207 207.0000 1 21 909 12
|
|
5 27 132 132.0000 1 21 909 12
|
|
6 20 315 279.3333 1 21 909 12
|
|
8 33 404 213.6667 1 21 909 12
|
|
explain select * from v1,t2 where (t2.a<2) and (t2.c>900);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (t2.a<2) and (t2.c>900);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a < 2) and (t2.c > 900))"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279
|
|
1 19 107 107.0000 1 19 203 107
|
|
select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279
|
|
1 19 107 107.0000 1 19 203 107
|
|
explain select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 10 test.t2.a,test.t2.b 2
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a=t2.a) and (v1.b=t2.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.b is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "10",
|
|
"used_key_parts": ["a", "b"],
|
|
"ref": ["test.t2.a", "test.t2.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
select * from v1,t2 where
|
|
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
explain select * from v1,t2 where
|
|
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
(t2.a=v1.a) or (v1.b=t2.b) and ((v1.a=1) or (v1.a=6));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a = t2.a) or ((v1.b = t2.b) and ((v1.a = 1) or (v1.a = 6))))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 6 20 315 279
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 19 107 107.0000 8 80 800 314
|
|
1 19 107 107.0000 3 12 231 190
|
|
1 19 107 107.0000 6 23 303 909
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
5 16 207 207.0000 2 3 207 207
|
|
5 27 132 132.0000 2 3 207 207
|
|
6 20 315 279.3333 2 3 207 207
|
|
8 33 404 213.6667 2 3 207 207
|
|
select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 2 3 207 207
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 7 13 312 406
|
|
1 19 107 107.0000 8 64 248 107
|
|
1 19 107 107.0000 6 20 315 279
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 19 107 107.0000 8 80 800 314
|
|
1 19 107 107.0000 3 12 231 190
|
|
1 19 107 107.0000 6 23 303 909
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 1 19 203 107
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
5 16 207 207.0000 2 3 207 207
|
|
5 27 132 132.0000 2 3 207 207
|
|
6 20 315 279.3333 2 3 207 207
|
|
8 33 404 213.6667 2 3 207 207
|
|
explain select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where (v1.a=1) or (v1.b=21) or (t2.a=2);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a = 1) or (v1.b = 21) or (t2.a = 2))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 21 909 12
|
|
5 16 207 207.0000 1 21 909 12
|
|
5 27 132 132.0000 1 21 909 12
|
|
6 20 315 279.3333 1 21 909 12
|
|
8 33 404 213.6667 1 21 909 12
|
|
select * from v1,t2 where
|
|
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 21 500 234.6000 1 21 909 12
|
|
5 16 207 207.0000 1 21 909 12
|
|
5 27 132 132.0000 1 21 909 12
|
|
6 20 315 279.3333 1 21 909 12
|
|
8 33 404 213.6667 1 21 909 12
|
|
explain select * from v1,t2 where
|
|
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,t2 where
|
|
(t2.a<2) and (t2.c>900) and ((v1.a<t2.a) or (t2.a<11));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a < 2) and (t2.c > 900))"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a < t2.a) or (t2.a < 11))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : nothing to push
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
|
|
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
select * from v1,v2,t2 where
|
|
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
explain select * from v1,v2,t2 where
|
|
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key1 key1 5 test.t2.a 2
|
|
1 PRIMARY <derived3> ref key0 key0 5 test.t2.a 2 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where
|
|
(v1.a=v2.a) and (v1.a=t2.a) and (v2.b<50);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key1"],
|
|
"key": "key1",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.b < 50)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b < 50))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279.3333 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279.3333 3 12 231 190
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 8 33 404 213.6667 6 23 303 909
|
|
select * from v1,v2,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 2 3 207 207
|
|
6 20 315 279.3333 6 20 315 279.3333 1 21 909 12
|
|
6 20 315 279.3333 6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279.3333 3 12 231 190
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,v2,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived3> ref key0 key0 5 v1.b 2 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and (t2.b<50) and (v1.b=v2.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b < 50)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(v1.b is not null)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v1.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v2.a = v1.a) or (v1.a = t2.a))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
|
|
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
|
|
select * from v1,v2,t2 where
|
|
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 8 33 404 213.6667 8 80 800 314
|
|
explain select * from v1,v2,t2 where
|
|
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where
|
|
((v1.a=v2.a) and (v1.a=t2.a)) or ((v2.b>13) and (t2.c<115));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a = t2.a) or (t2.c < 115))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "incremental",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a = t2.a) and (v2.a = t2.a)) or ((v2.b > 13) and (t2.c < 115)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing in all tables
|
|
# conjunctive subformula : pushing into HAVING
|
|
# extracted or formula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
|
|
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
1 19 107 107.0000 6 20 315 279.3333 1 21 909 12
|
|
1 19 107 107.0000 6 20 315 279.3333 1 19 203 107
|
|
1 19 107 107.0000 8 33 404 213.6667 1 21 909 12
|
|
1 19 107 107.0000 8 33 404 213.6667 1 19 203 107
|
|
select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
|
|
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
1 19 107 107.0000 6 20 315 279.3333 1 21 909 12
|
|
1 19 107 107.0000 6 20 315 279.3333 1 19 203 107
|
|
1 19 107 107.0000 8 33 404 213.6667 1 21 909 12
|
|
1 19 107 107.0000 8 33 404 213.6667 1 19 203 107
|
|
explain select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
|
|
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where ((v1.a=v2.a) or (v1.a=t2.a)) and
|
|
((v2.b<50) or (v2.b=19)) and (v1.max_c<300);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c < 300)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c < 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v2.b < 50) or (v2.b = 19))"
|
|
},
|
|
"buffer_type": "incremental",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v2.a = v1.a) or (v1.a = t2.a)) and ((v2.b < 50) or (v2.b = 19)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and ((t1.b < 50) or (t1.b = 19)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing only in one table
|
|
# conjunctive subformula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where
|
|
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
select * from v1,v2,t2 where
|
|
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
explain select * from v1,v2,t2 where
|
|
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key1 key1 10 test.t2.a,test.t2.a 2
|
|
1 PRIMARY <derived3> ref key0 key0 5 test.t2.a 2 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where
|
|
(v1.a=t2.a) and (v1.a=v1.b) and (v1.a=v2.a) and (v2.max_c<300);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key1"],
|
|
"key": "key1",
|
|
"key_length": "10",
|
|
"used_key_parts": ["a", "b"],
|
|
"ref": ["test.t2.a", "test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.b = t1.a)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.max_c < 300)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((max_c < 707) and (max_c < 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing only in one table
|
|
# extracted and formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into WHERE using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b);
|
|
a b max_c avg_c a b max_c avg_c a b c d
|
|
explain select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived3> ref key0 key0 5 v1.b 2
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,t2 where (v1.a=1) and (v1.b>10) and (v1.b=v2.b);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 1) and (v1.b > 10))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(v1.b is not null)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 1) and (t1.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v1.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into WHERE using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
|
|
a b max_c a b c
|
|
b Vika 2 b Ivan 1
|
|
b Vika 2 b Ali 6
|
|
b Vika 2 b Hermes 3
|
|
b Vika 2 b Ivan 11
|
|
b Vika 2 b Harry 4
|
|
select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
|
|
a b max_c a b c
|
|
b Vika 2 b Ivan 1
|
|
b Vika 2 b Ali 6
|
|
b Vika 2 b Hermes 3
|
|
b Vika 2 b Ivan 11
|
|
b Vika 2 b Harry 4
|
|
explain select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 Using where
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (t.a='b') and ((v.b='Vika') or (v.b='Ali'));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.a = 'b') and ((v.b = 'Vika') or (v.b = 'Ali')))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(max_c < 9)",
|
|
"filesort": {
|
|
"sort_key": "t1_char.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_char",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1_char.a = 'b') and ((t1_char.b = 'Vika') or (t1_char.b = 'Ali')))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "(t.a = 'b')"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL"
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing in all tables
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformulas : pushing into HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,v2,v3,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
|
|
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
|
|
a b max_c avg_c a b max_c avg_c a b min_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 7 11 708 7 13 312 406
|
|
6 20 315 279.3333 6 20 315 279.3333 8 33 114 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 214 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 8 33 114 8 80 800 314
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 214 6 23 303 909
|
|
6 20 315 279.3333 8 33 404 213.6667 6 20 214 6 20 315 279
|
|
6 20 315 279.3333 8 33 404 213.6667 6 20 214 6 23 303 909
|
|
8 33 404 213.6667 6 20 315 279.3333 8 33 114 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279.3333 8 33 114 8 80 800 314
|
|
8 33 404 213.6667 8 33 404 213.6667 7 11 708 7 13 312 406
|
|
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 64 248 107
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 80 800 314
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 23 303 909
|
|
select * from v1,v2,v3,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
|
|
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
|
|
a b max_c avg_c a b max_c avg_c a b min_c a b c d
|
|
6 20 315 279.3333 6 20 315 279.3333 7 11 708 7 13 312 406
|
|
6 20 315 279.3333 6 20 315 279.3333 8 33 114 8 64 248 107
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 214 6 20 315 279
|
|
6 20 315 279.3333 6 20 315 279.3333 8 33 114 8 80 800 314
|
|
6 20 315 279.3333 6 20 315 279.3333 6 20 214 6 23 303 909
|
|
6 20 315 279.3333 8 33 404 213.6667 6 20 214 6 20 315 279
|
|
6 20 315 279.3333 8 33 404 213.6667 6 20 214 6 23 303 909
|
|
8 33 404 213.6667 6 20 315 279.3333 8 33 114 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279.3333 8 33 114 8 80 800 314
|
|
8 33 404 213.6667 8 33 404 213.6667 7 11 708 7 13 312 406
|
|
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 64 248 107
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 20 315 279
|
|
8 33 404 213.6667 8 33 404 213.6667 8 33 114 8 80 800 314
|
|
8 33 404 213.6667 8 33 404 213.6667 6 20 214 6 23 303 909
|
|
explain select * from v1,v2,v3,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
|
|
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 test.t2.a 2 Using where
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (incremental, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
explain format=json select * from v1,v2,v3,t2 where
|
|
((v1.a=v2.a) or (v1.a=t2.a)) and ((v3.b<50) or (v3.b=33))
|
|
and (v1.max_c<500) and (v3.a=t2.a) and (v2.max_c>300);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v3.b < 50) or (v3.b = 33))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(min_c > 109)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.b < 50) or (t1.b = 33)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.max_c > 300)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((max_c < 707) and (max_c > 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c < 500)"
|
|
},
|
|
"buffer_type": "incremental",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a = v2.a) or (v1.a = t2.a))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c < 500))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing in all tables
|
|
# conjunctive subformulas : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
t2 where (v1.a=v2.a) and (v1.b=t2.b) and (v1.max_c>130) and (v2.min_c<130);
|
|
a b max_c avg_c a b min_c a b c d
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
t2 where (v1.a=v2.a) and (v1.b=t2.b) and (v1.max_c>130) and (v2.min_c<130);
|
|
a b max_c avg_c a b min_c a b c d
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
t2 where (v1.a=v2.a) and (v1.b=t2.b) and (v1.max_c>130) and (v2.min_c<130);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key1 key1 5 test.t2.b 2 Using where
|
|
1 PRIMARY <derived3> ref key0 key0 5 v1.a 2 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
t2 where (v1.a=v2.a) and (v1.b=t2.b) and (v1.max_c>130) and (v2.min_c<130);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key1"],
|
|
"key": "key1",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["test.t2.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 130) and (v1.a is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 130))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["v1.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.min_c < 130)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((min_c < 707) and (min_c < 130))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using several derived tables : pushing in all tables
|
|
# extracted or formulas : pushing into HAVING
|
|
# conjunctive subformula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
(select a, b, avg(c) as avg_c from t1
|
|
where t1.a<8 group by a,b) v3,
|
|
t2 where (v1.a=v2.a) and (v1.b=v3.b) and ((v3.avg_c>170) or (v3.a<5))
|
|
and ((v1.avg_c<400) or (v1.a>1)) and (v2.min_c<200);
|
|
a b max_c avg_c a b min_c a b avg_c a b c d
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 2 3 207 207
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 1 21 909 12
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 7 13 312 406
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 8 64 248 107
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 6 20 315 279
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 1 19 203 107
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 8 80 800 314
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 3 12 231 190
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 6 23 303 909
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
(select a, b, avg(c) as avg_c from t1
|
|
where t1.a<8 group by a,b) v3,
|
|
t2 where (v1.a=v2.a) and (v1.b=v3.b) and ((v3.avg_c>170) or (v3.a<5))
|
|
and ((v1.avg_c<400) or (v1.a>1)) and (v2.min_c<200);
|
|
a b max_c avg_c a b min_c a b avg_c a b c d
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 2 3 207 207
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 1 21 909 12
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 7 13 312 406
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 8 64 248 107
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 6 20 315 279
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 1 19 203 107
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 8 80 800 314
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 3 12 231 190
|
|
8 33 404 213.6667 8 33 114 1 33 497.5000 6 23 303 909
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
(select a, b, avg(c) as avg_c from t1
|
|
where t1.a<8 group by a,b) v3,
|
|
t2 where (v1.a=v2.a) and (v1.b=v3.b) and ((v3.avg_c>170) or (v3.a<5))
|
|
and ((v1.avg_c<400) or (v1.a>1)) and (v2.min_c<200);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived3> ref key0 key0 5 v1.a 2 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 v1.b 2 Using where
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
(select a, b, min(c) as min_c from t1
|
|
where t1.a>5 group by a,b having min_c < 707) v2,
|
|
(select a, b, avg(c) as avg_c from t1
|
|
where t1.a<8 group by a,b) v3,
|
|
t2 where (v1.a=v2.a) and (v1.b=v3.b) and ((v3.avg_c>170) or (v3.a<5))
|
|
and ((v1.avg_c<400) or (v1.a>1)) and (v2.min_c<200);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.avg_c < 400) or (v1.a > 1))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.avg_c < 400) or (v1.a > 1)) and (v1.a is not null) and (v1.b is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((avg_c < 400) or (t1.a > 1)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["v1.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.min_c < 200)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((min_c < 707) and (min_c < 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v1.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v3.avg_c > 170) or (v3.a < 5))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((avg_c > 170) or (t1.a < 5))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a < 8)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted or formula : pushing into HAVING
|
|
# conjunctive subformula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
|
|
a b max_c avg_c a b c d
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
5 27 132 132.0000 7 13 312 406
|
|
5 27 132 132.0000 8 64 248 107
|
|
5 27 132 132.0000 6 20 315 279
|
|
5 27 132 132.0000 1 19 203 107
|
|
5 27 132 132.0000 8 80 800 314
|
|
5 27 132 132.0000 3 12 231 190
|
|
5 27 132 132.0000 6 23 303 909
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
|
|
a b max_c avg_c a b c d
|
|
5 27 132 132.0000 2 3 207 207
|
|
5 27 132 132.0000 1 21 909 12
|
|
5 27 132 132.0000 7 13 312 406
|
|
5 27 132 132.0000 8 64 248 107
|
|
5 27 132 132.0000 6 20 315 279
|
|
5 27 132 132.0000 1 19 203 107
|
|
5 27 132 132.0000 8 80 800 314
|
|
5 27 132 132.0000 3 12 231 190
|
|
5 27 132 132.0000 6 23 303 909
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
group by a,b having max_c < 707) v1,
|
|
t2 where ((v1.a=1) or (v1.max_c<300)) and (v1.b>25);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a = 1) or (v1.max_c < 300)) and (v1.b > 25))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.a = 1) or (v1.max_c < 300))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and ((t1.a = 1) or (max_c < 300)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.b > 25)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# extracted and formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
|
|
a b max_c avg_c a b c d
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
explain select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 2 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from
|
|
(select a, b, max(c) as max_c, avg(c) as avg_c from t1
|
|
where t1.a>5 group by a,b having max_c < 707) v1,
|
|
t2 where (v1.a=t2.a) and (v1.max_c>300) and (v1.b<30);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 300) and (v1.b < 30))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 707) and (max_c > 300))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b < 30))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using query with union
|
|
# conjunctive subformula : pushing into WHERE
|
|
# conjunctive subformulas : pushing into HAVING and WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800)
|
|
union
|
|
select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800)
|
|
union
|
|
select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
|
|
a b max_c avg_c a b c d
|
|
1 21 500 234.6000 1 21 909 12
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800)
|
|
union
|
|
select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived3> ref key0 key0 5 test.t2.b 2 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 UNION t2 ALL NULL NULL NULL NULL 9 Using where
|
|
2 UNION <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (t2.c>800)
|
|
union
|
|
select * from v1,t2 where (v1.max_c>100) and (v1.a>7) and (t2.d>800);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union1,2>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.c > 800) and (t2.b is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["test.t2.b"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a < 5)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a < 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.d > 800)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 100) and (v1.a > 7))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and (max_c > 100))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 7)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
# using query with union
|
|
# extracted and formula : pushing into WHERE
|
|
# extracted or formula : pushing into HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
|
|
union
|
|
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 8 64 248 107
|
|
6 20 315 279.3333 8 80 800 314
|
|
select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
|
|
union
|
|
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 2 3 207 207
|
|
1 21 500 234.6000 7 13 312 406
|
|
1 21 500 234.6000 8 64 248 107
|
|
1 21 500 234.6000 6 20 315 279
|
|
1 21 500 234.6000 8 80 800 314
|
|
1 21 500 234.6000 3 12 231 190
|
|
1 21 500 234.6000 6 23 303 909
|
|
6 20 315 279.3333 7 13 312 406
|
|
6 20 315 279.3333 8 64 248 107
|
|
6 20 315 279.3333 8 80 800 314
|
|
explain select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
|
|
union
|
|
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 UNION t2 ALL NULL NULL NULL NULL 9
|
|
2 UNION <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v1,t2 where (v1.a<5) and (v1.b=t2.b) and (v1.b=19)
|
|
union
|
|
select * from v1,t2 where ((v1.max_c>400) or (v1.avg_c>270)) and (v1.a<t2.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union1,2>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b = 19)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.b = 19) and (v1.a < 5))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b = 19) and (t1.a < 5))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.max_c > 400) or (v1.avg_c > 270))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.max_c > 400) or (v1.avg_c > 270)) and (v1.a < t2.a))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and ((max_c > 400) or (avg_c > 270)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
# using query with union
|
|
# extracted or formula : pushing into HAVING
|
|
# extracted or formula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
|
|
union
|
|
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
select * from v1,t2 where
|
|
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
|
|
union
|
|
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
1 21 500 234.6000 1 21 909 12
|
|
1 21 500 234.6000 1 19 203 107
|
|
6 20 315 279.3333 6 20 315 279
|
|
6 20 315 279.3333 6 23 303 909
|
|
8 33 404 213.6667 2 3 207 207
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 7 13 312 406
|
|
8 33 404 213.6667 8 64 248 107
|
|
8 33 404 213.6667 6 20 315 279
|
|
8 33 404 213.6667 1 19 203 107
|
|
8 33 404 213.6667 8 80 800 314
|
|
8 33 404 213.6667 3 12 231 190
|
|
8 33 404 213.6667 6 23 303 909
|
|
explain select * from v1,t2 where
|
|
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
|
|
union
|
|
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 UNION t2 ALL NULL NULL NULL NULL 9
|
|
2 UNION <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v1,t2 where
|
|
((t2.a=v1.a) or (v1.b=t2.b)) and ((v1.a=1) or (v1.a=6))
|
|
union
|
|
select * from v1,t2 where ((v1.a>3) and (v1.b>27)) or (v1.max_c>550);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union1,2>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 1) or (v1.a = 6))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a = t2.a) or (v1.b = t2.b)) and ((v1.a = 1) or (v1.a = 6)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 1) or (t1.a = 6))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v1.a > 3) and (v1.b > 27)) or (v1.max_c > 550))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "(((v1.a > 3) and (v1.b > 27)) or (v1.max_c > 550))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and (((t1.a > 3) and (t1.b > 27)) or (max_c > 550)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
# using query with union
|
|
# extracted or formula : pushing into HAVING
|
|
# conjunctive subformulas : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v1,t2 where
|
|
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
|
|
union
|
|
select * from v2,t2 where
|
|
((v2.a<t2.b) or (v2.max_c>200)) and (v2.b>10) and (t2.a<2)
|
|
union
|
|
select * from v2,t2 where
|
|
(v2.max_c=t2.c) and (v2.b<10);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
6 20 315 279.3333 1 21 909 12
|
|
6 20 315 279.3333 1 19 203 107
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 1 19 203 107
|
|
select * from v1,t2 where
|
|
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
|
|
union
|
|
select * from v2,t2 where
|
|
((v2.a<t2.b) or (v2.max_c>200)) and (v2.b>10) and (t2.a<2)
|
|
union
|
|
select * from v2,t2 where
|
|
(v2.max_c=t2.c) and (v2.b<10);
|
|
a b max_c avg_c a b c d
|
|
1 19 107 107.0000 1 21 909 12
|
|
1 19 107 107.0000 1 19 203 107
|
|
6 20 315 279.3333 1 21 909 12
|
|
6 20 315 279.3333 1 19 203 107
|
|
8 33 404 213.6667 1 21 909 12
|
|
8 33 404 213.6667 1 19 203 107
|
|
explain select * from v1,t2 where
|
|
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
|
|
union
|
|
select * from v2,t2 where
|
|
((v2.a<t2.b) or (v2.max_c>200)) and (v2.b>10) and (t2.a<2)
|
|
union
|
|
select * from v2,t2 where
|
|
(v2.max_c=t2.c) and (v2.b<10);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 UNION t2 ALL NULL NULL NULL NULL 9 Using where
|
|
2 UNION <derived5> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
5 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t2 ALL NULL NULL NULL NULL 9 Using where
|
|
3 UNION <derived6> ref key0 key0 5 test.t2.c 2 Using where
|
|
6 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union1,2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v1,t2 where
|
|
((v1.a=1) and (v1.a=t2.a)) and ((v1.max_c<500) or (v1.avg_c>500))
|
|
union
|
|
select * from v2,t2 where
|
|
((v2.a<t2.b) or (v2.max_c>200)) and (v2.b>10) and (t2.a<2)
|
|
union
|
|
select * from v2,t2 where
|
|
(v2.max_c=t2.c) and (v2.b<10);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union1,2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 1)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a = 1) and ((v1.max_c < 500) or (v1.avg_c > 500)))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v1.max_c < 500) or (v1.avg_c > 500))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and ((max_c < 500) or (avg_c > 500)))",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a < 2)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived5>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.b > 10)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v2.a < t2.b) or (v2.max_c > 200))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 5,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.c is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived6>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["max_c"],
|
|
"ref": ["test.t2.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.b < 10)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 6,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b < 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union
|
|
# conjunctive subformulas : pushing into WHERE and HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,t2 where (v_union.a<3) and (v_union.c>100);
|
|
a b c a b c d
|
|
1 19 107 2 3 207 207
|
|
1 19 107 1 21 909 12
|
|
1 19 107 7 13 312 406
|
|
1 19 107 8 64 248 107
|
|
1 19 107 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 107 8 80 800 314
|
|
1 19 107 3 12 231 190
|
|
1 19 107 6 23 303 909
|
|
select * from v_union,t2 where (v_union.a<3) and (v_union.c>100);
|
|
a b c a b c d
|
|
1 19 107 2 3 207 207
|
|
1 19 107 1 21 909 12
|
|
1 19 107 7 13 312 406
|
|
1 19 107 8 64 248 107
|
|
1 19 107 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 107 8 80 800 314
|
|
1 19 107 3 12 231 190
|
|
1 19 107 6 23 303 909
|
|
explain select * from v_union,t2 where (v_union.a<3) and (v_union.c>100);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 40 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v_union,t2 where (v_union.a<3) and (v_union.c>100);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 40,
|
|
"filtered": 100,
|
|
"attached_condition": "((v_union.a < 3) and (v_union.c > 100))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((c > 109) and (c > 100))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and (t1.a < 3))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((c < 300) and (c > 100))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.a < 3))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union
|
|
# conjunctive subformula : pushing into WHERE
|
|
# extracted or formula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,t2 where
|
|
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
|
|
a b c a b c d
|
|
1 19 107 2 3 207 207
|
|
1 19 107 1 21 909 12
|
|
1 19 107 7 13 312 406
|
|
1 19 107 8 64 248 107
|
|
1 19 107 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 107 8 80 800 314
|
|
1 19 107 3 12 231 190
|
|
1 19 107 6 23 303 909
|
|
select * from v_union,t2 where
|
|
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
|
|
a b c a b c d
|
|
1 19 107 2 3 207 207
|
|
1 19 107 1 21 909 12
|
|
1 19 107 7 13 312 406
|
|
1 19 107 8 64 248 107
|
|
1 19 107 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 107 8 80 800 314
|
|
1 19 107 3 12 231 190
|
|
1 19 107 6 23 303 909
|
|
explain select * from v_union,t2 where
|
|
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 40 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v_union,t2 where
|
|
((v_union.a<2) or (v_union.c>800)) and (v_union.b>12);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 40,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v_union.a < 2) or (v_union.c > 800)) and (v_union.b > 12))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v_union.a < 2) or (v_union.c > 800))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((c > 109) and ((t1.a < 2) or (c > 800)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and (t1.b > 12))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((c < 300) and ((t1.a < 2) or (c > 800)))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.b > 12))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union
|
|
# conjunctive subformula : pushing into HAVING
|
|
# conjunctive subformula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,t2 where
|
|
(v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200);
|
|
a b c a b c d
|
|
1 19 107 1 21 909 12
|
|
1 19 107 1 19 203 107
|
|
select * from v_union,t2 where
|
|
(v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200);
|
|
a b c a b c d
|
|
1 19 107 1 21 909 12
|
|
1 19 107 1 19 203 107
|
|
explain select * from v_union,t2 where
|
|
(v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 40 Using where; Using join buffer (flat, BNL join)
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v_union,t2 where
|
|
(v_union.a=1) and (v_union.a=t2.a) and (v_union.c<200);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 1)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 40,
|
|
"filtered": 100,
|
|
"attached_condition": "((v_union.a = 1) and (v_union.c < 200))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((c > 109) and (c < 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((c < 300) and (c < 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 1) and (t1.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
|
|
a b max_c a b c
|
|
c Vika 7 c Vinny 3
|
|
c Vika 7 c Inga 9
|
|
c Vika 7 c Ivan 2
|
|
c Vika 7 c Inga 2
|
|
select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
|
|
a b max_c a b c
|
|
c Vika 7 c Vinny 3
|
|
c Vika 7 c Inga 9
|
|
c Vika 7 c Ivan 2
|
|
c Vika 7 c Inga 2
|
|
explain select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t ALL NULL NULL NULL NULL 12 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 2 test.t.a 2 Using where
|
|
2 DERIVED t1_char ALL NULL NULL NULL NULL 12 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v_char as v,t2_char as t where
|
|
(v.a=t.a) and (v.b='Vika') and (v.max_c>2);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "(t.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "2",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "((v.b = 'Vika') and (v.max_c > 2))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((max_c < 9) and (max_c > 2))",
|
|
"filesort": {
|
|
"sort_key": "t1_char.a",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1_char",
|
|
"access_type": "ALL",
|
|
"rows": 12,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1_char.b = 'Vika')"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union
|
|
# using several derived tables : pushing in all tables
|
|
# conjunctive subformula : pushing into WHERE using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v_union,v1,t2 where
|
|
(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
|
|
and ((v_union.c>800) or (v1.max_c>200));
|
|
a b c a b max_c avg_c a b c d
|
|
1 19 107 1 21 500 234.6000 1 21 909 12
|
|
1 19 107 1 21 500 234.6000 1 19 203 107
|
|
select * from v_union,v1,t2 where
|
|
(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
|
|
and ((v_union.c>800) or (v1.max_c>200));
|
|
a b c a b max_c avg_c a b c d
|
|
1 19 107 1 21 500 234.6000 1 21 909 12
|
|
1 19 107 1 21 500 234.6000 1 19 203 107
|
|
explain select * from v_union,v1,t2 where
|
|
(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
|
|
and ((v_union.c>800) or (v1.max_c>200));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 40 Using where; Using join buffer (incremental, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v_union,v1,t2 where
|
|
(v_union.a=v1.a) and (v1.a=t2.a) and (t2.a=1)
|
|
and ((v_union.c>800) or (v1.max_c>200));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a = 1)"
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a = 1)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 40,
|
|
"filtered": 100,
|
|
"attached_condition": "(v_union.a = 1)"
|
|
},
|
|
"buffer_type": "incremental",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((v_union.c > 800) or (v1.max_c > 200))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(c > 109)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(c < 300)",
|
|
"filesort": {
|
|
"sort_key": "t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a = 1) and (t1.b > 10))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v2_union as v,t2 where
|
|
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
|
|
a b c a b c d
|
|
8 33 404.0000 8 64 248 107
|
|
6 20 312.0000 6 20 315 279
|
|
6 20 214.0000 6 20 315 279
|
|
8 33 404.0000 8 80 800 314
|
|
6 20 312.0000 6 23 303 909
|
|
6 20 214.0000 6 23 303 909
|
|
select * from v2_union as v,t2 where
|
|
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
|
|
a b c a b c d
|
|
8 33 404.0000 8 64 248 107
|
|
6 20 312.0000 6 20 315 279
|
|
6 20 214.0000 6 20 315 279
|
|
8 33 404.0000 8 80 800 314
|
|
6 20 312.0000 6 23 303 909
|
|
6 20 214.0000 6 23 303 909
|
|
explain select * from v2_union as v,t2 where
|
|
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 6 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
4 UNION t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
NULL UNION RESULT <union2,3,4> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v2_union as v,t2 where
|
|
((v.a=6) or (v.a=8)) and (v.c>200) and (v.a=t2.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(((t2.a = 6) or (t2.a = 8)) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 6,
|
|
"filtered": 100,
|
|
"attached_condition": "(v.c > 200)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3,4>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((c > 109) and (c > 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.a = 6) or (t1.a = 8)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "((c < 300) and (c > 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and ((t1.a = 6) or (t1.a = 8)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((c < 707) and (c > 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.c > 300) and ((t1.a = 6) or (t1.a = 8)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union of selects without aggregation
|
|
# extracted conjunctive predicate: pushing in WHERE of both selects
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6);
|
|
a b c a b c d
|
|
1 21 123 1 21 909 12
|
|
1 21 101 1 21 909 12
|
|
1 21 104 1 21 909 12
|
|
1 33 988 1 21 909 12
|
|
1 19 107 1 21 909 12
|
|
1 21 500 1 21 909 12
|
|
1 21 345 1 21 909 12
|
|
7 11 708 7 13 312 406
|
|
7 11 8 7 13 312 406
|
|
8 33 404 8 64 248 107
|
|
8 33 123 8 64 248 107
|
|
8 33 114 8 64 248 107
|
|
8 33 9 8 64 248 107
|
|
6 20 214 6 20 315 279
|
|
6 20 315 6 20 315 279
|
|
6 20 309 6 20 315 279
|
|
6 20 7 6 20 315 279
|
|
1 21 123 1 19 203 107
|
|
1 21 101 1 19 203 107
|
|
1 21 104 1 19 203 107
|
|
1 33 988 1 19 203 107
|
|
1 19 107 1 19 203 107
|
|
1 21 500 1 19 203 107
|
|
1 21 345 1 19 203 107
|
|
8 33 404 8 80 800 314
|
|
8 33 123 8 80 800 314
|
|
8 33 114 8 80 800 314
|
|
8 33 9 8 80 800 314
|
|
6 20 214 6 23 303 909
|
|
6 20 315 6 23 303 909
|
|
6 20 309 6 23 303 909
|
|
6 20 7 6 23 303 909
|
|
select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6);
|
|
a b c a b c d
|
|
1 21 123 1 21 909 12
|
|
1 21 101 1 21 909 12
|
|
1 21 104 1 21 909 12
|
|
1 33 988 1 21 909 12
|
|
1 19 107 1 21 909 12
|
|
1 21 500 1 21 909 12
|
|
1 21 345 1 21 909 12
|
|
7 11 708 7 13 312 406
|
|
7 11 8 7 13 312 406
|
|
8 33 404 8 64 248 107
|
|
8 33 123 8 64 248 107
|
|
8 33 114 8 64 248 107
|
|
8 33 9 8 64 248 107
|
|
6 20 214 6 20 315 279
|
|
6 20 315 6 20 315 279
|
|
6 20 309 6 20 315 279
|
|
6 20 7 6 20 315 279
|
|
1 21 123 1 19 203 107
|
|
1 21 101 1 19 203 107
|
|
1 21 104 1 19 203 107
|
|
1 33 988 1 19 203 107
|
|
1 19 107 1 19 203 107
|
|
1 21 500 1 19 203 107
|
|
1 21 345 1 19 203 107
|
|
8 33 404 8 80 800 314
|
|
8 33 123 8 80 800 314
|
|
8 33 114 8 80 800 314
|
|
8 33 9 8 80 800 314
|
|
6 20 214 6 23 303 909
|
|
6 20 315 6 23 303 909
|
|
6 20 309 6 23 303 909
|
|
6 20 7 6 23 303 909
|
|
explain select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 4 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v3_union as v,t2 where (v.a=t2.a) and (v.c>6);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "(v.c > 6)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.a + 1) > 6))"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.c > 100) and (t1.c > 6))"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union of selects without aggregation
|
|
# extracted conjunctive OR subformula: pushing in WHERE using equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20));
|
|
a b c a b c d
|
|
1 19 107 1 21 909 12
|
|
1 19 2 1 21 909 12
|
|
7 11 708 7 13 312 406
|
|
7 11 8 7 13 312 406
|
|
8 33 404 8 64 248 107
|
|
8 33 123 8 64 248 107
|
|
8 33 114 8 64 248 107
|
|
8 33 9 8 64 248 107
|
|
6 20 214 6 20 315 279
|
|
6 20 315 6 20 315 279
|
|
6 20 309 6 20 315 279
|
|
6 20 7 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 2 1 19 203 107
|
|
8 33 404 8 80 800 314
|
|
8 33 123 8 80 800 314
|
|
8 33 114 8 80 800 314
|
|
8 33 9 8 80 800 314
|
|
6 20 214 6 23 303 909
|
|
6 20 315 6 23 303 909
|
|
6 20 309 6 23 303 909
|
|
6 20 7 6 23 303 909
|
|
select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20));
|
|
a b c a b c d
|
|
1 19 107 1 21 909 12
|
|
1 19 2 1 21 909 12
|
|
7 11 708 7 13 312 406
|
|
7 11 8 7 13 312 406
|
|
8 33 404 8 64 248 107
|
|
8 33 123 8 64 248 107
|
|
8 33 114 8 64 248 107
|
|
8 33 9 8 64 248 107
|
|
6 20 214 6 20 315 279
|
|
6 20 315 6 20 315 279
|
|
6 20 309 6 20 315 279
|
|
6 20 7 6 20 315 279
|
|
1 19 107 1 19 203 107
|
|
1 19 2 1 19 203 107
|
|
8 33 404 8 80 800 314
|
|
8 33 123 8 80 800 314
|
|
8 33 114 8 80 800 314
|
|
8 33 9 8 80 800 314
|
|
6 20 214 6 23 303 909
|
|
6 20 315 6 23 303 909
|
|
6 20 309 6 23 303 909
|
|
6 20 7 6 23 303 909
|
|
explain select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 4 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v3_union as v,t2 where (v.a=t2.a) and ((t2.a>1) or (v.b<20));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a > 1) or (v.b < 20))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.a > 1) or (t1.b < 20)))"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.c > 100) and ((t1.a > 1) or (t1.b < 20)))"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union of selects without aggregation
|
|
# extracted the whole condition: in WHERE of both selects
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v3_union as v,t2 where
|
|
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
|
|
a b c a b c d
|
|
1 19 2 1 21 909 12
|
|
1 21 2 1 21 909 12
|
|
1 19 2 1 19 203 107
|
|
1 21 2 1 19 203 107
|
|
select * from v3_union as v,t2 where
|
|
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
|
|
a b c a b c d
|
|
1 19 2 1 21 909 12
|
|
1 21 2 1 21 909 12
|
|
1 19 2 1 19 203 107
|
|
1 21 2 1 19 203 107
|
|
explain select * from v3_union as v,t2 where
|
|
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 4 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v3_union as v,t2 where
|
|
(v.a=t2.a) and ((v.b=19) or (v.b=21)) and ((v.c<3) or (v.c>600));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v.b = 19) or (v.b = 21)) and ((v.c < 3) or (v.c > 600)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.b = 19) or (t1.b = 21)) and (((t1.a + 1) < 3) or ((t1.a + 1) > 600)))"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.c > 100) and ((t1.b = 19) or (t1.b = 21)) and ((t1.c < 3) or (t1.c > 600)))"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union of
|
|
# a select without aggregation and a select with aggregation
|
|
# extracted conjunctive predicate: pushing in WHERE of both selects
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
|
|
a b c a b c d
|
|
1 19 207 1 21 909 12
|
|
7 11 808 7 13 312 406
|
|
7 11 608 7 13 312 406
|
|
1 19 207 1 19 203 107
|
|
select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
|
|
a b c a b c d
|
|
1 19 207 1 21 909 12
|
|
7 11 808 7 13 312 406
|
|
7 11 608 7 13 312 406
|
|
1 19 207 1 19 203 107
|
|
explain select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 4 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v4_union as v,t2 where (v.a=t2.a) and (v.b<20);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "(v.b < 20)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(c > 109)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and (t1.b < 20))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and (t1.b < 20))"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using derived table with union of
|
|
# a select without aggregation and a select with aggregation
|
|
# extracted subformula: pushing in WHERE of one select
|
|
# extracted subformula: pushing in HAVING of the other select
|
|
# extracted sub-subformula: pushing in WHERE of the other select
|
|
# using an equality in all pushdowns
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4_union as v,t2 where
|
|
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
|
|
a b c a b c d
|
|
1 33 1088 1 21 909 12
|
|
1 21 600 1 21 909 12
|
|
1 33 888 1 21 909 12
|
|
7 11 808 7 13 312 406
|
|
7 11 608 7 13 312 406
|
|
8 33 504 8 64 248 107
|
|
1 33 1088 1 19 203 107
|
|
1 21 600 1 19 203 107
|
|
1 33 888 1 19 203 107
|
|
8 33 504 8 80 800 314
|
|
select * from v4_union as v,t2 where
|
|
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
|
|
a b c a b c d
|
|
1 33 1088 1 21 909 12
|
|
1 21 600 1 21 909 12
|
|
1 33 888 1 21 909 12
|
|
7 11 808 7 13 312 406
|
|
7 11 608 7 13 312 406
|
|
8 33 504 8 64 248 107
|
|
1 33 1088 1 19 203 107
|
|
1 21 600 1 19 203 107
|
|
1 33 888 1 19 203 107
|
|
8 33 504 8 80 800 314
|
|
explain select * from v4_union as v,t2 where
|
|
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.a 4 Using where
|
|
2 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 UNION t1 ALL NULL NULL NULL NULL 20 Using where
|
|
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
|
|
explain format=json select * from v4_union as v,t2 where
|
|
(v.a=t2.a) and ((t2.a<3) or (v.b<40)) and (v.c>500);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.a is not null)"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "(((t2.a < 3) or (v.b < 40)) and (v.c > 500))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"union_result": {
|
|
"table_name": "<union2,3>",
|
|
"access_type": "ALL",
|
|
"query_specifications": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "((c > 109) and (c > 500))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 10) and ((t1.a < 3) or (t1.b < 40)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b > 10) and ((t1.a < 3) or (t1.b < 40)) and ((t1.c + 100) > 500))"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded derived table : pushing the same conditions
|
|
# using several derived tables : pushing in all tables
|
|
# conjunctive subformula : pushing into WHERE
|
|
# extracted and formula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v1 where
|
|
(v4.a<13) and (v1.a>5) and (v1.b>12);
|
|
a b min_c a b max_c avg_c
|
|
1 19 107 6 20 315 279.3333
|
|
1 21 500 6 20 315 279.3333
|
|
5 16 207 6 20 315 279.3333
|
|
5 27 132 6 20 315 279.3333
|
|
6 20 315 6 20 315 279.3333
|
|
8 33 404 6 20 315 279.3333
|
|
1 19 107 8 33 404 213.6667
|
|
1 21 500 8 33 404 213.6667
|
|
5 16 207 8 33 404 213.6667
|
|
5 27 132 8 33 404 213.6667
|
|
6 20 315 8 33 404 213.6667
|
|
8 33 404 8 33 404 213.6667
|
|
select * from v4,v1 where
|
|
(v4.a<13) and (v1.a>5) and (v1.b>12);
|
|
a b min_c a b max_c avg_c
|
|
1 19 107 6 20 315 279.3333
|
|
1 21 500 6 20 315 279.3333
|
|
5 16 207 6 20 315 279.3333
|
|
5 27 132 6 20 315 279.3333
|
|
6 20 315 6 20 315 279.3333
|
|
8 33 404 6 20 315 279.3333
|
|
1 19 107 8 33 404 213.6667
|
|
1 21 500 8 33 404 213.6667
|
|
5 16 207 8 33 404 213.6667
|
|
5 27 132 8 33 404 213.6667
|
|
6 20 315 8 33 404 213.6667
|
|
8 33 404 8 33 404 213.6667
|
|
explain select * from v4,v1 where
|
|
(v4.a<13) and (v1.a>5) and (v1.b>12);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v1 where
|
|
(v4.a<13) and (v1.a>5) and (v1.b>12);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v4.a < 13)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and (v1.a < 13))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and (t1.a < 13))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a > 5) and (v1.b > 12))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b > 12))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : nothing to push
|
|
# using several derived tables : pushing only in one table
|
|
# conjunctive subformula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30);
|
|
a b min_c a b max_c avg_c a b c d
|
|
8 33 404 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 8 33 404 213.6667 8 80 800 314
|
|
select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30);
|
|
a b min_c a b max_c avg_c a b c d
|
|
8 33 404 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 8 33 404 213.6667 8 80 800 314
|
|
explain select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key1 key1 5 test.t2.a 2
|
|
1 PRIMARY <derived4> ref key0 key0 5 test.t2.a 2 Using where
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a=v1.a) and (v1.b>30);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key1"],
|
|
"key": "key1",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a < 15)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a < 15)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.b > 30)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.b > 30)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing different conditions
|
|
# using several derived tables : pushing in all tables
|
|
# conjunctive subformula : pushing into WHERE using equalities
|
|
# extracted and formula : pushing into WHERE using equalities
|
|
# conjunctive subformula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
|
|
a b min_c a b max_c avg_c a b c d
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 6 20 315 279.3333 6 23 303 909
|
|
select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
|
|
a b min_c a b max_c avg_c a b c d
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 6 20 315 279.3333 6 23 303 909
|
|
explain select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key1 key1 5 test.t2.a 2 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 test.t2.a 2 Using where
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v1,t2 where
|
|
(v4.a=t2.a) and (v4.a>1) and (v4.a=v1.a) and (v4.min_c>100) and (v1.b<30);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.a > 1) and (t2.a is not null) and (t2.a is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key1"],
|
|
"key": "key1",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v4.min_c > 100)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(min_c > 100)",
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and (v1.a > 1))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and (t1.a > 1))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["test.t2.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.b < 30)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 1) and (t1.b < 30))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing different conditions
|
|
# using several derived tables : pushing in all tables
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v1,t2 where
|
|
(((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a);
|
|
a b min_c a b max_c avg_c a b c d
|
|
1 19 107 1 21 500 234.6000 2 3 207 207
|
|
1 19 107 1 21 500 234.6000 1 21 909 12
|
|
1 19 107 1 21 500 234.6000 7 13 312 406
|
|
1 19 107 1 21 500 234.6000 8 64 248 107
|
|
1 19 107 1 21 500 234.6000 6 20 315 279
|
|
1 19 107 1 21 500 234.6000 1 19 203 107
|
|
1 19 107 1 21 500 234.6000 8 80 800 314
|
|
1 19 107 1 21 500 234.6000 3 12 231 190
|
|
1 19 107 1 21 500 234.6000 6 23 303 909
|
|
5 16 207 5 16 207 207.0000 2 3 207 207
|
|
5 16 207 5 16 207 207.0000 1 21 909 12
|
|
5 16 207 5 16 207 207.0000 7 13 312 406
|
|
5 16 207 5 16 207 207.0000 8 64 248 107
|
|
5 16 207 5 16 207 207.0000 6 20 315 279
|
|
5 16 207 5 16 207 207.0000 1 19 203 107
|
|
5 16 207 5 16 207 207.0000 8 80 800 314
|
|
5 16 207 5 16 207 207.0000 3 12 231 190
|
|
5 16 207 5 16 207 207.0000 6 23 303 909
|
|
5 27 132 5 16 207 207.0000 2 3 207 207
|
|
5 27 132 5 16 207 207.0000 1 21 909 12
|
|
5 27 132 5 16 207 207.0000 7 13 312 406
|
|
5 27 132 5 16 207 207.0000 8 64 248 107
|
|
5 27 132 5 16 207 207.0000 6 20 315 279
|
|
5 27 132 5 16 207 207.0000 1 19 203 107
|
|
5 27 132 5 16 207 207.0000 8 80 800 314
|
|
5 27 132 5 16 207 207.0000 3 12 231 190
|
|
5 27 132 5 16 207 207.0000 6 23 303 909
|
|
6 20 315 6 20 315 279.3333 2 3 207 207
|
|
6 20 315 6 20 315 279.3333 1 21 909 12
|
|
6 20 315 6 20 315 279.3333 7 13 312 406
|
|
6 20 315 6 20 315 279.3333 8 64 248 107
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 6 20 315 279.3333 1 19 203 107
|
|
6 20 315 6 20 315 279.3333 8 80 800 314
|
|
6 20 315 6 20 315 279.3333 3 12 231 190
|
|
6 20 315 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 8 33 404 213.6667 2 3 207 207
|
|
8 33 404 8 33 404 213.6667 1 21 909 12
|
|
8 33 404 8 33 404 213.6667 7 13 312 406
|
|
8 33 404 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 8 33 404 213.6667 6 20 315 279
|
|
8 33 404 8 33 404 213.6667 1 19 203 107
|
|
8 33 404 8 33 404 213.6667 8 80 800 314
|
|
8 33 404 8 33 404 213.6667 3 12 231 190
|
|
8 33 404 8 33 404 213.6667 6 23 303 909
|
|
select * from v4,v1,t2 where
|
|
(((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a);
|
|
a b min_c a b max_c avg_c a b c d
|
|
1 19 107 1 21 500 234.6000 2 3 207 207
|
|
1 19 107 1 21 500 234.6000 1 21 909 12
|
|
1 19 107 1 21 500 234.6000 7 13 312 406
|
|
1 19 107 1 21 500 234.6000 8 64 248 107
|
|
1 19 107 1 21 500 234.6000 6 20 315 279
|
|
1 19 107 1 21 500 234.6000 1 19 203 107
|
|
1 19 107 1 21 500 234.6000 8 80 800 314
|
|
1 19 107 1 21 500 234.6000 3 12 231 190
|
|
1 19 107 1 21 500 234.6000 6 23 303 909
|
|
5 16 207 5 16 207 207.0000 2 3 207 207
|
|
5 16 207 5 16 207 207.0000 1 21 909 12
|
|
5 16 207 5 16 207 207.0000 7 13 312 406
|
|
5 16 207 5 16 207 207.0000 8 64 248 107
|
|
5 16 207 5 16 207 207.0000 6 20 315 279
|
|
5 16 207 5 16 207 207.0000 1 19 203 107
|
|
5 16 207 5 16 207 207.0000 8 80 800 314
|
|
5 16 207 5 16 207 207.0000 3 12 231 190
|
|
5 16 207 5 16 207 207.0000 6 23 303 909
|
|
5 27 132 5 16 207 207.0000 2 3 207 207
|
|
5 27 132 5 16 207 207.0000 1 21 909 12
|
|
5 27 132 5 16 207 207.0000 7 13 312 406
|
|
5 27 132 5 16 207 207.0000 8 64 248 107
|
|
5 27 132 5 16 207 207.0000 6 20 315 279
|
|
5 27 132 5 16 207 207.0000 1 19 203 107
|
|
5 27 132 5 16 207 207.0000 8 80 800 314
|
|
5 27 132 5 16 207 207.0000 3 12 231 190
|
|
5 27 132 5 16 207 207.0000 6 23 303 909
|
|
6 20 315 6 20 315 279.3333 2 3 207 207
|
|
6 20 315 6 20 315 279.3333 1 21 909 12
|
|
6 20 315 6 20 315 279.3333 7 13 312 406
|
|
6 20 315 6 20 315 279.3333 8 64 248 107
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 6 20 315 279.3333 1 19 203 107
|
|
6 20 315 6 20 315 279.3333 8 80 800 314
|
|
6 20 315 6 20 315 279.3333 3 12 231 190
|
|
6 20 315 6 20 315 279.3333 6 23 303 909
|
|
8 33 404 8 33 404 213.6667 2 3 207 207
|
|
8 33 404 8 33 404 213.6667 1 21 909 12
|
|
8 33 404 8 33 404 213.6667 7 13 312 406
|
|
8 33 404 8 33 404 213.6667 8 64 248 107
|
|
8 33 404 8 33 404 213.6667 6 20 315 279
|
|
8 33 404 8 33 404 213.6667 1 19 203 107
|
|
8 33 404 8 33 404 213.6667 8 80 800 314
|
|
8 33 404 8 33 404 213.6667 3 12 231 190
|
|
8 33 404 8 33 404 213.6667 6 23 303 909
|
|
explain select * from v4,v1,t2 where
|
|
(((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where; Using join buffer (flat, BNL join)
|
|
1 PRIMARY <derived4> ref key0 key0 5 v4.a 2 Using where
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v1,t2 where
|
|
(((v4.b>10) and (v4.a>1)) or (v4.b<20)) and (v1.max_c>200) and (v1.a=v4.a);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v4.b > 10) and (v4.a > 1)) or (v4.b < 20))"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"attached_condition": "((((v4.b > 10) and (v4.a > 1)) or (v4.b < 20)) and (v4.a is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and (((v1.b > 10) and (v1.a > 1)) or (v1.b < 20)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and (((t1.b > 10) and (t1.a > 1)) or (t1.b < 20)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["a"],
|
|
"ref": ["v4.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.max_c > 200)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and (max_c > 200))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing different conditions
|
|
# using several derived tables : pushing only in one table
|
|
# extracted or formula : pushing into WHERE
|
|
# extracted or formula : pushing into HAVING
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
|
|
((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1);
|
|
a b min_c a b max_c avg_c
|
|
select * from v4,v2 where
|
|
((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1);
|
|
a b min_c a b max_c avg_c
|
|
explain select * from v4,v2 where
|
|
((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2 where
|
|
((v4.a>12) and (v4.min_c<300) and (v4.b>13)) or (v4.a<1);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v4.a > 12) and (v4.min_c < 300) and (v4.b > 13)) or (v4.a < 1))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(((v1.a > 12) and (min_c < 300) and (v1.b > 13)) or (v1.a < 1))",
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and (((v1.a > 12) and (v1.b > 13)) or (v1.a < 1)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and (((t1.a > 12) and (t1.b > 13)) or (t1.a < 1)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing different conditions
|
|
# using several derived tables : pushing only in one table
|
|
# conjunctive subformula : pushing into WHERE
|
|
# conjunctive subformula : pushing into HAVING
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
|
|
a b min_c a b max_c avg_c
|
|
select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
|
|
a b min_c a b max_c avg_c
|
|
explain select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 v4.a 2
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v4.min_c<100);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v4.b = v4.a) and (v4.min_c < 100) and (v4.a is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(min_c < 100)",
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.b = v1.a) and (v1.a < 15))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b = t1.a) and (t1.a < 15))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v4.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing the same conditions
|
|
# using several derived tables : pushing in all tables
|
|
# extracted and formula : pushing into WHERE using equalities
|
|
# conjunctive subformula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
|
|
a b min_c a b max_c avg_c
|
|
select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
|
|
a b min_c a b max_c avg_c
|
|
explain select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 v4.a 2
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and (v2.b<30);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v4.b = v4.a) and (v4.a < 30) and (v4.a is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.b = v1.a) and (v1.a < 15) and (v1.a < 30))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b = t1.a) and (t1.a < 15) and (t1.a < 30))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v4.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and (t1.b < 30))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing the same conditions
|
|
# using several derived tables : pushing in all tables
|
|
# extracted or formula : pushing into WHERE using equalities
|
|
# extracted and formula : pushing into WHERE using equalities
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2));
|
|
a b min_c a b max_c avg_c
|
|
select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2));
|
|
a b min_c a b max_c avg_c
|
|
explain select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 v4.a 2
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2 where
|
|
(v4.a=v2.b) and (v4.a=v4.b) and ((v2.b<30) or (v4.a>2));
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v4.b = v4.a) and ((v4.a < 30) or (v4.a > 2)) and (v4.a is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.b = v1.a) and (v1.a < 15) and ((v1.a < 30) or (v1.a > 2)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.b = t1.a) and (t1.a < 15) and ((t1.a < 30) or (t1.a > 2)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["v4.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a > 5) and ((t1.b < 30) or (t1.b > 2)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing the same conditions
|
|
# using several derived tables : pushing in all tables
|
|
# extracted or formula : pushing into WHERE
|
|
# conjunctive subformula : pushing into WHERE
|
|
# pushing equalities
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2 where
|
|
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=v2.max_c) and (v4.min_c>100);
|
|
a b min_c a b max_c avg_c
|
|
6 20 315 6 20 315 279.3333
|
|
8 33 404 8 33 404 213.6667
|
|
select * from v4,v2 where
|
|
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=v2.max_c) and (v4.min_c>100);
|
|
a b min_c a b max_c avg_c
|
|
6 20 315 6 20 315 279.3333
|
|
8 33 404 8 33 404 213.6667
|
|
explain select * from v4,v2 where
|
|
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=v2.max_c) and (v4.min_c>100);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 20 Using where
|
|
1 PRIMARY <derived4> ref key0 key0 5 v4.min_c 2
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2 where
|
|
(((v4.a<12) and (v4.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=v2.max_c) and (v4.min_c>100);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((((v4.a < 12) and (v4.b > 13)) or (v4.a > 10)) and (v4.min_c > 100) and (v4.min_c is not null))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(min_c > 100)",
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and (((v1.a < 12) and (v1.b > 13)) or (v1.a > 10)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and (((t1.a < 12) and (t1.b > 13)) or (t1.a > 10)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["max_c"],
|
|
"ref": ["v4.min_c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "((max_c < 707) and (max_c > 100))",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
# using embedded view : pushing the same conditions
|
|
# using several derived tables : pushing only in one table
|
|
# extracted or formula : pushing into WHERE
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for select * from v4,v2,t2 where
|
|
(((v4.a<12) and (t2.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=t2.c) and (t2.c>100);
|
|
a b min_c a b max_c avg_c a b c d
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 8 33 404 213.6667 6 20 315 279
|
|
select * from v4,v2,t2 where
|
|
(((v4.a<12) and (t2.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=t2.c) and (t2.c>100);
|
|
a b min_c a b max_c avg_c a b c d
|
|
6 20 315 6 20 315 279.3333 6 20 315 279
|
|
6 20 315 8 33 404 213.6667 6 20 315 279
|
|
explain select * from v4,v2,t2 where
|
|
(((v4.a<12) and (t2.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=t2.c) and (t2.c>100);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where
|
|
1 PRIMARY <derived2> ref key0 key0 5 test.t2.c 2 Using where
|
|
1 PRIMARY <derived4> ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join)
|
|
4 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
2 DERIVED <derived3> ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 20 Using where; Using temporary; Using filesort
|
|
explain format=json select * from v4,v2,t2 where
|
|
(((v4.a<12) and (t2.b>13)) or (v4.a>10)) and
|
|
(v4.min_c=t2.c) and (t2.c>100);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 9,
|
|
"filtered": 100,
|
|
"attached_condition": "((t2.c > 100) and (t2.c is not null))"
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["min_c"],
|
|
"ref": ["test.t2.c"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(((v4.a < 12) and (t2.b > 13)) or (v4.a > 10))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"having_condition": "(min_c > 100)",
|
|
"filesort": {
|
|
"sort_key": "v1.a, v1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((v1.a < 15) and ((v1.a < 12) or (v1.a > 10)))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "((t1.a < 15) and ((t1.a < 12) or (t1.a > 10)))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"having_condition": "(max_c < 707)",
|
|
"filesort": {
|
|
"sort_key": "t1.a, t1.b",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 20,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a > 5)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
drop view v1,v2,v3,v4;
|
|
drop view v_union,v2_union,v3_union,v4_union;
|
|
drop view v_double,v_char,v_decimal;
|
|
drop table t1,t2,t1_double,t2_double,t1_char,t2_char,t1_decimal,t2_decimal;
|
|
#
|
|
# MDEV-10782: condition extracted from a multiple equality
|
|
# pushed into HAVING
|
|
#
|
|
CREATE TABLE t1 (i int);
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
EXPLAIN EXTENDED
|
|
SELECT *
|
|
FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
|
|
WHERE f = 8;
|
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
|
1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using where
|
|
3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00
|
|
Warnings:
|
|
Note 1003 select `sq1`.`f` AS `f` from (select min(`test`.`t1`.`i`) AS `f` from `test`.`t1` having (`f` = 8)) `sq1` where (`sq1`.`f` = 8)
|
|
SELECT *
|
|
FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
|
|
WHERE f = 8;
|
|
f
|
|
SELECT *
|
|
FROM ( SELECT * FROM ( SELECT MIN(i) as f FROM t1 ) sq1 ) AS sq2
|
|
WHERE f = 1;
|
|
f
|
|
1
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-10783: pushdown into constant view
|
|
#
|
|
CREATE TABLE t1 (i int) ENGINE=MyISAM;
|
|
CREATE VIEW v AS SELECT 5;
|
|
SELECT * FROM t1 WHERE 1 IN ( SELECT * FROM v );
|
|
i
|
|
DROP VIEW v;
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-10785: second execution of a query with condition
|
|
# pushed into view
|
|
#
|
|
CREATE TABLE t1 (i int);
|
|
CREATE VIEW v1 AS SELECT i FROM t1 WHERE i < 5;
|
|
CREATE FUNCTION f (in1 int) RETURNS int RETURN in1;
|
|
CREATE VIEW v2 AS SELECT * FROM v1 GROUP BY i;
|
|
PREPARE stmt FROM "SELECT * FROM v2 WHERE f(0) <> 2";
|
|
EXECUTE stmt;
|
|
i
|
|
EXECUTE stmt;
|
|
i
|
|
DROP FUNCTION f;
|
|
DROP VIEW v2,v1;
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-10884: condition pushdown into derived specified by
|
|
# 1. unit with SELECT containing ORDER BY ... LIMIT
|
|
# 2. unit containing global ORDER BY ... LIMIT
|
|
#
|
|
create table t1(a int);
|
|
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
select a from t1 order by a limit 5;
|
|
a
|
|
0
|
|
1
|
|
2
|
|
3
|
|
4
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for
|
|
select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
|
|
a
|
|
0
|
|
4
|
|
set statement optimizer_switch='condition_pushdown_for_derived=on' for
|
|
select * from (select a from t1 order by a limit 5) t where t.a not in (1,2,3);
|
|
a
|
|
0
|
|
4
|
|
select a from t1 where a < 4 union select a from t1 where a > 5
|
|
order by a limit 5;
|
|
a
|
|
0
|
|
1
|
|
2
|
|
3
|
|
6
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for
|
|
select * from
|
|
(select a from t1 where a < 4 union select a from t1 where a > 5
|
|
order by a limit 5) t where t.a not in (2,9);
|
|
a
|
|
0
|
|
1
|
|
3
|
|
6
|
|
set statement optimizer_switch='condition_pushdown_for_derived=on' for
|
|
select * from
|
|
(select a from t1 where a < 4 union select a from t1 where a > 5
|
|
order by a limit 5) t where t.a not in (2,9);
|
|
a
|
|
0
|
|
1
|
|
3
|
|
6
|
|
drop table t1;
|
|
#
|
|
# MDEV-11072: pushdown of the condition obtained
|
|
# after constant row substitution
|
|
#
|
|
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
|
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
|
CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
|
|
CREATE TABLE t3 (c INT) ENGINE=MyISAM;
|
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3;
|
|
SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT c FROM v3 WHERE c = a
|
|
)
|
|
);
|
|
a
|
|
INSERT INTO t1 VALUES (2);
|
|
INSERT INTO t2 VALUES (3), (2);
|
|
INSERT INTO t3 VALUES (4), (1), (2), (7);
|
|
SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT c FROM v3 WHERE c = a
|
|
)
|
|
);
|
|
a
|
|
2
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT c FROM v3 WHERE c = a
|
|
)
|
|
);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"const_condition": "(0 or <in_optimizer>(2,<exists>(subquery#3)))",
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100
|
|
},
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b = 2)",
|
|
"first_match": "t1"
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "<derived5>",
|
|
"access_type": "index_subquery",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["c"],
|
|
"ref": ["func"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 5,
|
|
"table": {
|
|
"table_name": "t3",
|
|
"access_type": "ALL",
|
|
"rows": 4,
|
|
"filtered": 100,
|
|
"attached_condition": "(t3.c = 2)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
CREATE TABLE t4 (d INT, e INT) ENGINE=MyISAM;
|
|
INSERT INTO t4 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
|
|
CREATE OR REPLACE VIEW v4 AS
|
|
SELECT d, sum(e) AS s FROM t4 GROUP BY d;
|
|
set statement optimizer_switch='condition_pushdown_for_derived=off' for SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT d FROM v4 WHERE s > a
|
|
)
|
|
);
|
|
a
|
|
2
|
|
SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT d FROM v4 WHERE s > a
|
|
)
|
|
);
|
|
a
|
|
2
|
|
explain SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT d FROM v4 WHERE s > a
|
|
)
|
|
);
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t1 system NULL NULL NULL NULL 1
|
|
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1)
|
|
3 DEPENDENT SUBQUERY <derived5> index_subquery key0 key0 5 func 2 Using where
|
|
5 DERIVED t4 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
|
|
explain format=json SELECT * FROM t1 WHERE a IN (
|
|
SELECT b FROM v2 WHERE b < a OR b IN (
|
|
SELECT d FROM v4 WHERE s > a
|
|
)
|
|
);
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"const_condition": "(0 or <in_optimizer>(2,<exists>(subquery#3)))",
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100
|
|
},
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b = 2)",
|
|
"first_match": "t1"
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "<derived5>",
|
|
"access_type": "index_subquery",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["d"],
|
|
"ref": ["func"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 5,
|
|
"filesort": {
|
|
"sort_key": "t4.d",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t4",
|
|
"access_type": "ALL",
|
|
"rows": 5,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
DROP VIEW v2,v3,v4;
|
|
DROP TABLE t1,t2,t3,t4;
|
|
#
|
|
# MDEV-10800: pushdown of the condition obtained
|
|
# after constant row substitution
|
|
#
|
|
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
|
INSERT INTO t1 VALUES (1);
|
|
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
|
INSERT INTO t2 VALUES (3),(4);
|
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
|
|
SELECT * FROM
|
|
( SELECT * FROM t1
|
|
WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
|
|
a
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM
|
|
( SELECT * FROM t1
|
|
WHERE EXISTS ( SELECT * FROM v2 WHERE b = a ) ) AS sq;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"const_condition": "<in_optimizer>(1,exists(subquery#3))",
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.b = 1)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t2.b = 1)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
DROP VIEW v2;
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# MDEV-11102: condition pushdown into materialized inner table
|
|
# of outer join is not applied as not being valid
|
|
#
|
|
CREATE TABLE t1 (a INT);
|
|
INSERT INTO t1 VALUES (0),(2);
|
|
CREATE TABLE t2 (b INT);
|
|
INSERT INTO t2 VALUES (1),(2);
|
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
|
|
SELECT * FROM t1 LEFT JOIN t2 ON a = b WHERE b IS NULL;
|
|
a b
|
|
0 NULL
|
|
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
|
|
a b
|
|
0 NULL
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM t1 LEFT JOIN v2 ON a = b WHERE b IS NULL;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100
|
|
},
|
|
"table": {
|
|
"table_name": "<derived2>",
|
|
"access_type": "ref",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "5",
|
|
"used_key_parts": ["b"],
|
|
"ref": ["test.t1.a"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(trigcond(isnull(v2.b)) and trigcond(trigcond((t1.a is not null))))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DROP VIEW v2;
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# MDEV-11103: pushdown condition with ANY subquery
|
|
#
|
|
CREATE TABLE t1 (i INT);
|
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "<nop>((v1.i <= 3))",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "<nop>((t1.i <= 3))"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Warnings:
|
|
Note 1249 Select 2 was reduced during optimization
|
|
SELECT * FROM v1 WHERE i <= ANY ( SELECT 3 );
|
|
i
|
|
1
|
|
2
|
|
DROP VIEW v1;
|
|
DROP TABLE t1;
|
|
#
|
|
# MDEV-11315: condition with outer reference to mergeable derived
|
|
#
|
|
CREATE TABLE t1 (pk1 INT PRIMARY KEY, a INT, b INT) ENGINE=MyISAM;
|
|
INSERT INTO t1 VALUES (10,7,1),(11,0,2);
|
|
CREATE TABLE t2 (pk2 INT PRIMARY KEY, c INT, d DATETIME) ENGINE=MyISAM;
|
|
INSERT INTO t2 VALUES
|
|
(1,4,'2008-09-27 00:34:58'),
|
|
(2,5,'2007-05-28 00:00:00'),
|
|
(3,6,'2009-07-25 09:21:20');
|
|
CREATE VIEW v1 AS SELECT * FROM t1;
|
|
CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t2;
|
|
SELECT * FROM v1 AS sq
|
|
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
|
|
pk1 a b
|
|
10 7 1
|
|
11 0 2
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM v1 AS sq
|
|
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(<in_optimizer>(t1.b,<exists>(subquery#2)) or (t1.b = 100))"
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "index_subquery",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "4",
|
|
"used_key_parts": ["pk2"],
|
|
"ref": ["func"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 3,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
SELECT * FROM ( SELECT * FROM t1 ) AS sq
|
|
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
|
|
pk1 a b
|
|
10 7 1
|
|
11 0 2
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM ( SELECT * FROM t1 ) AS sq
|
|
WHERE b IN ( SELECT pk2 FROM v2 WHERE c > sq.b ) OR b = 100;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(<in_optimizer>(t1.b,<exists>(subquery#3)) or (t1.b = 100))"
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "index_subquery",
|
|
"possible_keys": ["key0"],
|
|
"key": "key0",
|
|
"key_length": "4",
|
|
"used_key_parts": ["pk2"],
|
|
"ref": ["func"],
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "ALL",
|
|
"rows": 3,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
DROP VIEW v1,v2;
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# MDEV-11313: pushdown of the condition obtained
|
|
# after constant row substitution
|
|
#
|
|
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
|
INSERT INTO t1 VALUES (1),(2);
|
|
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
|
INSERT INTO t2 VALUES (50);
|
|
CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
|
|
SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
|
|
f
|
|
0
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT ( SELECT COUNT(*) FROM v1 WHERE a = t2.b ) AS f FROM t2 GROUP BY f;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.a = 50)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.a = 50)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
CREATE TABLE t3 (a INT, b INT) ENGINE=MYISAM;
|
|
INSERT INTO t3 VALUES (1,10),(3,11),(2,10),(2,20),(3,21);
|
|
CREATE VIEW v2 AS SELECT a, sum(b) AS s FROM t3 GROUP BY a ;
|
|
SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
|
|
f
|
|
3
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT ( SELECT COUNT(*) FROM v2 WHERE s < t2.b ) AS f FROM t2 GROUP BY f;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "t2",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100
|
|
},
|
|
"subqueries": [
|
|
{
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 5,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.s < 50)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"filesort": {
|
|
"sort_key": "t3.a",
|
|
"temporary_table": {
|
|
"table": {
|
|
"table_name": "t3",
|
|
"access_type": "ALL",
|
|
"rows": 5,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
DROP VIEW v1,v2;
|
|
DROP TABLE t1,t2,t3;
|
|
#
|
|
# MDEV-10882: pushdown of the predicate with cached value
|
|
#
|
|
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL) ENGINE=MyISAM;
|
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1;
|
|
INSERT INTO t1 VALUES (1,2),(3,4);
|
|
CREATE TABLE t2 (c INT NOT NULL) ENGINE=MyISAM;
|
|
INSERT INTO t2 VALUES (5),(6);
|
|
SELECT a, GROUP_CONCAT(b) FROM v1
|
|
WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
|
|
a GROUP_CONCAT(b)
|
|
1 2
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT a, GROUP_CONCAT(b) FROM v1
|
|
WHERE b IN ( SELECT COUNT(c) FROM t2 ) GROUP BY a;
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<subquery2>",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"unique": 1,
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"message": "Select tables optimized away"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"read_sorted_file": {
|
|
"filesort": {
|
|
"sort_key": "v1.a",
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.b = 2)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t1",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t1.b = 2)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DROP VIEW v1;
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# MDEV-10836: pushdown of the predicate with cached value
|
|
#
|
|
CREATE TABLE t (pk INT PRIMARY KEY, f INT) ENGINE=MyISAM;
|
|
CREATE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t;
|
|
INSERT INTO t VALUES (1,1),(3,2);
|
|
SELECT * FROM v AS v1, v AS v2
|
|
WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
|
|
pk f pk f
|
|
3 2 3 2
|
|
EXPLAIN FORMAT=JSON
|
|
SELECT * FROM v AS v1, v AS v2
|
|
WHERE v2.pk > v1.f AND v1.f IN ( SELECT COUNT(pk) FROM t );
|
|
EXPLAIN
|
|
{
|
|
"query_block": {
|
|
"select_id": 1,
|
|
"table": {
|
|
"table_name": "<subquery2>",
|
|
"access_type": "system",
|
|
"rows": 1,
|
|
"filtered": 100,
|
|
"materialized": {
|
|
"unique": 1,
|
|
"query_block": {
|
|
"select_id": 2,
|
|
"table": {
|
|
"message": "Select tables optimized away"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"table": {
|
|
"table_name": "<derived3>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v1.f = 2)",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 3,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(t.f = 2)"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
"block-nl-join": {
|
|
"table": {
|
|
"table_name": "<derived4>",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100,
|
|
"attached_condition": "(v2.pk > 2)"
|
|
},
|
|
"buffer_type": "flat",
|
|
"buffer_size": "256Kb",
|
|
"join_type": "BNL",
|
|
"materialized": {
|
|
"query_block": {
|
|
"select_id": 4,
|
|
"table": {
|
|
"table_name": "t",
|
|
"access_type": "ALL",
|
|
"rows": 2,
|
|
"filtered": 100
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
DROP VIEW v;
|
|
DROP TABLE t;
|