~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/group_min_max.result

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
drop table if exists t1;
2
 
create table t1 (
 
2
create TEMPORARY table t1 (
3
3
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
4
 
);
 
4
) ENGINE=MYISAM;
5
5
insert into t1 (a1, a2, b, c, d) values
6
6
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
7
7
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
40
40
create index idx_t1_2 on t1 (a1,a2,b);
41
41
analyze table t1;
42
42
Table   Op      Msg_type        Msg_text
43
 
test.t1 analyze status  Table is already up to date
 
43
test.t1 analyze note    The storage engine for the table doesn't support analyze
44
44
drop table if exists t2;
45
 
create table t2 (
 
45
create TEMPORARY table t2 (
46
46
a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' '
47
 
);
 
47
) ENGINE=MYISAM;
48
48
insert into t2 select * from t1;
49
49
insert into t2 (a1, a2, b, c, d) values
50
50
('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'),
68
68
create index idx_t2_2 on t2 (a1,a2,b);
69
69
analyze table t2;
70
70
Table   Op      Msg_type        Msg_text
71
 
test.t2 analyze status  Table is already up to date
 
71
test.t2 analyze note    The storage engine for the table doesn't support analyze
72
72
drop table if exists t3;
73
 
create table t3 (
 
73
create TEMPORARY table t3 (
74
74
a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' '
75
 
);
 
75
) ENGINE=MYISAM;
76
76
insert into t3 (a1, a2, b, c, d) values
77
77
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
78
78
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
130
130
create index idx_t3_2 on t3 (a1,a2,b);
131
131
analyze table t3;
132
132
Table   Op      Msg_type        Msg_text
133
 
test.t3 analyze status  Table is already up to date
 
133
test.t3 analyze note    The storage engine for the table doesn't support analyze
134
134
explain select a1, min(a2) from t1 group by a1;
135
135
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
136
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using index for group-by
 
136
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using index for group-by
137
137
explain select a1, max(a2) from t1 group by a1;
138
138
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
139
 
1       SIMPLE  t1      range   NULL    idx_t1_1        65      NULL    5       Using index for group-by
 
139
1       SIMPLE  t1      range   NULL    idx_t1_1        259     NULL    5       Using index for group-by
140
140
explain select a1, min(a2), max(a2) from t1 group by a1;
141
141
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
142
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using index for group-by
 
142
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using index for group-by
143
143
explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b;
144
144
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
145
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
145
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
146
146
explain select a1,a2,b,max(c),min(c) from t1 group by a1,a2,b;
147
147
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
148
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
148
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
149
149
explain select a1,a2,b,max(c),min(c) from t2 group by a1,a2,b;
150
150
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
151
 
1       SIMPLE  t2      range   NULL    idx_t2_1        #       NULL    #       Using index for group-by
 
151
1       SIMPLE  t2      index   NULL    idx_t2_1        #       NULL    #       Using index
152
152
explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1;
153
153
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
154
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using index for group-by
 
154
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using index for group-by
155
155
explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b;
156
156
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
157
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
157
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
158
158
explain select min(a2) from t1 group by a1;
159
159
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
160
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using index for group-by
 
160
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using index for group-by
161
161
explain select a2, min(c), max(c) from t1 group by a1,a2,b;
162
162
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
163
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
163
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
164
164
select a1, min(a2) from t1 group by a1;
165
165
a1      min(a2)
166
166
a       a
287
287
b       m422    p422
288
288
explain select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b;
289
289
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
290
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
290
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
291
291
explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'b' group by a1,a2,b;
292
292
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
293
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
293
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
294
294
explain select a1,a2,b,       max(c) from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b;
295
295
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
296
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
296
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
297
297
explain select a1, max(c)            from t1 where a1 >= 'c' or a1 < 'b' group by a1,a2,b;
298
298
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
299
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
299
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
300
300
explain select a1,a2,b,min(c),max(c) from t1 where a1 >= 'c' or a2 < 'b' group by a1,a2,b;
301
301
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
302
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
302
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    17      Using where; Using index for group-by
303
303
explain select a1,a2,b,       max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b;
304
304
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
305
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
305
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    8       Using where; Using index for group-by
306
306
explain select a1,a2,b,min(c),max(c) from t1 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b;
307
307
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
308
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
308
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    8       Using where; Using index for group-by
309
309
explain select a1,a2,b,       max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b;
310
310
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
311
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
311
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    8       Using where; Using index for group-by
312
312
explain select a1,a2,b,min(c),max(c) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b;
313
313
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
314
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
314
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    8       Using where; Using index for group-by
315
315
explain select a1,min(c),max(c)      from t1 where a1 >= 'b' group by a1,a2,b;
316
316
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
317
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
317
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
318
318
explain select a1,  max(c)           from t1 where a1 in ('a','b','d') group by a1,a2,b;
319
319
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
320
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
320
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
321
321
explain select a1,a2,b,       max(c) from t2 where a1 < 'd' group by a1,a2,b;
322
322
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
323
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
323
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
324
324
explain select a1,a2,b,min(c),max(c) from t2 where a1 < 'd' group by a1,a2,b;
325
325
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
326
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
326
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
327
327
explain select a1,a2,b,min(c),max(c) from t2 where a1 >= 'b' group by a1,a2,b;
328
328
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
329
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
329
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
330
330
explain select a1,a2,b,       max(c) from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b;
331
331
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
332
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
332
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
333
333
explain select a1, max(c)            from t2 where a1 >= 'c' or a1 < 'b' group by a1,a2,b;
334
334
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
335
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
335
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
336
336
explain select a1,a2,b,min(c),max(c) from t2 where a1 >= 'c' or a2 < 'b' group by a1,a2,b;
337
337
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
338
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
338
1       SIMPLE  t2      index   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index
339
339
explain select a1,a2,b,       max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b;
340
340
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
341
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
341
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
342
342
explain select a1,a2,b,min(c),max(c) from t2 where a1 = 'z' or a1 = 'b' or a1 = 'd' group by a1,a2,b;
343
343
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
344
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
344
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
345
345
explain select a1,a2,b,       max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b;
346
346
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
347
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
347
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
348
348
explain select a1,a2,b,min(c),max(c) from t2 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') group by a1,a2,b;
349
349
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
350
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
350
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
351
351
explain select a1,min(c),max(c)      from t2 where a1 >= 'b' group by a1,a2,b;
352
352
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
353
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
353
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
354
354
explain select a1,  max(c)           from t2 where a1 in ('a','b','d') group by a1,a2,b;
355
355
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
356
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
356
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
357
357
select a1,a2,b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b;
358
358
a1      a2      b       min(c)  max(c)
359
359
a       a       a       a111    d111
669
669
d       p422
670
670
explain select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1;
671
671
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
672
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    5       Using where; Using index for group-by
 
