Skip to content

Commit 9bef428

Browse files
MDEV-36106 New-style hints: [NO_]DERIVED_CONDITION_PUSHDOWN, [NO_]MERGE
Implements and tests the optimizer hints DERIVED_CONDITION_PUSHDOWN and NO_DERIVED_CONDITION_PUSHDOWN, table-level hints to enable and disable, respectively, the condition pushdown for derived tables which is typically controlled by the condition_pushdown_for_derived optimizer switch. Implements and tests the optimizer hints MERGE and NO_MERGE, table-level hints to enable and disable, respectively, the derived_merge optimization which is typically controlled by the derived_merge optimizer switch. Sometimes hints need to be fixed before TABLE instances are available, but after TABLE_LIST instances have been created (as in the cases of MERGE and NO_MERGE). This commit introduces code to fix such hints provisionally, allowing them to be fully fixed later, after their corresponding TABLE instances have been created.
1 parent 5a6a8fa commit 9bef428

11 files changed

+2243
-42
lines changed

mysql-test/main/mdev-36106-derived-condition-pushdown-hint.result

+1,276
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
--source include/have_sequence.inc
2+
--disable_ps_protocol
3+
--disable_view_protocol
4+
create table t1 (a int, b int, c int);
5+
create table t2 (a int, b int, c int, d decimal);
6+
insert into t1 values
7+
(1,21,345), (1,33,7), (8,33,114), (1,21,500), (1,19,107), (5,14,787),
8+
(8,33,123), (9,10,211), (5,16,207), (1,33,988), (5,27,132), (1,21,104),
9+
(6,20,309), (6,20,315), (1,21,101), (8,33,404), (9,10,800), (1,21,123),
10+
(7,11,708), (6,20,214);
11+
create index t1_a on t1 (a);
12+
insert into t2 values
13+
(2,3,207,207.0000), (1,21,909,12.0000), (7,13,312,406.0000),
14+
(8,64,248,107.0000), (6,20,315,279.3333), (1,19,203,107.0000),
15+
(8,80,800,314.0000), (3,12,231,190.0000), (6,23,303,909.0000);
16+
create view v1 as select a, b, max(c) as max_c, avg(c) as avg_c from t1
17+
group by a,b having max_c < 707;
18+
create table t3 select 2*seq as a, 2*seq+1 as b from seq_0_to_1000;
19+
CREATE TABLE t4 (a INT, b INT);
20+
INSERT INTO t4 VALUES (1,2),(2,3),(3,4);
21+
create table t5 select seq as i, 10*seq as j from seq_1_to_10;
22+
create view v2 as select * from t5;
23+
24+
set @save_optimizer_switch=@@optimizer_switch;
25+
26+
set session optimizer_switch='condition_pushdown_for_derived=on';
27+
28+
--source include/explain-no-costs.inc
29+
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
30+
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
31+
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
32+
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
33+
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
34+
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
35+
36+
--source include/explain-no-costs.inc
37+
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
38+
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
39+
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
40+
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
41+
42+
--source include/explain-no-costs.inc
43+
explain format=json select * from (
44+
select t3.b as a from t3 group by t3.a
45+
) dt join (
46+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
47+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
48+
select count(*) from (
49+
select t3.b as a from t3 group by t3.a
50+
) dt join (
51+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
52+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
53+
54+
--source include/explain-no-costs.inc
55+
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ * from (
56+
select t3.b as a from t3 group by t3.a
57+
) dt join (
58+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
59+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
60+
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt)*/ count(*) from (
61+
select t3.b as a from t3 group by t3.a
62+
) dt join (
63+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
64+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
65+
66+
--source include/explain-no-costs.inc
67+
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(du)*/ * from (
68+
select t3.b as a from t3 group by t3.a
69+
) dt join (
70+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
71+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
72+
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(du)*/ count(*) from (
73+
select t3.b as a from t3 group by t3.a
74+
) dt join (
75+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
76+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
77+
78+
--source include/explain-no-costs.inc
79+
explain format=json select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt,du)*/ * from (
80+
select t3.b as a from t3 group by t3.a
81+
) dt join (
82+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
83+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
84+
select /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt,du)*/ count(*) from (
85+
select t3.b as a from t3 group by t3.a
86+
) dt join (
87+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
88+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
89+
90+
--source include/explain-no-costs.inc
91+
explain format=json SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
92+
SELECT t4.b AS a
93+
FROM t4
94+
GROUP BY t4.a
95+
) dt WHERE (dt.a=2);
96+
SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
97+
SELECT t4.b AS a
98+
FROM t4
99+
GROUP BY t4.a
100+
) dt WHERE (dt.a=2);
101+
102+
--source include/explain-no-costs.inc
103+
explain format=json SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
104+
SELECT qb.b AS a
105+
FROM (
106+
select 1*t4.b as b, 1*t4.a as a from t4
107+
) qb
108+
GROUP BY qb.a
109+
) dt WHERE (dt.a=2);
110+
SELECT /*+ NO_DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
111+
SELECT qb.b AS a
112+
FROM (
113+
select 1*t4.b as b, 1*t4.a as a from t4
114+
) qb
115+
GROUP BY qb.a
116+
) dt WHERE (dt.a=2);
117+
118+
set session optimizer_switch='condition_pushdown_for_derived=off';
119+
120+
--source include/explain-no-costs.inc
121+
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
122+
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
123+
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
124+
select /*+ DERIVED_CONDITION_PUSHDOWN(v1) */ * from v1,t2 where
125+
((v1.max_c>300) and (v1.avg_c>t2.d) and (v1.b=t2.b)) or
126+
((v1.max_c<135) and (v1.max_c<t2.c) and (v1.a=t2.a));
127+
128+
--source include/explain-no-costs.inc
129+
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
130+
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
131+
select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from
132+
(select t3.b as a from t3 group by t3.a) dt where (dt.a=3 or dt.a=5);
133+
134+
--source include/explain-no-costs.inc
135+
explain format=json SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
136+
SELECT t4.b AS a
137+
FROM t4
138+
GROUP BY t4.a
139+
) dt WHERE (dt.a=2);
140+
SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
141+
SELECT t4.b AS a
142+
FROM t4
143+
GROUP BY t4.a
144+
) dt WHERE (dt.a=2);
145+
146+
--source include/explain-no-costs.inc
147+
explain format=json SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
148+
SELECT qb.b AS a
149+
FROM (
150+
select 1*t4.b as b, 1*t4.a as a from t4
151+
) qb
152+
GROUP BY qb.a
153+
) dt WHERE (dt.a=2);
154+
SELECT /*+ DERIVED_CONDITION_PUSHDOWN(dt) */ * FROM (
155+
SELECT qb.b AS a
156+
FROM (
157+
select 1*t4.b as b, 1*t4.a as a from t4
158+
) qb
159+
GROUP BY qb.a
160+
) dt WHERE (dt.a=2);
161+
162+
--source include/explain-no-costs.inc
163+
explain format=json select * from (
164+
select t3.b as a from t3 group by t3.a
165+
) dt join (
166+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
167+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
168+
select count(*) from (
169+
select t3.b as a from t3 group by t3.a
170+
) dt join (
171+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
172+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
173+
174+
--source include/explain-no-costs.inc
175+
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ * from (
176+
select t3.b as a from t3 group by t3.a
177+
) dt join (
178+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
179+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
180+
select /*+ DERIVED_CONDITION_PUSHDOWN(dt)*/ count(*) from (
181+
select t3.b as a from t3 group by t3.a
182+
) dt join (
183+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
184+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
185+
186+
--source include/explain-no-costs.inc
187+
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(du)*/ * from (
188+
select t3.b as a from t3 group by t3.a
189+
) dt join (
190+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
191+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
192+
select /*+ DERIVED_CONDITION_PUSHDOWN(du)*/ count(*) from (
193+
select t3.b as a from t3 group by t3.a
194+
) dt join (
195+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
196+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
197+
198+
--source include/explain-no-costs.inc
199+
explain format=json select /*+ DERIVED_CONDITION_PUSHDOWN(dt,du)*/ * from (
200+
select t3.b as a from t3 group by t3.a
201+
) dt join (
202+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
203+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
204+
select /*+ DERIVED_CONDITION_PUSHDOWN(dt,du)*/ count(*) from (
205+
select t3.b as a from t3 group by t3.a
206+
) dt join (
207+
select t3.a as a, t3.b as b from t3 where t3.a % 2 = 0 group by t3.b
208+
) du where (dt.a=3 or dt.a=5) and (du.a % 10 <> 0 or du.a % 5 <> 0);
209+
210+
set optimizer_switch=@save_optimizer_switch;
211+
drop view v1, v2;
212+
drop table t1, t2, t3, t4, t5;
213+
--enable_view_protocol
214+
--enable_ps_protocol

0 commit comments

Comments
 (0)