Skip to content

Commit 261d552

Browse files
MDEV-34413 Index Condition Pushdown for reverse-ordered scans
Adds tests which show that ICP was not enabled for reverse-ordered scans prior to this mdev. A later commit for this same mdev records again these same tests, showing that ICP for reverse-ordered scans is enabled and working.
1 parent c3f2176 commit 261d552

File tree

5 files changed

+555
-0
lines changed

5 files changed

+555
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[myisam]
2+
default-storage-engine=myisam
3+
4+
[innodb]
5+
innodb
6+
default-storage-engine=innodb
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
create table ten(a int);
2+
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3+
create table one_k(a int);
4+
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
5+
create table t10 (a int, b int, c int, key(a,b));
6+
insert into t10 select a,a,a from one_k;
7+
select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a desc, b desc;
8+
a b c
9+
20 20 20
10+
19 19 19
11+
18 18 18
12+
17 17 17
13+
16 16 16
14+
15 15 15
15+
14 14 14
16+
13 13 13
17+
12 12 12
18+
11 11 11
19+
10 10 10
20+
explain select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a desc, b desc;
21+
id select_type table type possible_keys key key_len ref rows Extra
22+
1 SIMPLE t10 range a a 5 NULL 11 Using where
23+
flush status;
24+
select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a desc, b desc;
25+
a b c
26+
20 20 20
27+
19 19 19
28+
18 18 18
29+
17 17 17
30+
16 16 16
31+
15 15 15
32+
14 14 14
33+
13 13 13
34+
12 12 12
35+
11 11 11
36+
10 10 10
37+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
38+
VARIABLE_NAME VARIABLE_VALUE
39+
HANDLER_ICP_ATTEMPTS 0
40+
HANDLER_ICP_MATCH 0
41+
select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a asc, b asc;
42+
a b c
43+
10 10 10
44+
11 11 11
45+
12 12 12
46+
13 13 13
47+
14 14 14
48+
15 15 15
49+
16 16 16
50+
17 17 17
51+
18 18 18
52+
19 19 19
53+
20 20 20
54+
explain select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a asc, b asc;
55+
id select_type table type possible_keys key key_len ref rows Extra
56+
1 SIMPLE t10 range a a 5 NULL 11 Using index condition
57+
flush status;
58+
select * from t10 force index(a) where a between 10 and 20 and b+1 <3333 order by a asc, b asc;
59+
a b c
60+
10 10 10
61+
11 11 11
62+
12 12 12
63+
13 13 13
64+
14 14 14
65+
15 15 15
66+
16 16 16
67+
17 17 17
68+
18 18 18
69+
19 19 19
70+
20 20 20
71+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
72+
VARIABLE_NAME VARIABLE_VALUE
73+
HANDLER_ICP_ATTEMPTS 11
74+
HANDLER_ICP_MATCH 11
75+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b desc;
76+
a b c
77+
10 10 10
78+
explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b desc;
79+
id select_type table type possible_keys key key_len ref rows Extra
80+
1 SIMPLE t10 ref a a 5 const 1 Using where
81+
flush status;
82+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b desc;
83+
a b c
84+
10 10 10
85+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
86+
VARIABLE_NAME VARIABLE_VALUE
87+
HANDLER_ICP_ATTEMPTS 0
88+
HANDLER_ICP_MATCH 0
89+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b asc;
90+
a b c
91+
10 10 10
92+
explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b asc;
93+
id select_type table type possible_keys key key_len ref rows Extra
94+
1 SIMPLE t10 ref a a 5 const 1 Using index condition; Using where
95+
flush status;
96+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b asc;
97+
a b c
98+
10 10 10
99+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
100+
VARIABLE_NAME VARIABLE_VALUE
101+
HANDLER_ICP_ATTEMPTS 1
102+
HANDLER_ICP_MATCH 1
103+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b desc;
104+
a b c
105+
10 10 10
106+
explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b desc;
107+
id select_type table type possible_keys key key_len ref rows Extra
108+
1 SIMPLE t10 ref a a 5 const 1 Using where
109+
flush status;
110+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b desc;
111+
a b c
112+
10 10 10
113+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
114+
VARIABLE_NAME VARIABLE_VALUE
115+
HANDLER_ICP_ATTEMPTS 0
116+
HANDLER_ICP_MATCH 0
117+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b asc;
118+
a b c
119+
10 10 10
120+
explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b asc;
121+
id select_type table type possible_keys key key_len ref rows Extra
122+
1 SIMPLE t10 ref a a 5 const 1 Using index condition; Using where
123+
flush status;
124+
select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b asc;
125+
a b c
126+
10 10 10
127+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
128+
VARIABLE_NAME VARIABLE_VALUE
129+
HANDLER_ICP_ATTEMPTS 1
130+
HANDLER_ICP_MATCH 1
131+
create table t1 (a int, b int, c int, key(a,b));
132+
insert into t1 (a, b, c) values (1,10,100),(2,20,200),(3,30,300),(4,40,400),(5,50,500),(6,60,600),(7,70,700),(8,80,800),(9,90,900),(10,100,1000);
133+
select * from t1 where a >= 3 and a <= 3 order by a desc, b desc;
134+
a b c
135+
3 30 300
136+
explain select * from t1 where a >= 3 and a <= 3 order by a desc, b desc;
137+
id select_type table type possible_keys key key_len ref rows Extra
138+
1 SIMPLE t1 range a a 5 NULL 1 Using where
139+
flush status;
140+
select * from t1 where a >= 3 and a <= 3 order by a desc, b desc;
141+
a b c
142+
3 30 300
143+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
144+
VARIABLE_NAME VARIABLE_VALUE
145+
HANDLER_ICP_ATTEMPTS 0
146+
HANDLER_ICP_MATCH 0
147+
select * from t1 where a >= 3 and a <= 3 order by a asc, b asc;
148+
a b c
149+
3 30 300
150+
explain select * from t1 where a >= 3 and a <= 3 order by a asc, b asc;
151+
id select_type table type possible_keys key key_len ref rows Extra
152+
1 SIMPLE t1 range a a 5 NULL 1 Using index condition
153+
flush status;
154+
select * from t1 where a >= 3 and a <= 3 order by a asc, b asc;
155+
a b c
156+
3 30 300
157+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
158+
VARIABLE_NAME VARIABLE_VALUE
159+
HANDLER_ICP_ATTEMPTS 1
160+
HANDLER_ICP_MATCH 1
161+
drop table t1;
162+
create table t1 (a int, b int, c int, key(a,b));
163+
insert into t1 (a, b, c) values (1,10,100),(2,20,200),(3,30,300);
164+
select * from t1 where a >= 2 and a <= 2 order by a desc, b desc;
165+
a b c
166+
2 20 200
167+
explain select * from t1 where a >= 2 and a <= 2 order by a desc, b desc;
168+
id select_type table type possible_keys key key_len ref rows Extra
169+
1 SIMPLE t1 range a a 5 NULL 1 Using where
170+
flush status;
171+
select * from t1 where a >= 2 and a <= 2 order by a desc, b desc;
172+
a b c
173+
2 20 200
174+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
175+
VARIABLE_NAME VARIABLE_VALUE
176+
HANDLER_ICP_ATTEMPTS 0
177+
HANDLER_ICP_MATCH 0
178+
select * from t1 where a >= 2 and a <= 2 order by a asc, b asc;
179+
a b c
180+
2 20 200
181+
explain select * from t1 where a >= 2 and a <= 2 order by a asc, b asc;
182+
id select_type table type possible_keys key key_len ref rows Extra
183+
1 SIMPLE t1 range a a 5 NULL 1 Using index condition
184+
flush status;
185+
select * from t1 where a >= 2 and a <= 2 order by a asc, b asc;
186+
a b c
187+
2 20 200
188+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
189+
VARIABLE_NAME VARIABLE_VALUE
190+
HANDLER_ICP_ATTEMPTS 1
191+
HANDLER_ICP_MATCH 1
192+
drop table ten, one_k, t10, t1;
193+
create table t1 (
194+
a int not null,
195+
b int not null,
196+
c int not null,
197+
key (a,b)
198+
) partition by range ((a)) (
199+
partition p0 values less than (5),
200+
partition p1 values less than (10),
201+
partition p2 values less than (15),
202+
partition p3 values less than (20)
203+
);
204+
insert into t1 (a,b,c) values (1,1,1),(2,2,2),(3,3,3),
205+
(4,4,4),(5,5,5),(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10),
206+
(11,11,11),(12,12,12),(13,13,13),(14,14,14),(15,15,15),
207+
(16,16,16),(17,17,17),(18,18,18),(19,19,19);
208+
select * from t1 where a >= 3 and a <= 7 order by a desc;
209+
a b c
210+
7 7 7
211+
6 6 6
212+
5 5 5
213+
4 4 4
214+
3 3 3
215+
explain select * from t1 where a >= 3 and a <= 7 order by a desc;
216+
id select_type table type possible_keys key key_len ref rows Extra
217+
1 SIMPLE t1 range a a 4 NULL 5 Using where
218+
flush status;
219+
select * from t1 where a >= 3 and a <= 7 order by a desc;
220+
a b c
221+
7 7 7
222+
6 6 6
223+
5 5 5
224+
4 4 4
225+
3 3 3
226+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
227+
VARIABLE_NAME VARIABLE_VALUE
228+
HANDLER_ICP_ATTEMPTS 0
229+
HANDLER_ICP_MATCH 0
230+
select * from t1 where a >= 3 and a <= 7 order by a desc, b desc;
231+
a b c
232+
7 7 7
233+
6 6 6
234+
5 5 5
235+
4 4 4
236+
3 3 3
237+
explain select * from t1 where a >= 3 and a <= 7 order by a desc, b desc;
238+
id select_type table type possible_keys key key_len ref rows Extra
239+
1 SIMPLE t1 range a a 4 NULL 5 Using where
240+
flush status;
241+
select * from t1 where a >= 3 and a <= 7 order by a desc, b desc;
242+
a b c
243+
7 7 7
244+
6 6 6
245+
5 5 5
246+
4 4 4
247+
3 3 3
248+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
249+
VARIABLE_NAME VARIABLE_VALUE
250+
HANDLER_ICP_ATTEMPTS 0
251+
HANDLER_ICP_MATCH 0
252+
drop table t1;
253+
create table t1 (
254+
pk int primary key,
255+
kp1 int, kp2 int,
256+
col1 int,
257+
index (kp1,kp2)
258+
) partition by hash (pk) partitions 10;
259+
insert into t1 select seq, seq, seq, seq from seq_1_to_1000;
260+
select * from t1 where kp1 between 950 and 960 and kp2+1 >33333 order by kp1 asc, kp2 asc;
261+
pk kp1 kp2 col1
262+
flush status;
263+
select * from t1 where kp1 between 950 and 960 and kp2+1 >33333 order by kp1 asc, kp2 asc;
264+
pk kp1 kp2 col1
265+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
266+
VARIABLE_NAME VARIABLE_VALUE
267+
HANDLER_ICP_ATTEMPTS 11
268+
HANDLER_ICP_MATCH 0
269+
select * from t1 where kp1 between 950 and 960 and kp2+1 >33333 order by kp1 desc, kp2 desc;
270+
pk kp1 kp2 col1
271+
flush status;
272+
select * from t1 where kp1 between 950 and 960 and kp2+1 >33333 order by kp1 desc, kp2 desc;
273+
pk kp1 kp2 col1
274+
SELECT * FROM information_schema.SESSION_STATUS WHERE VARIABLE_NAME LIKE '%icp%';
275+
VARIABLE_NAME VARIABLE_VALUE
276+
HANDLER_ICP_ATTEMPTS 0
277+
HANDLER_ICP_MATCH 0
278+
drop table t1;

0 commit comments

Comments
 (0)