672
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    5       Using where; Using index for group-by
673
673
explain select a1,max(c),min(c)      from t1 where (a2 = 'a') and (b = 'b') group by a1;
674
674
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
675
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    5       Using where; Using index for group-by
 
675
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    5       Using where; Using index for group-by
676
676
explain select a1,a2,b,       max(c) from t1 where (b = 'b') group by a1,a2;
677
677
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
678
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    9       Using where; Using index for group-by
 
678
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    9       Using where; Using index for group-by
679
679
explain select a1,a2,b,min(c),max(c) from t1 where (b = 'b') group by a1,a2;
680
680
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
681
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    9       Using where; Using index for group-by
 
681
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    9       Using where; Using index for group-by
682
682
explain select a1,a2, max(c)         from t1 where (b = 'b') group by a1,a2;
683
683
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
684
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    9       Using where; Using index for group-by
 
684
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    9       Using where; Using index for group-by
685
685
explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') group by a1;
686
686
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
687
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    5       Using where; Using index for group-by
 
687
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    5       Using where; Using index for group-by
688
688
explain select a1,max(c),min(c)      from t2 where (a2 = 'a') and (b = 'b') group by a1;
689
689
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
690
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    5       Using where; Using index for group-by
 
690
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    5       Using where; Using index for group-by
691
691
explain select a1,a2,b,       max(c) from t2 where (b = 'b') group by a1,a2;
692
692
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
693
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    10      Using where; Using index for group-by
 
693
1       SIMPLE  t2      range   NULL    idx_t2_1        584     NULL    10      Using where; Using index for group-by
694
694
explain select a1,a2,b,min(c),max(c) from t2 where (b = 'b') group by a1,a2;
695
695
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
696
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    10      Using where; Using index for group-by
 
696
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    10      Using where; Using index for group-by
697
697
explain select a1,a2, max(c)         from t2 where (b = 'b') group by a1,a2;
698
698
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
699
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    10      Using where; Using index for group-by
 
699
1       SIMPLE  t2      range   NULL    idx_t2_1        584     NULL    10      Using where; Using index for group-by
700
700
explain select a1,a2,b,max(c),min(c) from t3 where (a2 = 'a') and (b = 'b') group by a1;
701
701
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
702
 
1       SIMPLE  t3      range   NULL    idx_t3_1        6       NULL    4       Using where; Using index for group-by
 
702
1       SIMPLE  t3      range   NULL    idx_t3_1        21      NULL    4       Using where; Using index for group-by
703
703
explain select a1,max(c),min(c)      from t3 where (a2 = 'a') and (b = 'b') group by a1;
704
704
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
705
 
1       SIMPLE  t3      range   NULL    idx_t3_1        6       NULL    4       Using where; Using index for group-by
 
705
1       SIMPLE  t3      range   NULL    idx_t3_1        21      NULL    4       Using where; Using index for group-by
706
706
select a1,a2,b,max(c),min(c) from t1 where (a2 = 'a') and (b = 'b') group by a1;
707
707
a1      a2      b       max(c)  min(c)
708
708
a       a       b       h112    e112
804
804
c       h312    e312
805
805
explain select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1;
806
806
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
807
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    5       Using where; Using index for group-by
 
807
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    5       Using where; Using index for group-by
808
808
explain select a1,a2,b,max(c) from t2 where (a2 = 'a') and b is NULL group by a1;
809
809
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
810
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    5       Using where; Using index for group-by
 
810
1       SIMPLE  t2      range   NULL    idx_t2_1        584     NULL    5       Using where; Using index for group-by
811
811
explain select a1,a2,b,min(c) from t2 where b is NULL group by a1,a2;
812
812
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
813
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    10      Using where; Using index for group-by
 
813
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    10      Using where; Using index for group-by
814
814
explain select a1,a2,b,max(c) from t2 where b is NULL group by a1,a2;
815
815
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
816
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    10      Using where; Using index for group-by
817
 
explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2;
818
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
819
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    10      Using where; Using index for group-by
820
 
explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2;
821
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
822
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    10      Using where; Using index for group-by
 
816
1       SIMPLE  t2      range   NULL    idx_t2_1        584     NULL    10      Using where; Using index for group-by
 
817
explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2;
 
818
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
819
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    10      Using where; Using index for group-by
 
820
explain select a1,a2,b,min(c),max(c) from t2 where b is NULL group by a1,a2;
 
821
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
822
1       SIMPLE  t2      range   NULL    idx_t2_1        651     NULL    10      Using where; Using index for group-by
823
823
select a1,a2,b,min(c) from t2 where (a2 = 'a') and b is NULL group by a1;
824
824
a1      a2      b       min(c)
825
825
a       a       NULL    a777
846
846
c       a       NULL    c777    c999
847
847
explain select a1,a2,b,       max(c) from t1 where (c > 'b1') group by a1,a2,b;
848
848
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
849
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    #       Using where; Using index for group-by
 
