1SET DEFAULT_STORAGE_ENGINE='tokudb';
2*** Bug #22169 ***
3DROP TABLE IF EXISTS z1;
4create table z1 (a int, b int, c int, d int, e int, primary key (c,d), key (a,b) clustering=yes);
5insert into z1 values (1,1,1,1,1), (1,2,3,4,5), (3,4,1,100,1),(3,4,1,2,3),(3,5,1,21,1),(7,8,4,2,6),(9,10,34,3,2);
6insert into z1 values (-1,-1,-1,-1,-1), (-1,-2,-3,-4,-5), (-3,-4,-1,-100,-1),(-3,-4,-1,-2,-3),(-3,-5,-1,-21,-1),(-7,-8,-4,-2,-6),(-9,-10,-34,-3,-2);
7select * from z1 group by a,b;
8a	b	c	d	e
9-9	-10	-34	-3	-2
10-7	-8	-4	-2	-6
11-3	-5	-1	-21	-1
12-3	-4	-1	-100	-1
13-1	-2	-3	-4	-5
14-1	-1	-1	-1	-1
151	1	1	1	1
161	2	3	4	5
173	4	1	2	3
183	5	1	21	1
197	8	4	2	6
209	10	34	3	2
21explain select a,b from z1 where a < 1;
22id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
231	SIMPLE	z1	range	a	a	5	NULL	7	Using where; Using index
24select max(a) from z1 where a < 1;
25max(a)
26-1
27explain select a,b from z1 where a < 9;
28id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
291	SIMPLE	z1	index	a	a	10	NULL	14	Using where; Using index
30select max(a) from z1 where a < 9;
31max(a)
327
33explain select a,b from z1 where a < 7;
34id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
351	SIMPLE	z1	range	a	a	5	NULL	12	Using where; Using index
36select max(a) from z1 where a < 7;
37max(a)
383
39explain select a,b from z1 where a < 3;
40id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
411	SIMPLE	z1	range	a	a	5	NULL	9	Using where; Using index
42select max(a) from z1 where a < 3;
43max(a)
441
45explain select max(b) from z1 where a = 1;
46id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
471	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
48select max(b) from z1 where a = 1;
49max(b)
502
51explain select max(b) from z1 where a = 3;
52id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
531	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
54select max(b) from z1 where a = 3;
55max(b)
565
57explain select max(b) from z1 where a = 9;
58id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
591	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
60select max(b) from z1 where a = 9;
61max(b)
6210
63DROP TABLE z1;
64