1 create table t1 (USR_ID integer not null, MAX_REQ integer not null, constraint PK_SEA_USER primary key (USR_ID)) engine=InnoDB;
2 insert into t1 values (1, 3);
3 select 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;
4 count(*) + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ
6 select Case When Count(*) < MAX_REQ Then 1 Else 0 End from t1 where t1.USR_ID = 1 group by MAX_REQ;
7 Case When Count(*) < MAX_REQ Then 1 Else 0 End
10 create table t1m (a int) engine=myisam;
11 create table t1i (a int) engine=innodb;
12 create table t2m (a int) engine=myisam;
13 create table t2i (a int) engine=innodb;
14 insert into t2m values (5);
15 insert into t2i values (5);
16 select min(a) from t1m;
19 select min(7) from t1m;
22 select min(7) from DUAL;
25 explain select min(7) from t2m join t1m;
26 id select_type table type possible_keys key key_len ref rows Extra
27 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
28 select min(7) from t2m join t1m;
31 select max(a) from t1m;
34 select max(7) from t1m;
37 select max(7) from DUAL;
40 explain select max(7) from t2m join t1m;
41 id select_type table type possible_keys key key_len ref rows Extra
42 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
43 select max(7) from t2m join t1m;
46 select 1, min(a) from t1m where a=99;
49 select 1, min(a) from t1m where 1=99;
52 select 1, min(1) from t1m where a=99;
55 select 1, min(1) from t1m where 1=99;
58 select 1, max(a) from t1m where a=99;
61 select 1, max(a) from t1m where 1=99;
64 select 1, max(1) from t1m where a=99;
67 select 1, max(1) from t1m where 1=99;
70 select min(a) from t1i;
73 select min(7) from t1i;
76 select min(7) from DUAL;
79 explain select min(7) from t2i join t1i;
80 id select_type table type possible_keys key key_len ref rows Extra
81 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
82 1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer
83 select min(7) from t2i join t1i;
86 select max(a) from t1i;
89 select max(7) from t1i;
92 select max(7) from DUAL;
95 explain select max(7) from t2i join t1i;
96 id select_type table type possible_keys key key_len ref rows Extra
97 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
98 1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer
99 select max(7) from t2i join t1i;
102 select 1, min(a) from t1i where a=99;
105 select 1, min(a) from t1i where 1=99;
108 select 1, min(1) from t1i where a=99;
111 select 1, min(1) from t1i where 1=99;
114 select 1, max(a) from t1i where a=99;
117 select 1, max(a) from t1i where 1=99;
120 select 1, max(1) from t1i where a=99;
123 select 1, max(1) from t1i where 1=99;
126 explain select count(*), min(7), max(7) from t1m, t1i;
127 id select_type table type possible_keys key key_len ref rows Extra
128 1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
129 1 SIMPLE t1i ALL NULL NULL NULL NULL 1
130 select count(*), min(7), max(7) from t1m, t1i;
131 count(*) min(7) max(7)
133 explain select count(*), min(7), max(7) from t1m, t2i;
134 id select_type table type possible_keys key key_len ref rows Extra
135 1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
136 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
137 select count(*), min(7), max(7) from t1m, t2i;
138 count(*) min(7) max(7)
140 explain select count(*), min(7), max(7) from t2m, t1i;
141 id select_type table type possible_keys key key_len ref rows Extra
142 1 SIMPLE t2m system NULL NULL NULL NULL 1
143 1 SIMPLE t1i ALL NULL NULL NULL NULL 1
144 select count(*), min(7), max(7) from t2m, t1i;
145 count(*) min(7) max(7)
147 drop table t1m, t1i, t2m, t2i;
149 # Bug#12713907: STRANGE OPTIMIZE & WRONG RESULT UNDER ORDER BY
154 member_id_to INT(11) ,
156 PRIMARY KEY (id,r_date),
157 KEY r_date_idx (r_date),
158 KEY t1_idx01 (member_id_to)
160 INSERT INTO t1 VALUES
161 (107924526,518491,'2011-05-01'),
162 (107924527,518491,'2011-05-01'),
163 (107924528,518491,'2011-05-01'),
164 (107924529,518491,'2011-05-01'),
165 (107924530,518491,'2011-05-01'),
166 (107924531,518491,'2011-05-01'),
167 (107924532,518491,'2011-05-01'),
168 (107924534,518491,'2011-06-21'),
169 (107924535,518491,'2011-06-21'),
170 (107924536,518491,'2011-06-21'),
171 (107924537,518491,'2011-06-21'),
172 (107924538,518491,'2011-06-21'),
173 (107924542,1601319,'2011-06-21'),
174 (107924543,1601319,'2011-06-21'),
175 (107924544,1601319,'2011-06-21'),
176 (107924545,1601319,'2011-06-21'),
177 (107924546,1601319,'2011-06-21'),
178 (107924547,1601319,'2011-06-21'),
179 (107924548,1601319,'2011-06-21'),
180 (107924549,1601319,'2011-06-21'),
181 (107924550,1601319,'2011-06-21');
182 SELECT member_id_to, COUNT(*) FROM t1 WHERE r_date =
183 '2011-06-21' GROUP BY member_id_to ORDER BY 2 LIMIT 1;
184 member_id_to COUNT(*)
187 # End of test BUG#12713907