1--source include/have_tokudb.inc
2SET DEFAULT_STORAGE_ENGINE='tokudb';
3#
4# Bug #22169: Crash with count(distinct)
5#
6--echo *** Bug #22169 ***
7
8--disable_warnings
9DROP TABLE IF EXISTS z1;
10--enable_warnings
11
12create table z1 (a int, b int, c int, d int, e int, primary key (c,d), clustering key (a,b));
13
14insert 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);
15insert 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);
16
17
18
19#let $1 = 2048;
20#SET @a=1;
21#while ($1)
22#{
23#  insert into z1 values (@a * -100, @a*-200, @a*-300, @a*-400, @a*-500);
24#  dec $1;
25#  SET @a = @a+1;
26#}
27
28
29
30select * from z1 group by a,b;
31
32
33explain select a,b from z1 where a < 1;
34select max(a) from z1 where a < 1;
35
36explain select a,b from z1 where a < 9;
37select max(a) from z1 where a < 9;
38
39explain select a,b from z1 where a < 7;
40select max(a) from z1 where a < 7;
41
42explain select a,b from z1 where a < 3;
43select max(a) from z1 where a < 3;
44
45explain select max(b) from z1 where a = 1;
46select max(b) from z1 where a = 1;
47
48explain select max(b) from z1 where a = 3;
49select max(b) from z1 where a = 3;
50
51explain select max(b) from z1 where a = 9;
52select max(b) from z1 where a = 9;
53
54DROP TABLE z1;
55