~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/select.test

  • Committer: Lee Bieber
  • Date: 2008-11-21 21:52:58 UTC
  • mto: (590.2.7 devel)
  • mto: This revision was merged to the branch mainline in revision 603.
  • Revision ID: lb4072@soe-t2000-8-20081121215258-s86ky54w5r676o4q
changes to get build working on Solaris

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#
46
46
 
47
47
--disable_query_log
48
 
begin;
49
48
INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat','');
50
49
INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W');
51
50
INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring','');
1245
1244
INSERT INTO t2 VALUES (1191,068504,00,'bonfire','corresponds','positively','');
1246
1245
INSERT INTO t2 VALUES (1192,068305,00,'Colombo','hardware','colicky','');
1247
1246
INSERT INTO t2 VALUES (1193,000000,00,'nondecreasing','implant','thrillingly','');
1248
 
commit;
1249
1247
--enable_query_log
1250
1248
 
1251
1249
#
1500
1498
# We need another table for join stuff..
1501
1499
#
1502
1500
 
1503
 
create temporary table t4 (
 
1501
create table t4 (
1504
1502
  companynr int NOT NULL default '0',
1505
1503
  companyname char(30) NOT NULL default '',
1506
1504
  PRIMARY KEY (companynr),
1507
1505
  UNIQUE KEY companyname(companyname)
1508
 
) ENGINE=MyISAM COMMENT='companynames';
 
1506
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
1509
1507
 
1510
1508
--disable_query_log
1511
1509
INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1');
1762
1760
show tables from test like "t?";
1763
1761
# We mask out the Privileges column because it differs with embedded server
1764
1762
--replace_column 8 #
1765
 
show columns from t2;
1766
 
--replace_column 8 #
1767
 
show columns from t2 from test like 'f%';
1768
 
--replace_column 8 #
1769
 
show columns from t2 from test like 's%';
 
1763
show full columns from t2;
 
1764
--replace_column 8 #
 
1765
show full columns from t2 from test like 'f%';
 
1766
--replace_column 8 #
 
1767
show full columns from t2 from test like 's%';
1770
1768
#show keys from t2;
1771
1769
 
1772
1770
drop table t4, t3, t2, t1;
1790
1788
# Test of bug with SUM(CASE...)
1791
1789
#
1792
1790
 
1793
 
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;
 
1791
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;
1794
1792
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);
1795
 
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;
 
1793
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;
1796
1794
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
1797
 
--error 1686 # bad datetime
 
1795
# Disable PS becasue we get more warnings from PS than from normal execution
 
1796
--disable_ps_protocol
1798
1797
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;
 
1798
--enable_ps_protocol
1799
1799
# Testing the same select with NULL's instead of invalid datetime values
1800
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;
1801
1801
DROP TABLE t1,t2;
1863
1863
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
1864
1864
drop table t1;
1865
1865
 
1866
 
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;
1867
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);
1868
 
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;
1869
1869
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
1870
1870
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
1871
1871
drop table t1,t2;
1923
1923
# Covering index is mentioned in EXPLAIN output for const tables (bug #5333)
1924
1924
#
1925
1925
 
1926
 