849
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    #       Using where; Using index for group-by
850
850
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b;
851
851
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
852
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
852
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
853
853
explain select a1,a2,b,       max(c) from t1 where (c > 'f123') group by a1,a2,b;
854
854
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
855
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
855
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
856
856
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b;
857
857
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
858
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
858
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
859
859
explain select a1,a2,b,       max(c) from t1 where (c < 'a0') group by a1,a2,b;
860
860
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
861
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
861
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
862
862
explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b;
863
863
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
864
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
864
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
865
865
explain select a1,a2,b,       max(c) from t1 where (c < 'k321') group by a1,a2,b;
866
866
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
867
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
867
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
868
868
explain select a1,a2,b,min(c),max(c) from t1 where (c < 'k321') group by a1,a2,b;
869
869
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
870
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
870
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
871
871
explain select a1,a2,b,       max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
872
872
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
873
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
873
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
874
874
explain select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
875
875
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
876
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
876
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
877
877
explain select a1,a2,b,       max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
878
878
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
879
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
879
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
880
880
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
881
881
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
882
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
882
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
883
883
explain select a1,a2,b,min(c),max(c) from t1 where (c > 'b111') and (c <= 'g112') group by a1,a2,b;
884
884
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
885
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
885
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
886
886
explain select a1,a2,b,min(c),max(c) from t1 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b;
887
887
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
888
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
888
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
889
889
explain select a1,a2,b,min(c),max(c) from t1 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b;
890
890
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
891
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
891
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
892
892
explain select a1,a2,b,min(c),max(c) from t1 where (c between 'b111' and 'g112') or (c between 'd000' and 'i110') group by a1,a2,b;
893
893
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
894
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
894
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
895
895
explain select a1,a2,b,       max(c) from t2 where (c > 'b1') group by a1,a2,b;
896
896
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
897
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
897
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
898
898
explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') group by a1,a2,b;
899
899
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
900
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
900
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
901
901
explain select a1,a2,b,       max(c) from t2 where (c > 'f123') group by a1,a2,b;
902
902
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
903
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
903
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
904
904
explain select a1,a2,b,min(c),max(c) from t2 where (c > 'f123') group by a1,a2,b;
905
905
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
906
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
906
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
907
907
explain select a1,a2,b,       max(c) from t2 where (c < 'a0') group by a1,a2,b;
908
908
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
909
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
909
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
910
910
explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') group by a1,a2,b;
911
911
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
912
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
912
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
913
913
explain select a1,a2,b,       max(c) from t2 where (c < 'k321') group by a1,a2,b;
914
914
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
915
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
915
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
916
916
explain select a1,a2,b,min(c),max(c) from t2 where (c < 'k321') group by a1,a2,b;
917
917
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
918
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
918
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
919
919
explain select a1,a2,b,       max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
920
920
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
921
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
921
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
922
922
explain select a1,a2,b,min(c),max(c) from t2 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
923
923
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
924
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
924
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
925
925
explain select a1,a2,b,       max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
926
926
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
927
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
927
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
928
928
explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
929
929
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
930
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
930
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
931
931
explain select a1,a2,b,min(c),max(c) from t2 where (c > 'b111') and (c <= 'g112') group by a1,a2,b;
932
932
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
933
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
933
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
934
934
explain select a1,a2,b,min(c),max(c) from t2 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b;
935
935
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
936
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
936
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
937
937
explain select a1,a2,b,min(c),max(c) from t2 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b;
938
938
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
939
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
939
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
940
940
select a1,a2,b,       max(c) from t1 where (c > 'b1') group by a1,a2,b;
941
941
a1      a2      b       max(c)
942
942
a       a       a       d111
955
955
d       a       b       h412
956
956
d       b       a       l421
957
957
d       b       b       p422
958
 
select a1,a2,b,min(c),max(c) from t1 where (c > 'b1') group by a1,a2,b;
959
 
a1      a2      b       min(c)  max(c)
960
 
a       a       a       b111    d111
961
 
a       a       b       e112    h112
962
 
a       b       a       i121    l121
963
 
a       b       b       m122    p122
964
 
b       a       a       b211    d211
965
 
b       a       b       e212    h212
966
 
b       b       a       i221    l221
967
 
b       b       b       m222    p222
968
 
c       a       a       b311    d311
969
 
c       a       b       e312    h312
970
 
c       b       a       i321    l321
971
 
c       b       b       m322    p322
972
 
d       a       a       b411    d411
973
 
d       a       b       e412    h412
974
 
d       b       a       i421    l421
975
 
d       b       b       m422    p422
976
958
select a1,a2,b,       max(c) from t1 where (c > 'f123') group by a1,a2,b;
977
959
a1      a2      b       max(c)
978
960
a       a       b       h112
987
969
d       a       b       h412
988
970
d       b       a       l421
989
971
d       b       b       p422
990
 
select a1,a2,b,min(c),max(c) from t1 where (c > 'f123') group by a1,a2,b;
991
 
a1      a2      b       min(c)  max(c)
992
 
a       a       b       g112    h112
993
 
a       b       a       i121    l121
994
 
a       b       b       m122    p122
995
 
b       a       b       f212    h212
996
 
b       b       a       i221    l221
997
 
b       b       b       m222    p222
998
 
c       a       b       f312    h312
999
 
c       b       a       i321    l321
1000
 
c       b       b       m322    p322
1001
 
d       a       b       f412    h412
1002
 
d       b       a       i421    l421
1003
 
d       b       b       m422    p422
1004
972
select a1,a2,b,       max(c) from t1 where (c < 'a0') group by a1,a2,b;
1005
973
a1      a2      b       max(c)
1006
974
select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') group by a1,a2,b;
1051
1019
d       a       b       h412
1052
1020
d       b       a       l421
1053
1021
d       b       b       p422
1054
 
select a1,a2,b,min(c),max(c) from t1 where (c < 'a0') or (c > 'b1') group by a1,a2,b;
1055
 
a1      a2      b       min(c)  max(c)
1056
 
a       a       a       b111    d111
1057
 
a       a       b       e112    h112
1058
 
a       b       a       i121    l121
1059
 
a       b       b       m122    p122
1060
 
b       a       a       b211    d211
1061
 
b       a       b       e212    h212
1062
 
b       b       a       i221    l221
1063
 
b       b       b       m222    p222
1064
 
c       a       a       b311    d311
1065
 
c       a       b       e312    h312
1066
 
c       b       a       i321    l321
1067
 
c       b       b       m322    p322
1068
 
d       a       a       b411    d411
1069
 
d       a       b       e412    h412
1070
 
d       b       a       i421    l421
1071
 
d       b       b       m422    p422
1072
1022
select a1,a2,b,       max(c) from t1 where (c > 'b1') or (c <= 'g1') group by a1,a2,b;
1073
1023
a1      a2      b       max(c)
1074
1024
a       a       a       d111
1358
1308
where exists ( select * from t2 where t2.c = t1.c )
1359
1309
group by a1,a2,b;
1360
1310
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1361
 
1       PRIMARY t1      index   NULL    idx_t1_1        163     NULL    128     Using where; Using index
1362
 
2       DEPENDENT SUBQUERY      t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1311
1       PRIMARY t1      index   NULL    idx_t1_1        651     NULL    128     Using where; Using index
 
1312
2       DEPENDENT SUBQUERY      t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1363
1313
explain select a1,a2,b,min(c),max(c) from t1
1364
1314
where exists ( select * from t2 where t2.c > 'b1' )
1365
1315
group by a1,a2,b;
1366
1316
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1367
 
1       PRIMARY t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
1368
 
2       SUBQUERY        t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1317
1       PRIMARY t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
 
