1# 2# Test of group functions that depend on innodb 3# 4 5--source include/have_innodb.inc 6 7--disable_warnings 8create table t1 (USR_ID integer not null, MAX_REQ integer not null, constraint PK_SEA_USER primary key (USR_ID)) engine=InnoDB; 9--enable_warnings 10insert into t1 values (1, 3); 11select count(*) + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ from t1 group by MAX_REQ; 12select Case When Count(*) < MAX_REQ Then 1 Else 0 End from t1 where t1.USR_ID = 1 group by MAX_REQ; 13drop table t1; 14 15 16# 17# Bug #12882 min/max inconsistent on empty table 18# 19 20--disable_warnings 21create table t1m (a int) engine=myisam; 22create table t1i (a int) engine=innodb; 23create table t2m (a int) engine=myisam; 24create table t2i (a int) engine=innodb; 25--enable_warnings 26insert into t2m values (5); 27insert into t2i values (5); 28 29# test with MyISAM 30select min(a) from t1m; 31select min(7) from t1m; 32select min(7) from DUAL; 33explain select min(7) from t2m join t1m; 34select min(7) from t2m join t1m; 35 36select max(a) from t1m; 37select max(7) from t1m; 38select max(7) from DUAL; 39explain select max(7) from t2m join t1m; 40select max(7) from t2m join t1m; 41 42select 1, min(a) from t1m where a=99; 43select 1, min(a) from t1m where 1=99; 44select 1, min(1) from t1m where a=99; 45select 1, min(1) from t1m where 1=99; 46 47select 1, max(a) from t1m where a=99; 48select 1, max(a) from t1m where 1=99; 49select 1, max(1) from t1m where a=99; 50select 1, max(1) from t1m where 1=99; 51 52# test with InnoDB 53select min(a) from t1i; 54select min(7) from t1i; 55select min(7) from DUAL; 56explain select min(7) from t2i join t1i; 57select min(7) from t2i join t1i; 58 59select max(a) from t1i; 60select max(7) from t1i; 61select max(7) from DUAL; 62explain select max(7) from t2i join t1i; 63select max(7) from t2i join t1i; 64 65select 1, min(a) from t1i where a=99; 66select 1, min(a) from t1i where 1=99; 67select 1, min(1) from t1i where a=99; 68select 1, min(1) from t1i where 1=99; 69 70select 1, max(a) from t1i where a=99; 71select 1, max(a) from t1i where 1=99; 72select 1, max(1) from t1i where a=99; 73select 1, max(1) from t1i where 1=99; 74 75# mixed MyISAM/InnoDB test 76explain select count(*), min(7), max(7) from t1m, t1i; 77select count(*), min(7), max(7) from t1m, t1i; 78 79explain select count(*), min(7), max(7) from t1m, t2i; 80select count(*), min(7), max(7) from t1m, t2i; 81 82explain select count(*), min(7), max(7) from t2m, t1i; 83select count(*), min(7), max(7) from t2m, t1i; 84 85drop table t1m, t1i, t2m, t2i; 86 87 88--echo # 89--echo # Bug #57954: BIT_AND function returns incorrect results when 90--echo # semijoin=on 91 92CREATE TABLE c ( 93 pk INT, 94 col_varchar_key VARCHAR(1), 95 PRIMARY KEY (pk), 96 KEY col_varchar_key (col_varchar_key) 97) ENGINE=InnoDB; 98INSERT INTO c VALUES (11,NULL); 99INSERT INTO c VALUES (16,'c'); 100CREATE TABLE bb ( 101 pk INT, 102 col_varchar_key VARCHAR(1), 103 PRIMARY KEY (pk), 104 KEY col_varchar_key (col_varchar_key) 105) ENGINE=InnoDB; 106INSERT INTO bb VALUES (10,NULL); 107 108SELECT straight_join BIT_AND(c.pk) 109FROM 110 bb, c 111 WHERE c.col_varchar_key='ABC' 112ORDER BY c.pk; 113 114DROP TABLE c,bb; 115 116--echo # 117--echo # Bug #58050: BIT_OR and BIT_XOR return incorrect results when 118--echo # semijoin=on 119--echo # 120 121CREATE TABLE t1 (pk INT PRIMARY KEY, b INT, c INT) ENGINE=InnoDB; 122INSERT INTO t1 VALUES(1, 1, 1); 123 124CREATE TABLE t2 (pk INT PRIMARY KEY, b INT, c INT) ENGINE=InnoDB; 125INSERT INTO t2 VALUES (1, 1, NULL); 126 127SELECT t1.* FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1; 128SELECT BIT_OR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1; 129SELECT BIT_AND(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1; 130SELECT BIT_XOR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1; 131 132DROP TABLE t1, t2; 133 134 135--echo End of 5.5 tests 136