CREATE TEMPORARY TABLE t1 (
 
1926
CREATE TABLE t1 (
1927
1927
  i int NOT NULL default '0',
1928
1928
  c char(10) NOT NULL default '',
1929
1929
  PRIMARY KEY  (i),
2173
2173
create table t1 (f1 int not null auto_increment primary key, f2 varchar(10));
2174
2174
create table t11 like t1;
2175
2175
insert into t1 values(1,""),(2,"");
2176
 
--replace_column 1 #  6 # 7 # 8 # 9 # 10 #
 
2176
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
2177
2177
show table status like 't1%';
2178
2178
select 123 as a from t1 where f1 is null;
2179
2179
drop table t1,t11;
2320
2320
# 1. has integer type, 
2321
2321
# 2. can be used with the "@@name" syntax
2322
2322
# 3. available in every server build
2323
 
INSERT INTO t1 VALUES(@@server_id);
2324
 
INSERT INTO t2 VALUES(@@server_id);
 
2323
INSERT INTO t1 VALUES(@@connect_timeout);
 
2324
INSERT INTO t2 VALUES(@@connect_timeout);
2325
2325
 
2326
2326
# We only need to ensure 1 row is returned to validate the results
2327
2327
--replace_column 1 X 2 X
2328
 
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);
2329
2329
 
2330
2330
DROP TABLE t1, t2;
2331
2331
 
2335
2335
# Test for bug #6474
2336
2336
#
2337
2337
 
2338
 
CREATE TEMPORARY TABLE t1 ( 
 
2338
CREATE TABLE t1 ( 
2339
2339
K2C4 varchar(4) collate utf8_bin NOT NULL default '', 
2340
2340
K4N4 varchar(4) collate utf8_bin NOT NULL default '0000', 
2341
2341
F2I4 int NOT NULL default '0' 
2388
2388
# Bug#9799
2389
2389
#
2390
2390
 
2391
 
create temporary table t1 (s1 int) engine=myisam;
 
2391
create table t1 (s1 int) engine=myisam;
2392
2392
insert into t1 values (0);
2393
2393
select avg(distinct s1) from t1 group by s1 with rollup;
2394
2394
drop table t1;
2587
2587
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2588
2588
  (4,'2005-10-01'),(5,'2005-12-30');
2589
2589
# should return all records
2590
 
--error 1686 # Bad date
2591
2590
select * from t1 where f2 >= 0            order by f2;
2592
 
--error 1686 # Bad date
2593
2591
select * from t1 where f2 >= '0000-00-00' order by f2;
2594
2592
# should return 4,5
2595
 
--error 1686 # Bad date
2596
2593
select * from t1 where f2 >= '2005-09-31' order by f2;
2597
 
--error 1686 # Bad date
2598
2594
select * from t1 where f2 >= '2005-09-3a' order by f2;
2599
 
--error 1686 # Bad date
 
2595
# should return 1,2,3
2600
2596
select * from t1 where f2 <= '2005-09-31' order by f2;
2601
 
--error 1686 # Bad date
2602
2597
select * from t1 where f2 <= '2005-09-3a' order by f2;
2603
2598
drop table t1;
2604
2599
 
3301
3296
# Bug#31800: Date comparison fails with timezone and slashes for greater
3302
3297
#            than comparison
3303
3298
#
3304
 
#
3305
 
# @TODO Commenting all str_to_date out for now...should move to a plugin.
3306
 
#
 
3299
 
3307
3300
# On DATETIME-like literals with trailing garbage, BETWEEN fudged in a
3308
3301
# DATETIME comparator, while greater/less-than used bin-string comparisons.
3309
3302
# Should correctly be compared as DATE or DATETIME, but throw a warning:
3310
3303
 
3311
 
#select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3312
 
#                                                and '2007/10/20 00:00:00 GMT';
3313
 
#select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3314
 
#select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
 
3304
select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
 
3305
                                                and '2007/10/20 00:00:00 GMT';
 
3306
select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
 
3307
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
3315
3308
 
3316
3309
# We have all we need -- and trailing garbage:
3317
3310
# (leaving out a leading zero in first example to prove it's a
3318
3311
# value-comparison, not a string-comparison!)
3319
 
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3320
 
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3321
 
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3322
 
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
 
3312
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
 
3313
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
 
3314
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
 
3315
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
3323
3316
# no time at all:
3324
 
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
 
3317
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3325
3318
# partial time:
3326
 
#select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
 
3319
select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3327
3320
# fail, different second part:
3328
 
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
 
3321
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3329
3322
# correct syntax, no trailing nonsense -- this one must throw no warning:
3330
 
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
 
3323
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3331
3324
# no warning, but failure (different hour parts):
3332
 
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
 
3325
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3333
3326
# succeed:
3334
 
#select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
 
3327
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3335
3328
# succeed, but warn for "trailing garbage" (":34"):
3336
 
#select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
 
3329
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3337
3330
# invalid date (Feb 30) succeeds
3338
 
#select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
 
3331
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3339
3332
# 0-day for both, just works in default SQL mode.
3340
 
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
 
3333
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3341
3334
# 0-day, succeed
3342
 
#select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3343
 
#                                                and '2007/10/20 00:00:00';
3344
 
#select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3345
 
#select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3346
 
#select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3347
 
#select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3348
 
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
 
3335
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
 
3336
                                                and '2007/10/20 00:00:00';
 
3337
select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
 
3338
select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
 
3339
select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
 
3340
select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
 
3341
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
3349
3342
 
3350
 
#select str_to_date('1','%Y-%m-%d') = '1';
3351
 
#select str_to_date('1','%Y-%m-%d') = '1';
3352
 
#select str_to_date('','%Y-%m-%d') = '';
 
3343
select str_to_date('1','%Y-%m-%d') = '1';
 
3344
select str_to_date('1','%Y-%m-%d') = '1';
 
3345
select str_to_date('','%Y-%m-%d') = '';
3353
3346
 
3354
3347
# these three should work!
3355
 
#select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3356
 
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3357
 
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
 
3348
select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
 
3349
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
 
3350
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
3358
3351
###########################################################################
3359
3352
 
3360
3353
--echo
3454
3447
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
3455
3448
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
3456
3449
DROP TABLE t1;
3457
 
 
3458
 
#
3459
 
# MySQL Bug#33546: Slowdown on re-evaluation of constant expressions.
3460
 
#
3461
 
CREATE TABLE t1 (a INT);
3462
 
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3463
 
CREATE TABLE t2 (b INT);
3464
 
INSERT INTO t2 VALUES (2);
3465
 
SELECT * FROM t1 WHERE a = 1 + 1;
3466
 
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 1 + 1;
3467
 
SELECT * FROM t1 HAVING a = 1 + 1;
3468
 
EXPLAIN EXTENDED SELECT * FROM t1 HAVING a = 1 + 1;
3469
 
SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3470
 
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3471
 
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3472
 
EXPLAIN EXTENDED SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3473
 
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > UNIX_TIMESTAMP('2009-03-10 00:00:00');
3474
 
 
3475
 
DROP TABLE t1, t2;