1318
2       SUBQUERY        t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1369
1319
explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1370
1320
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1371
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1321
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    17      Using where; Using index for group-by
1372
1322
explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b;
1373
1323
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1374
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
1324
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    17      Using where; Using index for group-by
1375
1325
explain select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;
1376
1326
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1377
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
1327
1       SIMPLE  t1      range   NULL    idx_t1_1        651     NULL    17      Using where; Using index for group-by
1378
1328
explain 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;
1379
1329
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1380
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        163     NULL    14      Using where; Using index for group-by
 
1330
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    13      Using where; Using index for group-by
1381
1331
explain 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;
1382
1332
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1383
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        163     NULL    14      Using where; Using index for group-by
 
1333
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    13      Using where; Using index for group-by
1384
1334
explain select a1,a2,b,min(c) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1385
1335
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1386
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
1336
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1387
1337
explain select a1,a2,b,min(c) from t1 where (ord(a1) > 97) and (ord(a2) + ord(a1) > 194) and (b = 'c') group by a1,a2,b;
1388
1338
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1389
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1339
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
1390
1340
explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1391
1341
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1392
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1342
1       SIMPLE  t2      index   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index
1393
1343
explain select a1,a2,b,min(c),max(c) from t2 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b;
1394
1344
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1395
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1345
1       SIMPLE  t2      index   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index
1396
1346
explain select a1,a2,b,min(c),max(c) from t2 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;
1397
1347
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1398
 
1       SIMPLE  t2      range   NULL    idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1348
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
1399
1349
explain select a1,a2,b,min(c) from t2 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;
1400
1350
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1401
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1351
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
1402
1352
explain select a1,a2,b,min(c) from t2 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;
1403
1353
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1404
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1354
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
1405
1355
explain select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1406
1356
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1407
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        163     NULL    #       Using where; Using index for group-by
 
1357
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        651     NULL    #       Using where; Using index for group-by
1408
1358
select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1409
1359
a1      a2      b       min(c)  max(c)
1410
1360
a       a       b       e112    h112
1413
1363
c       b       b       m322    p322
1414
1364
d       a       b       e412    h412
1415
1365
d       b       b       m422    p422
1416
 
select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (c > 'b111') group by a1,a2,b;
1417
 
a1      a2      b       min(c)  max(c)
1418
 
a       a       a       c111    d111
1419
 
a       a       b       e112    h112
1420
 
b       a       a       b211    d211
1421
 
b       a       b       e212    h212
1422
 
c       a       a       b311    d311
1423
 
c       a       b       e312    h312
1424
 
c       b       a       i321    l321
1425
 
c       b       b       m322    p322
1426
 
d       a       a       b411    d411
1427
 
d       a       b       e412    h412
1428
 
d       b       a       i421    l421
1429
 
d       b       b       m422    p422
1430
 
select a1,a2,b,min(c),max(c) from t1 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;
1431
 
a1      a2      b       min(c)  max(c)
1432
 
a       b       a       i121    l121
1433
 
b       b       a       i221    l221
1434
 
c       b       a       i321    l321
1435
 
d       b       a       i421    l421
1436
1366
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;
1437
1367
a1      a2      b       min(c)
1438
1368
b       b       a       k221
1491
1421
a1      a2      b       min(c)
1492
1422
explain select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1493
1423
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1494
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1424
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    17      Using where; Using index for group-by
1495
1425
explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1496
1426
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1497
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1427
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
1498
1428
explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;
1499
1429
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1500
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
1430
1       SIMPLE  t1      index   NULL    idx_t1_1        651     NULL    128     Using where; Using index
1501
1431
explain select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1502
1432
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1503
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
1433
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1504
1434
explain select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1505
1435
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1506
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1436
1       SIMPLE  t2      index   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_2        584     NULL    #       Using where; Using index
1507
1437
explain select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1508
1438
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1509
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1439
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using where; Using index
1510
1440
explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;
1511
1441
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1512
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    #       Using where; Using index
 
1442
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
1513
1443
explain select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1514
1444
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1515
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1445
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
1516
1446
select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
1517
1447
a1      a2      b
1518
1448
a       a       b
1554
1484
a1      a2      b
1555
1485
explain select distinct a1,a2,b from t1;
1556
1486
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1557
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
1487
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
1558
1488
explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a');
1559
1489
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1560
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1490
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
1561
1491
explain extended select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
1562
1492
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1563
 
1       SIMPLE  t1      index   NULL    idx_t1_1        163     NULL    128     50.78   Using where; Using index
 
1493
1       SIMPLE  t1      index   NULL    idx_t1_1        651     NULL    128     50.78   Using where; Using index
1564
1494
Warnings:
1565
 
Note    1003    select distinct "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2","test"."t1"."b" AS "b","test"."t1"."c" AS "c" from "test"."t1" where (("test"."t1"."c" = 'i121') and ("test"."t1"."b" = 'a') and ("test"."t1"."a2" >= 'b'))
 
1495
Note    1003    select distinct `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ((`test`.`t1`.`a2` >= 'b') and (`test`.`t1`.`b` = 'a') and (`test`.`t1`.`c` = 'i121'))
1566
1496
explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');
1567
1497
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1568
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
1498
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1569
1499
explain select distinct b from t1 where (a2 >= 'b') and (b = 'a');
1570
1500
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1571
 
1       SIMPLE  t1      index   NULL    idx_t1_2        147     NULL    128     Using where; Using index
 
1501
1       SIMPLE  t1      index   NULL    idx_t1_2        585     NULL    128     Using where; Using index
1572
1502
explain select distinct a1,a2,b from t2;
1573
1503
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1574
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using index for group-by
 
1504
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using index
1575
1505
explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a');
1576
1506
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1577
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1507
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using where; Using index
1578
1508
explain extended select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
1579
1509
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1580
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    164     50.61   Using where; Using index
 
1510
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    164     50.61   Using where; Using index
1581
1511
Warnings:
1582
 
Note    1003    select distinct "test"."t2"."a1" AS "a1","test"."t2"."a2" AS "a2","test"."t2"."b" AS "b","test"."t2"."c" AS "c" from "test"."t2" where (("test"."t2"."c" = 'i121') and ("test"."t2"."b" = 'a') and ("test"."t2"."a2" >= 'b'))
 
1512
Note    1003    select distinct `test`.`t2`.`a1` AS `a1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`a2` >= 'b') and (`test`.`t2`.`b` = 'a') and (`test`.`t2`.`c` = 'i121'))
1583
1513
explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c');
1584
1514
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1585
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1515
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
1586
1516
explain select distinct b from t2 where (a2 >= 'b') and (b = 'a');
1587
1517
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1588
 
