~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/group_by.result

  • Committer: Stewart Smith
  • Date: 2009-05-15 06:57:12 UTC
  • mto: (991.1.5 for-brian)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: stewart@flamingspork.com-20090515065712-bmionylacjmexmmm
Make sql_mode=NO_AUTO_VALUE_ON_ZERO default for Drizzle.

Also fix DEFAULT keyword handling for auto-increment so that it defaults to
NULL and not 0 so that the following is valid and generates two auto-inc
values:

create table t1 (a int auto_increment primary key)
insert into t1 (a) values (default);
insert into t1 (a) values (default);

Important to note that 0 is no longer magic. So this gives you duplicate
primary key error:

insert into t1 (a) values(0);
insert into t1 (a) values(0);

as you've inserted the explicit value of 0 twice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
operator int,
69
69
method enum('unknown','cash','dealer','check','card','lazy','delayed','test') DEFAULT 'unknown' NOT NULL,
70
70
DIID int,
71
 
reason char(1) DEFAULT '' NOT NULL,
 
71
reason char(1) binary DEFAULT '' NOT NULL,
72
72
code_id int,
73
73
qty int DEFAULT '0' NOT NULL,
74
74
PRIMARY KEY (PID),
95
95
PRIMARY KEY (call_id),
96
96
KEY contact_id (contact_id)
97
97
);
 
98
lock tables t1 read,t2 write;
98
99
INSERT INTO t2 VALUES (10,2);
99
100
INSERT INTO t2 VALUES (18,2);
100
101
INSERT INTO t2 VALUES (62,2);
104
105
cid     CONCAT(firstname, ' ', surname) COUNT(call_id)
105
106
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY NULL;
106
107
cid     CONCAT(firstname, ' ', surname) COUNT(call_id)
107
 
SELECT cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname;
 
108
SELECT HIGH_PRIORITY cid, CONCAT(firstname, ' ', surname), COUNT(call_id) FROM t1 LEFT JOIN t2 ON cid=contact_id WHERE firstname like '%foo%' GROUP BY cid ORDER BY surname, firstname;
108
109
cid     CONCAT(firstname, ' ', surname) COUNT(call_id)
109
110
drop table t2;
 
111
unlock tables;
110
112
drop table t1;
111
113
create table t1 (foo int);
112
114
insert into t1 values (1);
205
207
NULL    3
206
208
A       5
207
209
B       5
208
 
SELECT a FROM t1 GROUP BY a;
209
 
a
210
 
NULL
211
 
A
212
 
B
213
 
SELECT a,count(*) FROM t1 GROUP BY a;
214
 
a       count(*)
215
 
NULL    3
216
 
A       5
217
 
B       5
218
 
SELECT a FROM t1 GROUP BY 1;
219
 
a
220
 
NULL
221
 
A
222
 
B
223
 
SELECT a,count(*) FROM t1 GROUP BY 1;
224
 
a       count(*)
225
 
NULL    3
226
 
A       5
227
 
B       5
228
 
SELECT a FROM t1 GROUP BY a;
229
 
a
230
 
NULL
231
 
A
232
 
B
233
 
SELECT a,count(*) FROM t1 GROUP BY a;
234
 
a       count(*)
235
 
NULL    3
236
 
A       5
237
 
B       5
238
 
SELECT a FROM t1 GROUP BY a;
239
 
a
240
 
NULL
241
 
A
242
 
B
243
 
SELECT a,count(*) FROM t1 GROUP BY a;
244
 
a       count(*)
245
 
NULL    3
246
 
A       5
247
 
B       5
248
 
SELECT a FROM t1 GROUP BY 1;
249
 
a
250
 
NULL
251
 
A
252
 
B
253
 
SELECT a,count(*) FROM t1 GROUP BY 1;
254
 
a       count(*)
255
 
NULL    3
256
 
A       5
257
 
B       5
 
210
SELECT a FROM t1 GROUP BY binary a;
 
211
a
 
212
NULL
 
213
A
 
214
B
 
215
a
 
216
b
 
217
SELECT a,count(*) FROM t1 GROUP BY binary a;
 
218
a       count(*)
 
219
NULL    3
 
220
A       4
 
221
B       4
 
222
a       1
 
223
b       1
 
224
SELECT binary a FROM t1 GROUP BY 1;
 
225
binary a 
 
226
NULL
 
227
A
 
228
B
 
229
a
 
230
b
 
231
SELECT binary a,count(*) FROM t1 GROUP BY 1;
 
232
binary a        count(*)
 
233
NULL    3
 
234
A       4
 
235
B       4
 
236
a       1
 
237
b       1
 
