~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/select.test

  • Committer: Brian Aker
  • Date: 2009-05-15 17:06:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1023.
  • Revision ID: brian@gaz-20090515170635-croy1u63a3gqdn9n
Dead convert functions for character sets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#
46
46
 
47
47
--disable_query_log
 
48
begin;
48
49
INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat','');
49
50
INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W');
50
51
INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring','');
1244
1245
INSERT INTO t2 VALUES (1191,068504,00,'bonfire','corresponds','positively','');
1245
1246
INSERT INTO t2 VALUES (1192,068305,00,'Colombo','hardware','colicky','');
1246
1247
INSERT INTO t2 VALUES (1193,000000,00,'nondecreasing','implant','thrillingly','');
 
1248
commit;
1247
1249
--enable_query_log
1248
1250
 
1249
1251
#
1332
1334
# If the like starts with a certain letter key will be used.
1333
1335
#
1334
1336
 
 
1337
--sorted_result
1335
1338
select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%';
1336
1339
select fld3 from t2 where fld3 like "L%" and fld3 = "ok";
1337
1340
select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly");
1348
1351
select distinct companynr from t2;
1349
1352
select distinct companynr from t2 order by companynr;
1350
1353
select distinct companynr from t2 order by companynr desc;
 
1354
--sorted_result
1351
1355
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
1352
1356
 
1353
1357
select distinct fld3 from t2 where companynr = 34 order by fld3;
 
1358
# PBXT: because there is no ORDER BY with a LIMIT, these
 
1359
# statements return different results to those from innodb
 
1360
--sorted_result
1354
1361
select distinct fld3 from t2 limit 10;
1355
1362
select distinct fld3 from t2 having fld3 like "A%" limit 10;
1356
1363
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
1357
1364
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
1358
1365
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
 
1366
--sorted_result
1359
1367
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
1360
1368
 
1361
1369
# make a big table.
1411
1419
 
1412
1420
# big table done
1413
1421
 
1414
 
SET SQL_BIG_TABLES=1;
1415
1422
select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10;
1416
 
SET SQL_BIG_TABLES=0;
1417
1423
select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10;
1418
1424
select distinct fld5 from t2 limit 10;
1419
1425
 
1422
1428
#
1423
1429
 
1424
1430
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
1425
 
SET SQL_BIG_TABLES=1; # Force use of MyISAM
1426
1431
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
1427
 
SET SQL_BIG_TABLES=0;
1428
1432
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
1429
1433
 
1430
1434
#
1474
1478
# Search with a constant table and several rows from another table
1475
1479
#
1476
1480
 
 
1481
--sorted_result
1477
1482
select fld3,period from t2,t1 where companynr*10 = 37*10;
1478
1483
 
1479
1484
#
1789
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);
1790
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;
1791
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);
1792
 
# Disable PS becasue we get more warnings from PS than from normal execution
1793
 
--disable_ps_protocol
 
1797
--error 1686 # bad datetime
1794
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;
1795
 
--enable_ps_protocol
1796
1799
# Testing the same select with NULL's instead of invalid datetime values
1797
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;
1798
1801
DROP TABLE t1,t2;
1831
1834
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
1832
1835
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
1833
1836
# inner join on
 
1837
--sorted_result
1834
1838
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
1835
1839
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
1836
1840
# inner join using
2169
2173
create table t1 (f1 int not null auto_increment primary key, f2 varchar(10));
2170
2174
create table t11 like t1;
2171
2175
insert into t1 values(1,""),(2,"");
2172
 
--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
 
2176
--replace_column 3 X 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X
2173
2177
show table status like 't1%';
2174
2178
select 123 as a from t1 where f1 is null;
2175
2179
drop table t1,t11;
2583
2587
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2584
2588
  (4,'2005-10-01'),(5,'2005-12-30');
2585
2589
# should return all records
 
2590
--error 1686 # Bad date
2586
2591
select * from t1 where f2 >= 0            order by f2;
 
2592
--error 1686 # Bad date
2587
2593
select * from t1 where f2 >= '0000-00-00' order by f2;
2588
2594
# should return 4,5
 
2595
--error 1686 # Bad date
2589
2596
select * from t1 where f2 >= '2005-09-31' order by f2;
 
2597
--error 1686 # Bad date
2590
2598
select * from t1 where f2 >= '2005-09-3a' order by f2;
2591
 
# should return 1,2,3
 
2599
--error 1686 # Bad date
2592
2600
select * from t1 where f2 <= '2005-09-31' order by f2;
 
2601
--error 1686 # Bad date
2593
2602
select * from t1 where f2 <= '2005-09-3a' order by f2;
2594
2603
drop table t1;
2595
2604
 
2975
2984
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null IS NULL;
2976
2985
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
2977
2986
 
 
2987
# PBXT: does not return a consistent row count
 
2988
--replace_column 9 #
2978
2989
EXPLAIN SELECT * FROM t1
2979
2990
  WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
 
2991
--replace_column 9 #
2980
2992
EXPLAIN SELECT * FROM t1
2981
2993
  WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
 
2994
--replace_column 9 #
2982
2995
EXPLAIN SELECT * FROM t1
2983
2996
  WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
2984
2997
 
3288
3301
# Bug#31800: Date comparison fails with timezone and slashes for greater
3289
3302
#            than comparison
3290
3303
#
3291
 
 
 
3304
#
 
3305
# @TODO Commenting all str_to_date out for now...should move to a plugin.
 
3306
#
3292
3307
# On DATETIME-like literals with trailing garbage, BETWEEN fudged in a
3293
3308
# DATETIME comparator, while greater/less-than used bin-string comparisons.
3294
3309
# Should correctly be compared as DATE or DATETIME, but throw a warning:
3295
3310
 
3296
 
select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3297
 
                                                and '2007/10/20 00:00:00 GMT';
3298
 
select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3299
 
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
 
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';
3300
3315
 
3301
3316
# We have all we need -- and trailing garbage:
3302
3317
# (leaving out a leading zero in first example to prove it's a
3303
3318
# value-comparison, not a string-comparison!)
3304
 
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3305
 
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3306
 
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3307
 
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
 
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';
3308
3323
# no time at all:
3309
 
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
 
3324
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3310
3325
# partial time:
3311
 
select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
 
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';
3312
3327
# fail, different second part:
3313
 
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
 
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';
3314
3329
# correct syntax, no trailing nonsense -- this one must throw no warning:
3315
 
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
 
3330
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3316
3331
# no warning, but failure (different hour parts):
3317
 
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
 
3332
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3318
3333
# succeed:
3319
 
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
 
3334
#select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3320
3335
# succeed, but warn for "trailing garbage" (":34"):
3321
 
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
 
3336
#select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3322
3337
# invalid date (Feb 30) succeeds
3323
 
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
 
3338
#select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3324
3339
# 0-day for both, just works in default SQL mode.
3325
 
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
 
3340
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3326
3341
# 0-day, succeed
3327
 
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3328
 
                                                and '2007/10/20 00:00:00';
3329
 
select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3330
 
select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3331
 
select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3332
 
select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3333
 
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
 
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') = '';
3334
3349
 
3335
 
select str_to_date('1','%Y-%m-%d') = '1';
3336
 
select str_to_date('1','%Y-%m-%d') = '1';
3337
 
select str_to_date('','%Y-%m-%d') = '';
 
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') = '';
3338
3353
 
3339
3354
# these three should work!
3340
 
select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3341
 
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3342
 
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
 
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;
3343
3358
###########################################################################
3344
3359
 
3345
3360
--echo