1       SIMPLE  t2      index   NULL    idx_t2_2        146     NULL    164     Using where; Using index
 
1518
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    164     Using where; Using index
1589
1519
select distinct a1,a2,b from t1;
1590
1520
a1      a2      b
1591
1521
a       a       a
1702
1632
d       e
1703
1633
explain select distinct a1,a2,b from t1;
1704
1634
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1705
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using index for group-by
 
1635
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using index for group-by
1706
1636
explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1707
1637
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1708
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by
 
1638
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by
1709
1639
explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;
1710
1640
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1711
 
1       SIMPLE  t1      range   NULL    idx_t1_1        163     NULL    17      Using where; Using index for group-by
 
1641
1       SIMPLE  t1      index   NULL    idx_t1_1        651     NULL    128     Using where; Using index
1712
1642
explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1713
1643
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1714
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    14      Using where; Using index for group-by
 
1644
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1715
1645
explain select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1716
1646
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1717
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    17      Using where; Using index for group-by; Using temporary; Using filesort
 
1647
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    17      Using where; Using index for group-by; Using temporary; Using filesort
1718
1648
explain select distinct a1,a2,b from t2;
1719
1649
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1720
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using index for group-by
 
1650
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using index
1721
1651
explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1722
1652
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1723
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1653
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using where; Using index
1724
1654
explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;
1725
1655
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1726
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    #       Using where; Using index
 
1656
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    #       Using where; Using index
1727
1657
explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
1728
1658
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1729
 
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        146     NULL    #       Using where; Using index for group-by
 
1659
1       SIMPLE  t2      range   idx_t2_0,idx_t2_1,idx_t2_2      idx_t2_1        584     NULL    #       Using where; Using index for group-by
1730
1660
explain select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
1731
1661
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1732
 
1       SIMPLE  t2      range   NULL    idx_t2_1        146     NULL    #       Using where; Using index for group-by; Using temporary; Using filesort
 
1662
1       SIMPLE  t2      index   NULL    idx_t2_2        584     NULL    #       Using where; Using index; Using temporary; Using filesort
1733
1663
select distinct a1,a2,b from t1;
1734
1664
a1      a2      b
1735
1665
a       a       a
1800
1730
a
1801
1731
explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
1802
1732
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1803
 
1       SIMPLE  t1      index   NULL    idx_t1_2        147     NULL    128     Using where; Using index
 
1733
1       SIMPLE  t1      index   NULL    idx_t1_2        585     NULL    128     Using where; Using index
1804
1734
explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');
1805
1735
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1806
 
1       SIMPLE  t1      index   NULL    idx_t1_1        163     NULL    128     Using where; Using index
 
1736
1       SIMPLE  t1      index   NULL    idx_t1_1        651     NULL    128     Using where; Using index
1807
1737
explain extended select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');
1808
1738
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1809
 
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        147     NULL    128     75.00   Using where; Using index
 
1739
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        585     NULL    128     75.00   Using where; Using index
1810
1740
Warnings:
1811
 
Note    1003    select count(distinct "test"."t1"."a1","test"."t1"."a2","test"."t1"."b") AS "count(distinct a1,a2,b)" from "test"."t1" where (("test"."t1"."b" = 'c') and ("test"."t1"."a1" > 'a') and ("test"."t1"."a2" > 'a'))
 
1741
Note    1003    select count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`) AS `count(distinct a1,a2,b)` from `test`.`t1` where ((`test`.`t1`.`a1` > 'a') and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`b` = 'c'))
1812
1742
explain select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a');
1813
1743
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1814
 
1       SIMPLE  t1      index   NULL    idx_t1_2        147     NULL    128     Using where; Using index
 
1744
1       SIMPLE  t1      index   NULL    idx_t1_2        585     NULL    128     Using where; Using index
1815
1745
explain extended select ord(a1) + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a');
1816
1746
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1817
 
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        147     NULL    128     75.00   Using where; Using index
 
1747
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        585     NULL    128     75.00   Using where; Using index
1818
1748
Warnings:
1819
 
Note    1003    select (ord("test"."t1"."a1") + count(distinct "test"."t1"."a1","test"."t1"."a2","test"."t1"."b")) AS "ord(a1) + count(distinct a1,a2,b)" from "test"."t1" where (("test"."t1"."a1" > 'a') and ("test"."t1"."a2" > 'a'))
 
1749
Note    1003    select (ord(`test`.`t1`.`a1`) + count(distinct `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`)) AS `ord(a1) + count(distinct a1,a2,b)` from `test`.`t1` where ((`test`.`t1`.`a1` > 'a') and (`test`.`t1`.`a2` > 'a'))
1820
1750
select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');
1821
1751
count(distinct a1,a2,b)
1822
1752
4
1834
1764
104
1835
1765
explain select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b;
1836
1766
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1837
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
1767
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1838
1768
explain select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b;
1839
1769
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1840
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
1770
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1841
1771
explain select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b;
1842
1772
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1843
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
1773
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1844
1774
explain select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b;
1845
1775
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1846
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        147     NULL    10      Using where; Using index for group-by
 
1776
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        585     NULL    13      Using where; Using index for group-by
1847
1777
explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2;
1848
1778
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1849
 
1       SIMPLE  t1      range   NULL    idx_t1_1        147     NULL    9       Using index for group-by
 
1779
1       SIMPLE  t1      range   NULL    idx_t1_1        585     NULL    9       Using index for group-by
1850
1780
select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b;
1851
1781
a1      a2      b       concat(min(c), max(c))
1852
1782
a       a       a       a111d111
1922
1852
explain extended select a1,a2,min(b),max(b) from t1
1923
1853
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2;
1924
1854
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1925
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        130     NULL    76      85.53   Using where; Using index
 
1855
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    128     49.22   Using where; Using index
1926
1856
Warnings:
1927
 
Note    1003    select "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2",min("test"."t1"."b") AS "min(b)",max("test"."t1"."b") AS "max(b)" from "test"."t1" where ((("test"."t1"."a1" = 'b') or ("test"."t1"."a1" = 'd') or ("test"."t1"."a1" = 'a') or ("test"."t1"."a1" = 'c')) and ("test"."t1"."a2" > 'a') and ("test"."t1"."c" > 'a111')) group by "test"."t1"."a1","test"."t1"."a2"
 
1857
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`c` > 'a111')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`
1928
1858
explain extended select a1,a2,b,min(c),max(c) from t1
1929
1859
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b;
1930
1860
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1931
 
