~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/group_by.result

  • Committer: Monty Taylor
  • Date: 2008-10-20 08:48:34 UTC
  • mfrom: (520.1.22 drizzle)
  • Revision ID: monty@inaugust.com-20081020084834-xpb3w01vkcp55o02
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
SELECT 1 FROM (SELECT 1) as a  GROUP BY SUM(1);
3
3
ERROR HY000: Invalid use of group function
4
4
CREATE TABLE t1 (
5
 
spID int(10) unsigned,
6
 
userID int(10) unsigned,
7
 
score smallint(5) unsigned,
 
5
spID int,
 
6
userID int,
 
7
score int,
8
8
lsg char(40),
9
9
date date
10
10
);
13
13
INSERT INTO t1 VALUES (2,1,1,'','0000-00-00');
14
14
INSERT INTO t1 VALUES (3,3,3,'','0000-00-00');
15
15
CREATE TABLE t2 (
16
 
userID int(10) unsigned NOT NULL auto_increment,
 
16
userID int NOT NULL auto_increment,
17
17
niName char(15),
18
18
passwd char(8),
19
19
mail char(50),
59
59
1       SIMPLE  t2      eq_ref  PRIMARY PRIMARY 4       test.t1.userID  1       Using index
60
60
drop table t1,t2;
61
61
CREATE TABLE t1 (
62
 
PID int(10) unsigned NOT NULL auto_increment,
 
62
PID int NOT NULL auto_increment,
63
63
payDate date DEFAULT '0000-00-00' NOT NULL,
64
64
recDate datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
65
 
URID int(10) unsigned DEFAULT '0' NOT NULL,
66
 
CRID int(10) unsigned DEFAULT '0' NOT NULL,
67
 
amount int(10) unsigned DEFAULT '0' NOT NULL,
68
 
operator int(10) unsigned,
 
65
URID int DEFAULT '0' NOT NULL,
 
66
CRID int DEFAULT '0' NOT NULL,
 
67
amount int DEFAULT '0' NOT NULL,
 
68
operator int,
69
69
method enum('unknown','cash','dealer','check','card','lazy','delayed','test') DEFAULT 'unknown' NOT NULL,
70
 
DIID int(10) unsigned,
 
70
DIID int,
71
71
reason char(1) binary DEFAULT '' NOT NULL,
72
 
code_id int(10) unsigned,
73
 
qty mediumint(8) unsigned DEFAULT '0' NOT NULL,
 
72
code_id int,
 
73
qty int DEFAULT '0' NOT NULL,
74
74
PRIMARY KEY (PID),
75
75
KEY URID (URID),
76
76
KEY reason (reason),
82
82
ERROR 42000: Can't group on 'IsNew'
83
83
drop table t1;
84
84
CREATE TABLE t1 (
85
 
cid mediumint(9) NOT NULL auto_increment,
 
85
cid int NOT NULL auto_increment,
86
86
firstname varchar(32) DEFAULT '' NOT NULL,
87
87
surname varchar(32) DEFAULT '' NOT NULL,
88
88
PRIMARY KEY (cid)
90
90
INSERT INTO t1 VALUES (1,'That','Guy');
91
91
INSERT INTO t1 VALUES (2,'Another','Gent');
92
92
CREATE TABLE t2 (
93
 
call_id mediumint(8) NOT NULL auto_increment,
94
 
contact_id mediumint(8) DEFAULT '0' NOT NULL,
 
93
call_id int NOT NULL auto_increment,
 
94
contact_id int DEFAULT '0' NOT NULL,
95
95
PRIMARY KEY (call_id),
96
96
KEY contact_id (contact_id)
97
97
);
110
110
drop table t2;
111
111
unlock tables;
112
112
drop table t1;
113
 
CREATE TABLE t1 (
114
 
bug_id mediumint(9) NOT NULL auto_increment,
115
 
groupset bigint(20) DEFAULT '0' NOT NULL,
116
 
assigned_to mediumint(9) DEFAULT '0' NOT NULL,
117
 
bug_file_loc text,
118
 
bug_severity enum('blocker','critical','major','normal','minor','trivial','enhancement') DEFAULT 'blocker' NOT NULL,
119
 
bug_status enum('','NEW','ASSIGNED','REOPENED','RESOLVED','VERIFIED','CLOSED') DEFAULT 'NEW' NOT NULL,
120
 
creation_ts datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
121
 
delta_ts timestamp,
122
 
short_desc mediumtext,
123
 
long_desc mediumtext,
124
 
op_sys enum('All','Windows 3.1','Windows 95','Windows 98','Windows NT','Windows 2000','Linux','other') DEFAULT 'All' NOT NULL,
125
 
priority enum('P1','P2','P3','P4','P5') DEFAULT 'P1' NOT NULL,
126
 
product varchar(64) DEFAULT '' NOT NULL,
127
 
rep_platform enum('All','PC','VTD-8','Other'),
128
 
reporter mediumint(9) DEFAULT '0' NOT NULL,
129
 
version varchar(16) DEFAULT '' NOT NULL,
130
 
component varchar(50) DEFAULT '' NOT NULL,
131
 
resolution enum('','FIXED','INVALID','WONTFIX','LATER','REMIND','DUPLICATE','WORKSFORME') DEFAULT '' NOT NULL,
132
 
target_milestone varchar(20) DEFAULT '' NOT NULL,
133
 
qa_contact mediumint(9) DEFAULT '0' NOT NULL,
134
 
status_whiteboard mediumtext NOT NULL,
135
 
votes mediumint(9) DEFAULT '0' NOT NULL,
136
 
PRIMARY KEY (bug_id),
137
 
KEY assigned_to (assigned_to),
138
 
KEY creation_ts (creation_ts),
139
 
KEY delta_ts (delta_ts),
140
 
KEY bug_severity (bug_severity),
141
 
KEY bug_status (bug_status),
142
 
KEY op_sys (op_sys),
143
 
KEY priority (priority),
144
 
KEY product (product),
145
 
KEY reporter (reporter),
146
 
KEY version (version),
147
 
KEY component (component),
148
 
KEY resolution (resolution),
149
 
KEY target_milestone (target_milestone),
150
 
KEY qa_contact (qa_contact),
151
 
KEY votes (votes)
152
 
);
153
 
INSERT INTO t1 VALUES (1,0,0,'','normal','','2000-02-10 09:25:12',20000321114747,'','','Linux','P1','TestProduct','PC',3,'other','TestComponent','','M1',0,'',0);
154
 
INSERT INTO t1 VALUES (9,0,0,'','enhancement','','2000-03-10 11:49:36',20000321114747,'','','All','P5','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
155
 
INSERT INTO t1 VALUES (10,0,0,'','enhancement','','2000-03-10 18:10:16',20000321114747,'','','All','P4','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - conversion','','',0,'',0);
156
 
INSERT INTO t1 VALUES (7,0,0,'','critical','','2000-03-09 10:50:21',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
157
 
INSERT INTO t1 VALUES (6,0,0,'','normal','','2000-03-09 10:42:44',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
158
 
INSERT INTO t1 VALUES (8,0,0,'','major','','2000-03-09 11:32:14',20000321114747,'','','All','P3','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
159
 
INSERT INTO t1 VALUES (5,0,0,'','enhancement','','2000-03-09 10:38:59',20000321114747,'','','All','P5','CCC/CCCCCC','PC',5,'7.00','Administration','','',0,'',0);
160
 
INSERT INTO t1 VALUES (4,0,0,'','normal','','2000-03-08 18:32:14',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent2','','',0,'',0);
161
 
INSERT INTO t1 VALUES (3,0,0,'','normal','','2000-03-08 18:30:52',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
162
 
INSERT INTO t1 VALUES (2,0,0,'','enhancement','','2000-03-08 18:24:51',20000321114747,'','','All','P2','TestProduct','Other',4,'other','TestComponent2','','',0,'',0);
163
 
INSERT INTO t1 VALUES (11,0,0,'','blocker','','2000-03-13 09:43:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
164
 
INSERT INTO t1 VALUES (12,0,0,'','normal','','2000-03-13 16:14:31',20000321114747,'','','All','P2','AAAAA','PC',3,'2.00 CD - Pre','kkkkkkkkkkk lllllllllll','','',0,'',0);
165
 
INSERT INTO t1 VALUES (13,0,0,'','normal','','2000-03-15 16:20:44',20000321114747,'','','other','P2','TestProduct','Other',3,'other','TestComponent','','',0,'',0);
166
 
INSERT INTO t1 VALUES (14,0,0,'','blocker','','2000-03-15 18:13:47',20000321114747,'','','All','P1','AAAAA','PC',3,'2.00 CD - Pre','BBBBBBBBBBBBB - generic','','',0,'',0);
167
 
INSERT INTO t1 VALUES (15,0,0,'','minor','','2000-03-16 18:03:28',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
168
 
INSERT INTO t1 VALUES (16,0,0,'','normal','','2000-03-16 18:33:41',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
169
 
INSERT INTO t1 VALUES (17,0,0,'','normal','','2000-03-16 18:34:18',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
170
 
INSERT INTO t1 VALUES (18,0,0,'','normal','','2000-03-16 18:34:56',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
171
 
INSERT INTO t1 VALUES (19,0,0,'','enhancement','','2000-03-16 18:35:34',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
172
 
INSERT INTO t1 VALUES (20,0,0,'','enhancement','','2000-03-16 18:36:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
173
 
INSERT INTO t1 VALUES (21,0,0,'','enhancement','','2000-03-16 18:37:23',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
174
 
INSERT INTO t1 VALUES (22,0,0,'','enhancement','','2000-03-16 18:38:16',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','Administration','','',0,'',0);
175
 
INSERT INTO t1 VALUES (23,0,0,'','normal','','2000-03-16 18:58:12',20000321114747,'','','All','P2','CCC/CCCCCC','Other',5,'7.00','DDDDDDDDD','','',0,'',0);
176
 
INSERT INTO t1 VALUES (24,0,0,'','normal','','2000-03-17 11:08:10',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
177
 
INSERT INTO t1 VALUES (25,0,0,'','normal','','2000-03-17 11:10:45',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
178
 
INSERT INTO t1 VALUES (26,0,0,'','normal','','2000-03-17 11:15:47',20000321114747,'','','All','P2','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
179
 
INSERT INTO t1 VALUES (27,0,0,'','normal','','2000-03-17 17:45:41',20000321114747,'','','All','P2','CCC/CCCCCC','PC',5,'7.00','DDDDDDDDD','','',0,'',0);
180
 
INSERT INTO t1 VALUES (28,0,0,'','normal','','2000-03-20 09:51:45',20000321114747,'','','Windows NT','P2','TestProduct','PC',8,'other','TestComponent','','',0,'',0);
181
 
INSERT INTO t1 VALUES (29,0,0,'','normal','','2000-03-20 11:15:09',20000321114747,'','','All','P5','AAAAAAAA-AAA','PC',3,'2.8','Web Interface','','',0,'',0);
182
 
CREATE TABLE t2 (
183
 
value tinytext,
184
 
program varchar(64),
185
 
initialowner tinytext NOT NULL,
186
 
initialqacontact tinytext NOT NULL,
187
 
description mediumtext NOT NULL
188
 
);
189
 
INSERT INTO t2 VALUES ('TestComponent','TestProduct','id0001','','');
190
 
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - conversion','AAAAA','id0001','','');
191
 
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - generic','AAAAA','id0001','','');
192
 
INSERT INTO t2 VALUES ('TestComponent2','TestProduct','id0001','','');
193
 
INSERT INTO t2 VALUES ('BBBBBBBBBBBBB - eeeeeeeee','AAAAA','id0001','','');
194
 
INSERT INTO t2 VALUES ('kkkkkkkkkkk lllllllllll','AAAAA','id0001','','');
195
 
INSERT INTO t2 VALUES ('Test Procedures','AAAAA','id0001','','');
196
 
INSERT INTO t2 VALUES ('Documentation','AAAAA','id0003','','');
197
 
INSERT INTO t2 VALUES ('DDDDDDDDD','CCC/CCCCCC','id0002','','');
198
 
INSERT INTO t2 VALUES ('Eeeeeeee Lite','CCC/CCCCCC','id0002','','');
199
 
INSERT INTO t2 VALUES ('Eeeeeeee Full','CCC/CCCCCC','id0002','','');
200
 
INSERT INTO t2 VALUES ('Administration','CCC/CCCCCC','id0002','','');
201
 
INSERT INTO t2 VALUES ('Distribution','CCC/CCCCCC','id0002','','');
202
 
INSERT INTO t2 VALUES ('Setup','CCC/CCCCCC','id0002','','');
203
 
INSERT INTO t2 VALUES ('Unspecified','CCC/CCCCCC','id0002','','');
204
 
INSERT INTO t2 VALUES ('Web Interface','AAAAAAAA-AAA','id0001','','');
205
 
INSERT INTO t2 VALUES ('Host communication','AAAAA','id0001','','');
206
 
select value,description,bug_id from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA";
207
 
value   description     bug_id
208
 
BBBBBBBBBBBBB - conversion              9
209
 
BBBBBBBBBBBBB - conversion              10
210
 
BBBBBBBBBBBBB - generic         7
211
 
BBBBBBBBBBBBB - generic         14
212
 
BBBBBBBBBBBBB - eeeeeeeee               NULL
213
 
kkkkkkkkkkk lllllllllll         6
214
 
kkkkkkkkkkk lllllllllll         8
215
 
kkkkkkkkkkk lllllllllll         12
216
 
Test Procedures         NULL
217
 
Documentation           NULL
218
 
Host communication              NULL
219
 
select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value;
220
 
value   description     COUNT(bug_id)
221
 
BBBBBBBBBBBBB - conversion              2
222
 
BBBBBBBBBBBBB - eeeeeeeee               0
223
 
BBBBBBBBBBBBB - generic         2
224
 
Documentation           0
225
 
Host communication              0
226
 
kkkkkkkkkkk lllllllllll         3
227
 
Test Procedures         0
228
 
select value,description,COUNT(bug_id) from t2 left join t1 on t2.program=t1.product and t2.value=t1.component where program="AAAAA" group by value having COUNT(bug_id) IN (0,2);
229
 
value   description     COUNT(bug_id)
230
 
BBBBBBBBBBBBB - conversion              2
231
 
BBBBBBBBBBBBB - eeeeeeeee               0
232
 
BBBBBBBBBBBBB - generic         2
233
 
Documentation           0
234
 
Host communication              0
235
 
Test Procedures         0
236
 
drop table t1,t2;
237
113
create table t1 (foo int);
238
114
insert into t1 values (1);
239
115
select 1+1, "a",count(*) from t1 where foo in (2);
245
121
2       a       0
246
122
drop table t1;
247
123
CREATE TABLE t1 (
248
 
spID int(10) unsigned,
249
 
userID int(10) unsigned,
250
 
score smallint(5) unsigned,
 
124
spID int,
 
125
userID int,
 
126
score int,
251
127
key (spid),
252
128
key (score)
253
129
);
289
165
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
290
166
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    8       100.00  Using filesort
291
167
Warnings:
292
 
Note    1003    select sql_big_result "test"."t1"."spID" AS "spid",sum("test"."t1"."userID") AS "sum(userid)" from "test"."t1" group by "test"."t1"."spID" desc
 
168
Note    1003    select sql_big_result `test`.`t1`.`spID` AS `spid`,sum(`test`.`t1`.`userID`) AS `sum(userid)` from `test`.`t1` group by `test`.`t1`.`spID` desc
293
169
explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null;
294
170
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
295
171
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    8       Using filesort
304
180
1       1
305
181
explain select sql_big_result score,count(*) from t1 group by score desc;
306
182
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
307
 
1       SIMPLE  t1      index   NULL    score   3       NULL    8       Using index; Using filesort
 
183
1       SIMPLE  t1      index   NULL    score   5       NULL    8       Using index; Using filesort
308
184
explain select sql_big_result score,count(*) from t1 group by score desc order by null;
309
185
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
310
 
1       SIMPLE  t1      index   NULL    score   3       NULL    8       Using index; Using filesort
 
186
1       SIMPLE  t1      index   NULL    score   5       NULL    8       Using index; Using filesort
311
187
select sql_big_result score,count(*) from t1 group by score desc;
312
188
score   count(*)
313
189
3       5
359
235
B       4
360
236
a       1
361
237
b       1
362
 
SET SQL_BIG_TABLES=1;
363
238
SELECT a FROM t1 GROUP BY a;
364
239
a
365
240
NULL
398
273
B       4
399
274
a       1
400
275
b       1
401
 
SET SQL_BIG_TABLES=0;
402
276
drop table t1;
403
277
CREATE TABLE t1 (
404
278
`a` char(193) default NULL,
427
301
abcdef  1
428
302
hijklm  2
429
303
DROP TABLE t1;
430
 
create table t1 (One int unsigned, Two int unsigned, Three int unsigned, Four int unsigned);
 
304
create table t1 (One int, Two int, Three int, Four int);
431
305
insert into t1 values (1,2,1,4),(1,2,2,4),(1,2,3,4),(1,2,4,4),(1,1,1,4),(1,1,2,4),(1,1,3,4),(1,1,4,4),(1,3,1,4),(1,3,2,4),(1,3,3,4),(1,3,4,4);
432
306
select One, Two, sum(Four) from t1 group by One,Two;
433
307
One     Two     sum(Four)
471
345
4       185     ****
472
346
drop table t1;
473
347
CREATE TABLE t1 (
474
 
pid int(11) unsigned NOT NULL default '0',
475
 
c1id int(11) unsigned default NULL,
476
 
c2id int(11) unsigned default NULL,
477
 
value int(11) unsigned NOT NULL default '0',
 
348
pid int NOT NULL default '0',
 
349
c1id int default NULL,
 
350
c2id int default NULL,
 
351
value int NOT NULL default '0',
478
352
UNIQUE KEY pid2 (pid,c1id,c2id),
479
353
UNIQUE KEY pid (pid,value)
480
354
) ENGINE=MyISAM;
481
355
INSERT INTO t1 VALUES (1, 1, NULL, 1),(1, 2, NULL, 2),(1, NULL, 3, 3),(1, 4, NULL, 4),(1, 5, NULL, 5);
482
356
CREATE TABLE t2 (
483
 
id int(11) unsigned NOT NULL default '0',
 
357
id int NOT NULL default '0',
484
358
active enum('Yes','No') NOT NULL default 'Yes',
485
359
PRIMARY KEY  (id)
486
360
) ENGINE=MyISAM;
487
361
INSERT INTO t2 VALUES (1, 'Yes'),(2, 'No'),(4, 'Yes'),(5, 'No');
488
362
CREATE TABLE t3 (
489
 
id int(11) unsigned NOT NULL default '0',
 
363
id int NOT NULL default '0',
490
364
active enum('Yes','No') NOT NULL default 'Yes',
491
365
PRIMARY KEY  (id)
492
366
);
512
386
NULL    9
513
387
        3
514
388
b       1
515
 
set option sql_big_tables=1;
516
389
select a,count(*) from t1 group by a;
517
390
a       count(*)
518
391
NULL    9
602
475
1       4
603
476
drop table t1;
604
477
CREATE TABLE t1 (
605
 
userid int(10) unsigned,
606
 
score smallint(5) unsigned,
 
478
userid int,
 
479
score int,
607
480
key (score)
608
481
);
609
482
INSERT INTO t1 VALUES (1,1),(2,2),(1,1),(3,3),(3,3),(3,3),(3,3),(3,3);
617
490
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    8       Using temporary; Using filesort
618
491
DROP TABLE t1;
619
492
CREATE TABLE t1 (
620
 
i int(11) default NULL,
621
 
j int(11) default NULL
 
493
i int default NULL,
 
494
j int default NULL
622
495
);
623
496
INSERT INTO t1 VALUES (1,2),(2,3),(4,5),(3,5),(1,5),(23,5);
624
497
SELECT i, COUNT(DISTINCT(i)) FROM t1 GROUP BY j ORDER BY NULL;
687
560
d varchar(100) NOT NULL,
688
561
primary key (a,b(132),c,d),
689
562
key a (a,b)
690
 
) charset=utf8;
 
563
);
 
564
Warnings:
 
565
Warning 1071    Specified key was too long; max key length is 767 bytes
691
566
insert into t2 select 
692
567
x3.a,  -- 3
693
568
concat('val-', x3.a + 3*x4.a), -- 12
697
572
delete from t2  where a = 2 and b = 'val-2' order by a,b,c,d limit 30;
698
573
explain select c from t2 where a = 2 and b = 'val-2' group by c;
699
574
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
700
 
1       SIMPLE  t2      ref     PRIMARY,a       PRIMARY 534     const,const     6       Using where
 
575
1       SIMPLE  t2      ref     PRIMARY,a       a       770     const,const     36      Using where; Using index
701
576
select c from t2 where a = 2 and b = 'val-2' group by c;
702
577
c
703
578
val-74
704
579
val-98
705
580
drop table t1,t2;
706
 
create table t1 (b int4 unsigned not null);
707
 
insert into t1 values(3000000000);
 
581
create table t1 (b int4 not null);
 
582
insert into t1 values(300000);
708
583
select * from t1;
709
584
b
710
 
3000000000
 
585
300000
711
586
select min(b) from t1;
712
587
min(b)
713
 
3000000000
 
588
300000
714
589
drop table t1;
715
590
CREATE TABLE t1 (id int PRIMARY KEY, user_id int, hostname longtext);
716
591
INSERT INTO t1 VALUES
823
698
1
824
699
DROP TABLE t1;
825
700
CREATE TABLE t1 (
826
 
f1 int(10) unsigned NOT NULL auto_increment primary key,
 
701
f1 int NOT NULL auto_increment primary key,
827
702
f2 varchar(100) NOT NULL default ''
828
703
);
829
704
CREATE TABLE t2 (
877
752
1       SIMPLE  t1      index   NULL    b       5       NULL    128     Using index
878
753
EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
879
754
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
880
 
1       SIMPLE  t1      index   NULL    b       5       NULL    128     Using index; Using filesort
 
755
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    128     Using filesort
881
756
SELECT b, sum(1) FROM t1 GROUP BY b;
882
757
b       sum(1)
883
758
0       6
1093
968
2       4       1
1094
969
SELECT * FROM t1 GROUP BY c2  ORDER BY c2, c1;
1095
970
id      c1      c2
1096
 
1       5       1
1097
 
4       2       3
 
971
2       4       1
 
972
5       1       3
1098
973
3       3       5
1099
974
SELECT * FROM t1 GROUP BY c2  ORDER BY c2 DESC, c1;
1100
975
id      c1      c2
1122
997
SELECT 1 FROM t1 ORDER BY COUNT(*) + a;
1123
998
1
1124
999
1
1125
 
1
1126
 
1
1127
 
1
1128
 
1
1129
 
1
1130
1000
SELECT 1 FROM t1 ORDER BY COUNT(*), 1;
1131
1001
1
1132
1002
1
1133
1003
SELECT 1 FROM t1 ORDER BY COUNT(*), a;
1134
1004
1
1135
1005
1
1136
 
1
1137
 
1
1138
 
1
1139
 
1
1140
 
1
1141
1006
SELECT 1 FROM t1 ORDER BY SUM(a);
1142
1007
1
1143
1008
1
1314
1179
1       SIMPLE  t1      range   PRIMARY,i2      PRIMARY 4       NULL    1       Using where; Using index
1315
1180
EXPLAIN SELECT a FROM t1 WHERE a < 2 GROUP BY a;
1316
1181
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1317
 
1       SIMPLE  t1      range   PRIMARY,i2      PRIMARY 4       NULL    1       Using where; Using index
 
1182
1       SIMPLE  t1      range   PRIMARY,i2      PRIMARY 4       NULL    1       Using where; Using index for group-by
1318
1183
EXPLAIN SELECT a FROM t1 IGNORE INDEX (PRIMARY,i2);
1319
1184
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1320
1185
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    144     
1479
1344
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     Using index
1480
1345
EXPLAIN SELECT a FROM t1 IGNORE INDEX (PRIMARY) IGNORE INDEX FOR ORDER BY (i2);
1481
1346
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1482
 
1       SIMPLE  t1      index   NULL    i2      9       NULL    144     Using index
 
1347
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     
1483
1348
EXPLAIN SELECT a FROM t1 FORCE INDEX (i2);
1484
1349
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1485
 
1       SIMPLE  t1      index   NULL    i2      9       NULL    144     Using index
 
1350
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     
1486
1351
EXPLAIN SELECT a FROM t1 USE INDEX ();
1487
1352
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1488
1353
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    144     
1497
1362
ERROR HY000: Incorrect usage of USE INDEX and FORCE INDEX
1498
1363
EXPLAIN SELECT a FROM t1 USE INDEX (i2) USE INDEX ();
1499
1364
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1500
 
1       SIMPLE  t1      index   NULL    i2      9       NULL    144     Using index
 
1365
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     
1501
1366
EXPLAIN SELECT a FROM t1 FORCE INDEX ();
1502
1367
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
1503
1368
EXPLAIN SELECT a FROM t1 IGNORE INDEX ();
1521
1386
USE INDEX FOR ORDER BY (i2)
1522
1387
USE INDEX FOR JOIN (i2);
1523
1388
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1524
 
1       SIMPLE  t1      index   NULL    i2      9       NULL    144     Using index
 
1389
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     
1525
1390
EXPLAIN SELECT a FROM t1 
1526
1391
USE INDEX FOR JOIN (i2) 
1527
1392
USE INDEX FOR JOIN (i2) 
1528
1393
USE INDEX FOR JOIN (i2,i2);
1529
1394
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1530
 
1       SIMPLE  t1      index   NULL    i2      9       NULL    144     Using index
 
1395
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    144     
1531
1396
EXPLAIN SELECT 1 FROM t1 WHERE a IN
1532
1397
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
1533
1398
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1544
1409
EXPLAIN SELECT 1 FROM t2 WHERE a IN
1545
1410
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
1546
1411
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1547
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    144     Start temporary
1548
 
1       PRIMARY t2      index   a       a       5       NULL    4       Using where; Using index; End temporary; Using join buffer
 
1412
1       PRIMARY t2      index   a       a       5       NULL    4       Using index; Start temporary
 
1413
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    144     Using where; End temporary; Using join buffer
1549
1414
SHOW VARIABLES LIKE 'old';
1550
1415
Variable_name   Value
1551
1416
old     OFF
1580
1445
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
1581
1446
c       b       d
1582
1447
1       1       50
 
1448
3       1       4
1583
1449
3       2       40
1584
 
3       1       4
1585
1450
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
1586
1451
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1587
1452
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
1592
1457
3       2       40
1593
1458
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
1594
1459
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1595
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
 
1460
1       SIMPLE  t1      index   NULL    c       8       NULL    3       
1596
1461
SELECT c,b,d FROM t1 GROUP BY c,b;
1597
1462
c       b       d
1598
1463
1       1       50