238
SELECT a FROM t1 GROUP BY a;
 
239
a
 
240
NULL
 
241
A
 
242
B
 
243
SELECT a,count(*) FROM t1 GROUP BY a;
 
244
a       count(*)
 
245
NULL    3
 
246
A       5
 
247
B       5
 
248
SELECT a FROM t1 GROUP BY binary a;
 
249
a
 
250
NULL
 
251
A
 
252
B
 
253
a
 
254
b
 
255
SELECT a,count(*) FROM t1 GROUP BY binary a;
 
256
a       count(*)
 
257
NULL    3
 
258
A       4
 
259
B       4
 
260
a       1
 
261
b       1
 
262
SELECT binary a FROM t1 GROUP BY 1;
 
263
binary a 
 
264
NULL
 
265
A
 
266
B
 
267
a
 
268
b
 
269
SELECT binary a,count(*) FROM t1 GROUP BY 1;
 
270
binary a        count(*)
 
271
NULL    3
 
272
A       4
 
273
B       4
 
274
a       1
 
275
b       1
258
276
drop table t1;
259
277
CREATE TABLE t1 (
260
278
`a` char(193) default NULL,
326
344
3       134     ***
327
345
4       185     ****
328
346
drop table t1;
329
 
CREATE TEMPORARY TABLE t1 (
 
347
CREATE TABLE t1 (
330
348
pid int NOT NULL default '0',
331
349
c1id int default NULL,
332
350
c2id int default NULL,
335
353
UNIQUE KEY pid (pid,value)
336
354
) ENGINE=MyISAM;
337
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);
338
 
CREATE TEMPORARY TABLE t2 (
 
356
CREATE TABLE t2 (
339
357
id int NOT NULL default '0',
340
358
active enum('Yes','No') NOT NULL default 'Yes',
341
359
PRIMARY KEY  (id)
543
561
primary key (a,b(132),c,d),
544
562
key a (a,b)
545
563
);
 
564
Warnings:
 
565
Warning 1071    Specified key was too long; max key length is 767 bytes
546
566
insert into t2 select 
547
567
x3.a,  -- 3
548
568
concat('val-', x3.a + 3*x4.a), -- 12
552
572
delete from t2  where a = 2 and b = 'val-2' order by a,b,c,d limit 30;
553
573
explain select c from t2 where a = 2 and b = 'val-2' group by c;
554
574
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
555
 
1       SIMPLE  t2      #       PRIMARY,a       a       #       const,const     #       #
 
575
1       SIMPLE  t2      ref     PRIMARY,a       a       770     const,const     36      Using where; Using index
556
576
select c from t2 where a = 2 and b = 'val-2' group by c;
557
577
c
558
578
val-74
895
915
f1      f2
896
916
select * from t1 group by f1, f2;
897
917
f1      f2
898
 
select t1.f1,t.* from t1, t1 t where t1.f1 >= 0 group by 1;
 
918
select t1.f1,t.* from t1, t1 t group by 1;
899
919
f1      f1      f2
900
920
drop table t1;
901
921
CREATE TABLE t1(
1376
1396
EXPLAIN SELECT 1 FROM t1 WHERE a IN
1377
1397
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
1378
1398
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1379
 
1       PRIMARY t1      index   NULL    PRIMARY 4       NULL    144     Using where; Using index
1380
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    144     
 
1399
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    144     Start temporary
 
1400
1       PRIMARY t1      eq_ref  PRIMARY,i2      PRIMARY 4       test.t1.a       1       Using index; End temporary
1381
1401
CREATE TABLE t2 (a INT, b INT, KEY(a));
1382
1402
INSERT INTO t2 VALUES (1, 1), (2, 2), (3,3), (4,4);
1383
1403
EXPLAIN SELECT a, SUM(b) FROM t2 GROUP BY a LIMIT 2;
1389
1409
EXPLAIN SELECT 1 FROM t2 WHERE a IN
1390
1410
(SELECT a FROM t1 USE INDEX (i2) IGNORE INDEX (i2));
1391
1411
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1392
 
1       PRIMARY t2      index   NULL    a       5       NULL    4       Using where; Using index
1393
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    144     
 
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
1394
1414
DROP TABLE t1, t2;
1395
1415
CREATE TABLE t1(
1396
1416
a INT, 
1482
1502
NULL
1483
1503
1
1484
1504
2
1485
 
DROP TABLE t1,t2;
 
1505
DROP TABLE t1;
1486
1506
CREATE TABLE t1 ( a INT, b INT );
1487
1507
SELECT b c, (SELECT a FROM t1 WHERE b = c)
1488
1508
FROM t1;