1       SIMPLE  t1      ALL     idx_t1_0,idx_t1_1,idx_t1_2      NULL    NULL    NULL    128     50.78   Using where; Using temporary; Using filesort
 
1861
1       SIMPLE  t1      ALL     idx_t1_0,idx_t1_1,idx_t1_2      NULL    NULL    NULL    128     49.22   Using where; Using temporary; Using filesort
1932
1862
Warnings:
1933
 
Note    1003    select "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2","test"."t1"."b" AS "b",min("test"."t1"."c") AS "min(c)",max("test"."t1"."c") AS "max(c)" from "test"."t1" where ((("test"."t1"."a1" = 'b') or ("test"."t1"."a1" = 'd') or ("test"."t1"."a1" = 'a') or ("test"."t1"."a1" = 'c')) and ("test"."t1"."a2" > 'a') and ("test"."t1"."d" > 'xy2')) group by "test"."t1"."a1","test"."t1"."a2","test"."t1"."b"
 
1863
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,min(`test`.`t1`.`c`) AS `min(c)`,max(`test`.`t1`.`c`) AS `max(c)` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`d` > 'xy2')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
1934
1864
explain extended select a1,a2,b,c from t1
1935
1865
where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c;
1936
1866
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1937
 
1       SIMPLE  t1      ALL     idx_t1_0,idx_t1_1,idx_t1_2      NULL    NULL    NULL    128     50.78   Using where; Using temporary; Using filesort
 
1867
1       SIMPLE  t1      ALL     idx_t1_0,idx_t1_1,idx_t1_2      NULL    NULL    NULL    128     49.22   Using where; Using temporary; Using filesort
1938
1868
Warnings:
1939
 
Note    1003    select "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2","test"."t1"."b" AS "b","test"."t1"."c" AS "c" from "test"."t1" where ((("test"."t1"."a1" = 'b') or ("test"."t1"."a1" = 'd') or ("test"."t1"."a1" = 'a') or ("test"."t1"."a1" = 'c')) and ("test"."t1"."a2" > 'a') and ("test"."t1"."d" > 'xy2')) group by "test"."t1"."a1","test"."t1"."a2","test"."t1"."b","test"."t1"."c"
 
