14
14
drop table if exists t1;
17
create TEMPORARY table t1 (
18
18
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
21
21
insert into t1 (a1, a2, b, c, d) values
22
22
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
64
64
drop table if exists t2;
67
create TEMPORARY table t2 (
68
68
a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
70
70
insert into t2 select * from t1;
71
71
# add few rows with NULL's in the MIN/MAX column
72
72
insert into t2 (a1, a2, b, c, d) values
101
101
drop table if exists t3;
102
102
--enable_warnings
104
create TEMPORARY table t3 (
105
105
a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
108
108
insert into t3 (a1, a2, b, c, d) values
109
109
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
371
371
select a1,a2,b, max(c) from t1 where (c > 'b1') group by a1,a2,b;
372
select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b;
372
#select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b;
373
373
select a1,a2,b, max(c) from t1 where (c > 'f123') group by a1,a2,b;
374
select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b;
374
#select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b;
375
375
select a1,a2,b, max(c) from t1 where (c < 'a0') group by a1,a2,b;
376
376
select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b;
377
377
select a1,a2,b, max(c) from t1 where (c < 'k321') group by a1,a2,b;
378
378
select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b;
379
379
select a1,a2,b, max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
380
select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
380
#select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
381
381
select a1,a2,b, max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
382
382
select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
383
383
select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b;
439
439
select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
440
select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b;
441
select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;
440
#select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b;
441
#select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;
442
442
select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b;
443
443
select a1,a2,b,min(c) from t1 where ((a1 > 'a') or (a1 < '9')) and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b;
444
444
select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
523
523
# BUG #8532 - SELECT DISTINCT a, a causes server to crash
524
524
select distinct a1,a1 from t1;
525
525
select distinct a2,a1,a2,a1 from t1;
526
select distinct t1.a1,t2.a1 from t1,t2;
527
select distinct t1.a1,t2.a1 from t1,t2 where t1.a1 >= '';
689
690
# Bug #14920 Ordering aggregated result sets with composite primary keys
690
691
# corrupts resultset
692
create table t1 (c1 int not null,c2 int not null, primary key(c1,c2));
693
create TEMPORARY table t1 (c1 int not null,c2 int not null, primary key(c1,c2)) ENGINE=MYISAM;
693
694
insert into t1 (c1,c2) values
694
695
(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9);
695
696
select distinct c1, c2 from t1 order by c2;
702
703
# returns impossible range
705
CREATE TABLE t1 (a varchar(5), b int(11), PRIMARY KEY (a,b));
706
CREATE TABLE t1 (a varchar(5), b int, PRIMARY KEY (a,b));
706
707
INSERT INTO t1 VALUES ('AA',1), ('AA',2), ('AA',3), ('BB',1), ('AA',4);
708
ALTER TABLE t1 ENGINE="DEFAULT";
709
710
SELECT a FROM t1 WHERE a='AA' GROUP BY a;
710
711
SELECT a FROM t1 WHERE a='BB' GROUP BY a;
904
905
SELECT a, MIN(b), MAX(b), AVG(b) FROM t1 GROUP BY a ORDER BY a DESC;
910
# Bug #309547 key_infix_len can be overwritten causing some group by
911
# queries return no rows
913
CREATE TABLE t1 (a int, b int, c int, d int,
914
KEY foo (c,d,a,b), KEY bar (c,a,b,d));
916
INSERT INTO t1 VALUES (1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 1, 3), (1, 1, 1, 4);
917
INSERT INTO t1 SELECT * FROM t1;
918
INSERT INTO t1 SELECT * FROM t1;
919
INSERT INTO t1 SELECT a,b,c+1,d FROM t1;
922
EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4;
923
SELECT DISTINCT c FROM t1 WHERE d=4;