~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/select.test

  • 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:
1297
1297
# The next should give an error
1298
1298
#
1299
1299
 
1300
 
#-- error ER_KEY_DOES_NOT_EXITS
 
1300
#-- error 1176
1301
1301
#explain select fld3 from t2 ignore index (fld3,not_used);
1302
 
#-- error ER_KEY_DOES_NOT_EXITS
 
1302
#-- error 1176
1303
1303
#explain select fld3 from t2 use index (not_used);
1304
1304
 
1305
1305
#
1500
1500
# We need another table for join stuff..
1501
1501
#
1502
1502
 
1503
 
create temporary table t4 (
 
1503
create table t4 (
1504
1504
  companynr int NOT NULL default '0',
1505
1505
  companyname char(30) NOT NULL default '',
1506
1506
  PRIMARY KEY (companynr),
1507
1507
  UNIQUE KEY companyname(companyname)
1508
 
) ENGINE=MyISAM COMMENT='companynames';
 
1508
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
1509
1509
 
1510
1510
--disable_query_log
1511
1511
INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1');
1534
1534
# Full join (same alias)
1535
1535
#
1536
1536
 
1537
 
select * from t1 CROSS JOIN t1 t12;
1538
 
--sorted_result
 
1537
select * from t1,t1 t12;
1539
1538
select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505;
1540
1539
 
1541
1540
#
1763
1762
show tables from test like "t?";
1764
1763
# We mask out the Privileges column because it differs with embedded server
1765
1764
--replace_column 8 #
1766
 
show columns from t2;
1767
 
--replace_column 8 #
1768
 
show columns from t2 from test like 'f%';
1769
 
--replace_column 8 #
1770
 
show columns from t2 from test like 's%';
 
1765
show full columns from t2;
 
1766
--replace_column 8 #
 
1767
show full columns from t2 from test like 'f%';
 
1768
--replace_column 8 #
 
1769
show full columns from t2 from test like 's%';
1771
1770
#show keys from t2;
1772
1771
 
1773
1772
drop table t4, t3, t2, t1;
1791
1790
# Test of bug with SUM(CASE...)
1792
1791
#
1793
1792
 
1794
 
CREATE TEMPORARY TABLE t1 (gvid int default NULL,  hmid int default NULL,  volid int default NULL,  mmid int default NULL,  hdid int default NULL,  fsid int default NULL,  ctid int default NULL,  dtid int default NULL,  cost int default NULL,  performance int default NULL,  serialnumber bigint default NULL,  monitored int default '1',  removed int default '0',  target int default '0',  dt_modified timestamp NOT NULL,  name varchar(255) default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
 
1793
CREATE TABLE t1 (gvid int default NULL,  hmid int default NULL,  volid int default NULL,  mmid int default NULL,  hdid int default NULL,  fsid int default NULL,  ctid int default NULL,  dtid int default NULL,  cost int default NULL,  performance int default NULL,  serialnumber bigint default NULL,  monitored int default '1',  removed int default '0',  target int default '0',  dt_modified timestamp NOT NULL,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
1795
1794
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
1796
 
CREATE TEMPORARY TABLE t2 (  hmid int default NULL,  volid int default NULL,  sampletid int default NULL,  sampletime datetime default NULL,  samplevalue bigint default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
 
1795
CREATE TABLE t2 (  hmid int default NULL,  volid int default NULL,  sampletid int default NULL,  sampletime datetime default NULL,  samplevalue bigint default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
1797
1796
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
1798
 
--error ER_INVALID_DATETIME_VALUE # bad datetime
 
1797
--error 1686 # bad datetime
1799
1798
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1800
1799
# Testing the same select with NULL's instead of invalid datetime values
1801
1800
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1829
1828
insert into t1 values ();
1830
1829
insert into t1 values ();
1831
1830
# ,
1832
 
--sorted_result
1833
1831
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
1834
1832
select * from t1, (t1 as t2 left join t1 as t3 using (a));
1835
1833
# stright_join
1865
1863
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
1866
1864
drop table t1;
1867
1865
 
1868
 
CREATE TEMPORARY TABLE t1 (  aa char(2),  id int NOT NULL auto_increment,  t2_id int NOT NULL default '0',  PRIMARY KEY  (id),  KEY replace_id (t2_id)) ENGINE=MyISAM;
 
1866
CREATE TABLE t1 (  aa char(2),  id int NOT NULL auto_increment,  t2_id int NOT NULL default '0',  PRIMARY KEY  (id),  KEY replace_id (t2_id)) ENGINE=MyISAM;
1869
1867
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);
1870
 
CREATE TEMPORARY TABLE t2 ( id int NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
 
1868
CREATE TABLE t2 ( id int NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
1871
1869
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
1872
1870
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
1873
1871
drop table t1,t2;
1925
1923
# Covering index is mentioned in EXPLAIN output for const tables (bug #5333)
1926
1924
#
1927
1925
 
1928
 
CREATE TEMPORARY TABLE t1 (
 
1926
CREATE TABLE t1 (
1929
1927
  i int NOT NULL default '0',
1930
1928
  c char(10) NOT NULL default '',
1931
1929
  PRIMARY KEY  (i),
1991
1989
create table t1 (a int);
1992
1990
select all all * from t1;
1993
1991
select distinct distinct * from t1;
1994
 
--error ER_WRONG_USAGE
 
1992
--error 1221
1995
1993
select all distinct * from t1;
1996
 
--error ER_WRONG_USAGE
 
1994
--error 1221
1997
1995
select distinct all * from t1;
1998
1996
drop table t1;
1999
1997
 
2175
2173
create table t1 (f1 int not null auto_increment primary key, f2 varchar(10));
2176
2174
create table t11 like t1;
2177
2175
insert into t1 values(1,""),(2,"");
2178
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
2176
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
2179
2177
show table status like 't1%';
2180
2178
select 123 as a from t1 where f1 is null;
2181
2179
drop table t1,t11;
2239
2237
INSERT INTO t1 VALUES (2), (3), (1);
2240
2238
 
2241
2239
EXPLAIN SELECT * FROM t1 IGNORE INDEX (idx);
2242
 
--error ER_KEY_DOES_NOT_EXITS
 
2240
--error 1176
2243
2241
EXPLAIN SELECT * FROM t1 IGNORE INDEX (a);
2244
 
--error ER_KEY_DOES_NOT_EXITS
 
2242
--error 1176
2245
2243
EXPLAIN SELECT * FROM t1 FORCE INDEX (a);
2246
2244
 
2247
2245
DROP TABLE t1;
2322
2320
# 1. has integer type, 
2323
2321
# 2. can be used with the "@@name" syntax
2324
2322
# 3. available in every server build
2325
 
INSERT INTO t1 VALUES(@@server_id);
2326
 
INSERT INTO t2 VALUES(@@server_id);
 
2323
INSERT INTO t1 VALUES(@@connect_timeout);
 
2324
INSERT INTO t2 VALUES(@@connect_timeout);
2327
2325
 
2328
2326
# We only need to ensure 1 row is returned to validate the results
2329
2327
--replace_column 1 X 2 X
2330
 
SELECT * FROM t1 JOIN t2 ON t1.c0 = t2.c0 WHERE (t1.c0 <=> @@server_id);
 
2328
SELECT * FROM t1 JOIN t2 ON t1.c0 = t2.c0 WHERE (t1.c0 <=> @@connect_timeout);
2331
2329
 
2332
2330
DROP TABLE t1, t2;
2333
2331
 
2337
2335
# Test for bug #6474
2338
2336
#
2339
2337
 
2340
 
CREATE TEMPORARY TABLE t1 ( 
 
2338
CREATE TABLE t1 ( 
2341
2339
K2C4 varchar(4) collate utf8_bin NOT NULL default '', 
2342
2340
K4N4 varchar(4) collate utf8_bin NOT NULL default '0000', 
2343
2341
F2I4 int NOT NULL default '0' 
2390
2388
# Bug#9799
2391
2389
#
2392
2390
 
2393
 
create temporary table t1 (s1 int) engine=myisam;
 
2391
create table t1 (s1 int) engine=myisam;
2394
2392
insert into t1 values (0);
2395
2393
select avg(distinct s1) from t1 group by s1 with rollup;
2396
2394
drop table t1;
2487
2485
INSERT INTO t1 VALUES (1),(2),(3);
2488
2486
INSERT INTO t2 VALUES (2);
2489
2487
INSERT INTO t3 VALUES (3);
2490
 
--error ER_NON_UNIQ_ERROR
 
2488
-- error 1052
2491
2489
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2492
 
--error ER_NON_UNIQ_ERROR
 
2490
-- error 1052
2493
2491
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id);
2494
 
--error ER_NON_UNIQ_ERROR
 
2492
-- error 1052
2495
2493
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2496
 
--error ER_NON_UNIQ_ERROR
 
2494
-- error 1052
2497
2495
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
2498
2496
 
2499
2497
drop table t1, t2, t3;
2528
2526
select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
2529
2527
# Notice that ',' has lower priority than 'join', thus we have that:
2530
2528
# t1, t2 join t3 <==> t1, (t2 join t3).
2531
 
--error ER_BAD_FIELD_ERROR
 
2529
-- error 1054
2532
2530
select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
2533
2531
select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c);
2534
2532
select * from t1 join t2 join t4 using (c);
2589
2587
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2590
2588
  (4,'2005-10-01'),(5,'2005-12-30');
2591
2589
# should return all records
2592
 
--error ER_INVALID_DATE_VALUE # Bad date
 
2590
--error 1686 # Bad date
2593
2591
select * from t1 where f2 >= 0            order by f2;
2594
 
--error ER_INVALID_DATETIME_VALUE # Bad date
 
2592
--error 1686 # Bad date
2595
2593
select * from t1 where f2 >= '0000-00-00' order by f2;
2596
2594
# should return 4,5
2597
 
--error ER_INVALID_DATETIME_VALUE # Bad date
 
2595
--error 1686 # Bad date
2598
2596
select * from t1 where f2 >= '2005-09-31' order by f2;
2599
 
--error ER_INVALID_DATETIME_VALUE # Bad date
 
2597
--error 1686 # Bad date
2600
2598
select * from t1 where f2 >= '2005-09-3a' order by f2;
2601
 
--error ER_INVALID_DATETIME_VALUE # Bad date
 
2599
--error 1686 # Bad date
2602
2600
select * from t1 where f2 <= '2005-09-31' order by f2;
2603
 
--error ER_INVALID_DATETIME_VALUE # Bad date
 
2601
--error 1686 # Bad date
2604
2602
select * from t1 where f2 <= '2005-09-3a' order by f2;
2605
2603
drop table t1;
2606
2604
 
2689
2687
#
2690
2688
# Bug#15538 unchecked table absense caused server crash.
2691
2689
#
2692
 
--error ER_PARSE_ERROR
 
2690
--error 1064
2693
2691
select * from (select * left join t on f1=f2) tt;
2694
2692
 
2695
2693
#
2720
2718
create table t1 (a int);
2721
2719
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2722
2720
create table t2 (a int, b int, c int, e int, primary key(a,b,c));
2723
 
insert into t2 select A.a, B.a, C.a, C.a from t1 A CROSS JOIN t1 B CROSS JOIN t1 C;
 
2721
insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C;
2724
2722
analyze table t2;
2725
2723
select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
2726
2724
 
3278
3276
                 KEY (c33, c34, c32));
3279
3277
 
3280
3278
INSERT INTO t1 values (),(),(),(),();
3281
 
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a CROSS JOIN t1 b;
 
3279
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a, t1 b;
3282
3280
INSERT INTO t3 VALUES (1, 1, 1, 0), 
3283
3281
                      (2, 2, 0, 0), 
3284
3282
                      (3, 3, 1, 0), 
3456
3454
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
3457
3455
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
3458
3456
DROP TABLE t1;
3459
 
 
3460
 
#
3461
 
# MySQL Bug#33546: Slowdown on re-evaluation of constant expressions.
3462
 
#
3463
 
CREATE TABLE t1 (a INT);
3464
 
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3465
 
CREATE TABLE t2 (b INT);
3466
 
INSERT INTO t2 VALUES (2);
3467
 
SELECT * FROM t1 WHERE a = 1 + 1;
3468
 
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 1 + 1;
3469
 
SELECT * FROM t1 HAVING a = 1 + 1;
3470
 
EXPLAIN EXTENDED SELECT * FROM t1 HAVING a = 1 + 1;
3471
 
SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3472
 
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3473
 
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3474
 
EXPLAIN EXTENDED SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3475
 
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > UNIX_TIMESTAMP('2009-03-10 00:00:00');
3476
 
 
3477
 
DROP TABLE t1, t2;