1869
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`d` > 'xy2')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`,`test`.`t1`.`c`
1940
1870
explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1;
1941
1871
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1942
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1872
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1943
1873
explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b;
1944
1874
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1945
 
1       SIMPLE  t1      range   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        130     NULL    76      85.53   Using where; Using index
 
1875
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    128     49.22   Using where; Using index
1946
1876
Warnings:
1947
 
Note    1003    select "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2","test"."t1"."b" AS "b" from "test"."t1" where ((("test"."t1"."a1" = 'b') or ("test"."t1"."a1" = 'd') or ("test"."t1"."a1" = 'a') or ("test"."t1"."a1" = 'c')) and ("test"."t1"."a2" > 'a') and ("test"."t1"."c" > 'a111')) group by "test"."t1"."a1","test"."t1"."a2","test"."t1"."b"
 
1877
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`a1` = 'b') or (`test`.`t1`.`a1` = 'd') or (`test`.`t1`.`a1` = 'a') or (`test`.`t1`.`a1` = 'c')) and (`test`.`t1`.`a2` > 'a') and (`test`.`t1`.`c` > 'a111')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
1948
1878
explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;
1949
1879
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1950
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1880
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1951
1881
select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;
1952
1882
a1      a2      min(b)  c
1953
1883
a       a       a       a111
1954
1884
explain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b = 'a') group by a1;
1955
1885
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1956
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1886
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1957
1887
explain select a1,a2,b,min(c),max(c) from t2
1958
1888
where (c > 'a000') and (c <= 'd999') and (c like '_8__') group by a1,a2,b;
1959
1889
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1960
 
1       SIMPLE  t2      index   NULL    idx_t2_1        163     NULL    164     Using where; Using index
 
1890
1       SIMPLE  t2      index   NULL    idx_t2_1        651     NULL    164     Using where; Using index
1961
1891
explain select a1, a2, b, c, min(d), max(d) from t1 group by a1,a2,b,c;
1962
1892
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1963
1893
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    128     Using temporary; Using filesort
1964
1894
explain select a1,a2,count(a2) from t1 group by a1,a2,b;
1965
1895
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1966
 
1       SIMPLE  t1      index   NULL    idx_t1_2        147     NULL    128     Using index
 
1896
1       SIMPLE  t1      index   NULL    idx_t1_2        585     NULL    128     Using index
1967
1897
explain extended select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b;
1968
1898
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1969
 
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        147     NULL    128     75.00   Using where; Using index
 
1899
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    128     75.00   Using where; Using index
1970
1900
Warnings:
1971
 
Note    1003    select "test"."t1"."a1" AS "a1","test"."t1"."a2" AS "a2",count("test"."t1"."a2") AS "count(a2)" from "test"."t1" where ("test"."t1"."a1" > 'a') group by "test"."t1"."a1","test"."t1"."a2","test"."t1"."b"
 
1901
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,count(`test`.`t1`.`a2`) AS `count(a2)` from `test`.`t1` where (`test`.`t1`.`a1` > 'a') group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
1972
1902
explain extended select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b;
1973
1903
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
1974
 
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_2        147     NULL    128     75.00   Using where; Using index
 
1904
1       SIMPLE  t1      index   idx_t1_0,idx_t1_1,idx_t1_2      idx_t1_1        651     NULL    128     75.00   Using where; Using index
1975
1905
Warnings:
1976
 
Note    1003    select sum(ord("test"."t1"."a1")) AS "sum(ord(a1))" from "test"."t1" where ("test"."t1"."a1" > 'a') group by "test"."t1"."a1","test"."t1"."a2","test"."t1"."b"
 
1906
Note    1003    select sum(ord(`test`.`t1`.`a1`)) AS `sum(ord(a1))` from `test`.`t1` where (`test`.`t1`.`a1` > 'a') group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
1977
1907
explain select distinct(a1) from t1 where ord(a2) = 98;
1978
1908
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1979
 
1       SIMPLE  t1      index   NULL    idx_t1_2        147     NULL    128     Using where; Using index
 
1909
1       SIMPLE  t1      index   NULL    idx_t1_2        585     NULL    128     Using where; Using index
1980
1910
select distinct(a1) from t1 where ord(a2) = 98;
1981
1911
a1
1982
1912
a
1985
1915
d
1986
1916
explain select a1 from t1 where a2 = 'b' group by a1;
1987
1917
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1988
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using where; Using index for group-by
 
1918
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using where; Using index for group-by
1989
1919
select a1 from t1 where a2 = 'b' group by a1;
1990
1920
a1
1991
1921
a
1994
1924
d
1995
1925
explain select distinct a1 from t1 where a2 = 'b';
1996
1926
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1997
 
1       SIMPLE  t1      range   NULL    idx_t1_1        130     NULL    5       Using where; Using index for group-by
 
1927
1       SIMPLE  t1      range   NULL    idx_t1_1        518     NULL    5       Using where; Using index for group-by
1998
1928
select distinct a1 from t1 where a2 = 'b';
1999
1929
a1
2000
1930
a
2002
1932
c
2003
1933
d
2004
1934
drop table t1,t2,t3;
2005
 
create table t1 (c1 int not null,c2 int not null, primary key(c1,c2));
 
1935
create TEMPORARY table t1 (c1 int not null,c2 int not null, primary key(c1,c2)) ENGINE=MYISAM;
2006
1936
insert into t1 (c1,c2) values
2007
1937
(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9);
2008
1938
select distinct c1, c2 from t1 order by c2;
2033
1963
30      8
2034
1964
30      9
2035
1965
drop table t1;
2036
 
CREATE TABLE t1 (a varchar(5), b int(11), PRIMARY KEY (a,b));
 
1966
CREATE TABLE t1 (a varchar(5), b int, PRIMARY KEY (a,b));
2037
1967
INSERT INTO t1 VALUES ('AA',1), ('AA',2), ('AA',3), ('BB',1), ('AA',4);
2038
 
OPTIMIZE TABLE t1;
2039
 
Table   Op      Msg_type        Msg_text
2040
 
test.t1 optimize        status  OK
 
1968
ALTER TABLE t1 ENGINE="DEFAULT";
2041
1969
SELECT a FROM t1 WHERE a='AA' GROUP BY a;
2042
1970
a
2043
1971
AA
2046
1974
BB
2047
1975
EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a;
2048
1976
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2049
 
1       SIMPLE  t1      ref     PRIMARY PRIMARY 7       const   3       Using where; Using index
 
1977
1       SIMPLE  t1      ref     PRIMARY PRIMARY 22      const   2       Using where; Using index
2050
1978
EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a;
2051
1979
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2052
 
1       SIMPLE  t1      ref     PRIMARY PRIMARY 7       const   1       Using where; Using index
 
1980
1       SIMPLE  t1      ref     PRIMARY PRIMARY 22      const   1       Using where; Using index
2053
1981
SELECT DISTINCT a FROM t1 WHERE a='BB';
2054
1982
a
2055
1983
BB
2067
1995
('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN');
2068
1996
EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a;
2069
1997
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2070
 
1       SIMPLE  t1      range   NULL    PRIMARY 66      NULL    12      Using index for group-by
 
1998
1       SIMPLE  t1      range   NULL    PRIMARY 258     NULL    12      Using index for group-by
2071
1999
SELECT DISTINCT a,a FROM t1 ORDER BY a;
2072
2000
a       a
2073
2001
        
2150
2078
(2,2), (2,3), (2,1), (3,1), (4,1), (4,2), (4,3), (4,4), (4,5), (4,6);
2151
2079
EXPLAIN SELECT max(b), a FROM t1 GROUP BY a;
2152
2080
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2153
 
1       SIMPLE  t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2081
1       SIMPLE  t1      index   NULL    a       10      NULL    15      Using index
2154
2082
FLUSH STATUS;
2155
2083
SELECT max(b), a FROM t1 GROUP BY a;
2156
2084
max(b)  a
2160
2088
6       4
2161
2089
SHOW STATUS LIKE 'handler_read__e%';
2162
2090
Variable_name   Value
2163
 
Handler_read_key        8
2164
 
Handler_read_next       0
 
2091
Handler_read_key        2
 
2092
Handler_read_next       15
2165
2093
EXPLAIN SELECT max(b), a FROM t1 GROUP BY a;
2166
2094
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2167
 
1       SIMPLE  t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2095
1       SIMPLE  t1      index   NULL    a       10      NULL    15      Using index
2168
2096
FLUSH STATUS;
2169
2097
CREATE TABLE t2 SELECT max(b), a FROM t1 GROUP BY a;
2170
2098
SHOW STATUS LIKE 'handler_read__e%';
2171
2099
Variable_name   Value
2172
 
Handler_read_key        8
2173
 
Handler_read_next       0
 
2100
Handler_read_key        2
 
2101
Handler_read_next       15
2174
2102
FLUSH STATUS;
2175
2103
SELECT * FROM (SELECT max(b), a FROM t1 GROUP BY a) b;
2176
2104
max(b)  a
2180
2108
6       4
2181
2109
SHOW STATUS LIKE 'handler_read__e%';
2182
2110
Variable_name   Value
2183
 
Handler_read_key        8
2184
 
Handler_read_next       0
 
2111
Handler_read_key        2
 
2112
Handler_read_next       15
2185
2113
FLUSH STATUS;
2186
2114
(SELECT max(b), a FROM t1 GROUP BY a) UNION 
2187
2115
(SELECT max(b), a FROM t1 GROUP BY a);
2192
2120
6       4
2193
2121
SHOW STATUS LIKE 'handler_read__e%';
2194
2122
Variable_name   Value
2195
 
Handler_read_key        16
 
2123
Handler_read_key        22
2196
2124
Handler_read_next       0
2197
2125
EXPLAIN (SELECT max(b), a FROM t1 GROUP BY a) UNION 
2198
2126
(SELECT max(b), a FROM t1 GROUP BY a);
2199
2127
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2200
 
1       PRIMARY t1      range   NULL    a       5       NULL    8       Using index for group-by
2201
 
2       UNION   t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2128
1       PRIMARY t1      range   NULL    a       5       NULL    3       Using index for group-by
 
2129
2       UNION   t1      range   NULL    a       5       NULL    3       Using index for group-by
2202
2130
NULL    UNION RESULT    <union1,2>      ALL     NULL    NULL    NULL    NULL    NULL    
2203
2131
EXPLAIN SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x
2204
2132
FROM t1 AS t1_outer;
2205
2133
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2206
2134
1       PRIMARY t1_outer        index   NULL    a       10      NULL    15      Using index
2207
 
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2135
2       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2208
2136
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS 
2209
2137
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
2210
2138
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2214
2142
(SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12;
2215
2143
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2216
2144
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE
2217
 
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2145
2       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2218
2146
EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE 
2219
2147
a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
2220
2148
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2221
2149
1       PRIMARY t1_outer        index   NULL    a       10      NULL    15      Using where; Using index
2222
 
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2150
2       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2223
2151
EXPLAIN SELECT 1 FROM t1 AS t1_outer GROUP BY a HAVING 
2224
2152
a > (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2);
2225
2153
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2226
 
1       PRIMARY t1_outer        range   NULL    a       5       NULL    8       Using index for group-by
2227
 
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2154
1       PRIMARY t1_outer        range   NULL    a       5       NULL    3       Using index for group-by
 
2155
2       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2228
2156
EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2 
2229
2157
ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) 
2230
2158
AND t1_outer1.b = t1_outer2.b;
2231
2159
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2232
2160
1       PRIMARY t1_outer1       ref     a       a       5       const   1       Using where; Using index
2233
2161
1       PRIMARY t1_outer2       index   NULL    a       10      NULL    15      Using where; Using index; Using join buffer
2234
 
2       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2162
2       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2235
2163
EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x
2236
2164
FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2;
2237
2165
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2238
2166
1       PRIMARY t1_outer2       index   NULL    a       10      NULL    15      Using index
2239
2167
2       SUBQUERY        t1_outer        index   NULL    a       10      NULL    15      Using index
2240
 
3       SUBQUERY        t1      range   NULL    a       5       NULL    8       Using index for group-by
 
2168
3       SUBQUERY        t1      range   NULL    a       5       NULL    3       Using index for group-by
2241
2169
CREATE TABLE t3 LIKE t1;
2242
2170
FLUSH STATUS;
2243
2171
INSERT INTO t3 SELECT a,MAX(b) FROM t1 GROUP BY a;
2244
2172
SHOW STATUS LIKE 'handler_read__e%';
2245
2173
Variable_name   Value
2246
 
Handler_read_key        8
 
2174
Handler_read_key        11
2247
2175
Handler_read_next       0
2248
2176
DELETE FROM t3;
2249
2177
FLUSH STATUS;
2251
2179
FROM t1 LIMIT 1;
2252
2180
SHOW STATUS LIKE 'handler_read__e%';
2253
2181
Variable_name   Value
2254
 
Handler_read_key        8
 
2182
Handler_read_key        13
2255
2183
Handler_read_next       0
2256
2184
FLUSH STATUS;
2257
2185
DELETE FROM t3 WHERE (SELECT MAX(b) FROM t1 GROUP BY a HAVING a < 2) > 10000;
2258
2186
SHOW STATUS LIKE 'handler_read__e%';
2259
2187
Variable_name   Value
2260
 
Handler_read_key        8
 
2188
Handler_read_key        11
2261
2189
Handler_read_next       0
2262
2190
FLUSH STATUS;
2263
2191
DELETE FROM t3 WHERE (SELECT (SELECT MAX(b) FROM t1 GROUP BY a HAVING a < 2) x 
2265
2193
ERROR 21000: Subquery returns more than 1 row
2266
2194
SHOW STATUS LIKE 'handler_read__e%';
2267
2195
Variable_name   Value
2268
 
Handler_read_key        8
 
2196
Handler_read_key        13
2269
2197
Handler_read_next       1
2270
2198
DROP TABLE t1,t2,t3;
2271
2199
CREATE TABLE t1 (a int, INDEX idx(a));
2274
2202
(4), (2), (1), (2), (2), (4), (1), (4);
2275
2203
EXPLAIN SELECT DISTINCT(a) FROM t1;
2276
2204
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2277
 
1       SIMPLE  t1      range   NULL    idx     5       NULL    9       Using index for group-by
 
2205
1       SIMPLE  t1      index   NULL    idx     5       NULL    16      Using index
2278
2206
SELECT DISTINCT(a) FROM t1;
2279
2207
a
2280
2208
1
2282
2210
4
2283
2211
EXPLAIN SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1;
2284
2212
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2285
 
1       SIMPLE  t1      range   NULL    idx     5       NULL    9       Using index for group-by
 
2213
1       SIMPLE  t1      index   NULL    idx     5       NULL    16      Using index
2286
2214
SELECT SQL_BIG_RESULT DISTINCT(a) FROM t1;
2287
2215
a
2288
2216
1
2307
2235
EXPLAIN
2308
2236
SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a;
2309
2237
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2310
 
1       SIMPLE  t1      range   NULL    break_it        10      NULL    7       Using index for group-by
 
2238
1       SIMPLE  t1      range   NULL    break_it        10      NULL    3       Using index for group-by
2311
2239
SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a;
2312
2240
a       MIN(b)  MAX(b)
2313
2241
1       1       3
2317
2245
EXPLAIN
2318
2246
SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC;
2319
2247
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2320
 
1       SIMPLE  t1      range   NULL    break_it        10      NULL    7       Using index for group-by; Using temporary; Using filesort
 
2248
1       SIMPLE  t1      range   NULL    break_it        10      NULL    3       Using index for group-by; Using temporary; Using filesort
2321
2249
SELECT a, MIN(b), MAX(b) FROM t1 GROUP BY a ORDER BY a DESC;
2322
2250
a       MIN(b)  MAX(b)
2323
2251
4       1       3
2335
2263
2       1       3       2.0000
2336
2264
1       1       3       2.0000
2337
2265
DROP TABLE t1;
 
2266
CREATE TABLE t1 (a int, b int, c int, d int,
 
2267
KEY foo (c,d,a,b), KEY bar (c,a,b,d));
 
2268
INSERT INTO t1 VALUES (1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 1, 3), (1, 1, 1, 4);
 
2269
INSERT INTO t1 SELECT * FROM t1;
 
2270
INSERT INTO t1 SELECT * FROM t1;
 
2271
INSERT INTO t1 SELECT a,b,c+1,d FROM t1;
 
2272
EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4;
 
2273
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
2274
1       SIMPLE  t1      range   NULL    foo     10      NULL    17      Using where; Using index for group-by
 
2275
SELECT DISTINCT c FROM t1 WHERE d=4;
 
2276
c
 
2277
1
 
2278
2
 
2279
DROP TABLE t1;