1790
1785
# Test of bug with SUM(CASE...)
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;
1788
CREATE TABLE t1 (gvid int unsigned default NULL, hmid int unsigned default NULL, volid int unsigned default NULL, mmid int unsigned default NULL, hdid int unsigned default NULL, fsid int unsigned default NULL, ctid int unsigned default NULL, dtid int unsigned default NULL, cost int unsigned default NULL, performance int unsigned default NULL, serialnumber bigint unsigned default NULL, monitored tinyint unsigned default '1', removed tinyint unsigned default '0', target tinyint unsigned 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
1789
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;
1790
CREATE TABLE t2 ( hmid int unsigned default NULL, volid int unsigned default NULL, sampletid smallint unsigned default NULL, sampletime datetime default NULL, samplevalue bigint unsigned default NULL, KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
1796
1791
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 ER_INVALID_DATETIME_VALUE # bad datetime
1792
# Disable PS becasue we get more warnings from PS than from normal execution
1793
--disable_ps_protocol
1798
1794
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
1799
1796
# Testing the same select with NULL's instead of invalid datetime values
1800
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 >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1801
1798
DROP TABLE t1,t2;
1864
1859
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
1867
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;
1862
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;
1868
1863
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);
1869
CREATE TEMPORARY TABLE t2 ( id int NOT NULL auto_increment, PRIMARY KEY (id)) ENGINE=MyISAM;
1864
CREATE TABLE t2 ( id int NOT NULL auto_increment, PRIMARY KEY (id)) ENGINE=MyISAM;
1870
1865
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
1871
1866
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0 order by t1.id LIMIT 0, 5;
1872
1867
drop table t1,t2;
2480
2475
# for base tables, search all nested join operands of natural joins.
2483
CREATE TABLE t1 (`id` int);
2484
CREATE TABLE t2 (`id` int);
2485
CREATE TABLE t3 (`id` int);
2478
CREATE TABLE t1 (`id` TINYINT);
2479
CREATE TABLE t2 (`id` TINYINT);
2480
CREATE TABLE t3 (`id` TINYINT);
2486
2481
INSERT INTO t1 VALUES (1),(2),(3);
2487
2482
INSERT INTO t2 VALUES (2);
2488
2483
INSERT INTO t3 VALUES (3);
2489
--error ER_NON_UNIQ_ERROR
2490
2485
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2491
--error ER_NON_UNIQ_ERROR
2492
2487
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id);
2493
--error ER_NON_UNIQ_ERROR
2494
2489
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2495
--error ER_NON_UNIQ_ERROR
2496
2491
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
2498
2493
drop table t1, t2, t3;
2588
2583
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2589
2584
(4,'2005-10-01'),(5,'2005-12-30');
2590
2585
# should return all records
2591
--error ER_INVALID_DATE_VALUE # Bad date
2592
2586
select * from t1 where f2 >= 0 order by f2;
2593
--error ER_INVALID_DATETIME_VALUE # Bad date
2594
2587
select * from t1 where f2 >= '0000-00-00' order by f2;
2595
2588
# should return 4,5
2596
--error ER_INVALID_DATETIME_VALUE # Bad date
2597
2589
select * from t1 where f2 >= '2005-09-31' order by f2;
2598
--error ER_INVALID_DATETIME_VALUE # Bad date
2599
2590
select * from t1 where f2 >= '2005-09-3a' order by f2;
2600
--error ER_INVALID_DATETIME_VALUE # Bad date
2591
# should return 1,2,3
2601
2592
select * from t1 where f2 <= '2005-09-31' order by f2;
2602
--error ER_INVALID_DATETIME_VALUE # Bad date
2603
2593
select * from t1 where f2 <= '2005-09-3a' order by f2;
3266
3252
# Bug #30666: Incorrect order when using range conditions on 2 tables or more
3269
CREATE TABLE t1 (c11 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
3270
CREATE TABLE t2 (c21 INT NOT NULL,
3255
CREATE TABLE t1 (c11 INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
3256
CREATE TABLE t2 (c21 INT UNSIGNED NOT NULL,
3271
3257
c22 INT DEFAULT NULL,
3272
3258
KEY(c21, c22));
3273
CREATE TABLE t3 (c31 INT NOT NULL DEFAULT 0,
3259
CREATE TABLE t3 (c31 INT UNSIGNED NOT NULL DEFAULT 0,
3274
3260
c32 INT DEFAULT NULL,
3275
3261
c33 INT NOT NULL,
3262
c34 INT UNSIGNED DEFAULT 0,
3277
3263
KEY (c33, c34, c32));
3279
3265
INSERT INTO t1 values (),(),(),(),();
3280
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a CROSS JOIN t1 b;
3266
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a, t1 b;
3281
3267
INSERT INTO t3 VALUES (1, 1, 1, 0),
3302
3288
# Bug#31800: Date comparison fails with timezone and slashes for greater
3303
3289
# than comparison
3306
# @TODO Commenting all str_to_date out for now...should move to a plugin.
3308
3292
# On DATETIME-like literals with trailing garbage, BETWEEN fudged in a
3309
3293
# DATETIME comparator, while greater/less-than used bin-string comparisons.
3310
3294
# Should correctly be compared as DATE or DATETIME, but throw a warning:
3312
#select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3313
# and '2007/10/20 00:00:00 GMT';
3314
#select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3315
#select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
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';
3317
3301
# We have all we need -- and trailing garbage:
3318
3302
# (leaving out a leading zero in first example to prove it's a
3319
3303
# value-comparison, not a string-comparison!)
3320
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3321
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3322
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3323
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
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';
3324
3308
# no time at all:
3325
#select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3309
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3326
3310
# partial time:
3327
#select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
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';
3328
3312
# fail, different second part:
3329
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
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';
3330
3314
# correct syntax, no trailing nonsense -- this one must throw no warning:
3331
#select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3315
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3332
3316
# no warning, but failure (different hour parts):
3333
#select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3317
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3335
#select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3319
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3336
3320
# succeed, but warn for "trailing garbage" (":34"):
3337
#select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3321
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3338
3322
# invalid date (Feb 30) succeeds
3339
#select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3323
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3340
3324
# 0-day for both, just works in default SQL mode.
3341
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3325
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3342
3326
# 0-day, succeed
3343
#select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3344
# and '2007/10/20 00:00:00';
3345
#select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3346
#select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3347
#select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3348
#select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3349
#select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
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') = '';
3351
#select str_to_date('1','%Y-%m-%d') = '1';
3352
#select str_to_date('1','%Y-%m-%d') = '1';
3353
#select str_to_date('','%Y-%m-%d') = '';
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') = '';
3355
3339
# these three should work!
3356
#select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3357
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3358
#select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
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;
3359
3343
###########################################################################
3455
3439
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
3456
3440
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
3460
# MySQL Bug#33546: Slowdown on re-evaluation of constant expressions.
3462
CREATE TABLE t1 (a INT);
3463
INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3464
CREATE TABLE t2 (b INT);
3465
INSERT INTO t2 VALUES (2);
3466
SELECT * FROM t1 WHERE a = 1 + 1;
3467
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 1 + 1;
3468
SELECT * FROM t1 HAVING a = 1 + 1;
3469
EXPLAIN EXTENDED SELECT * FROM t1 HAVING a = 1 + 1;
3470
SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3471
EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a = b + (1 + 1);
3472
SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3473
EXPLAIN EXTENDED SELECT * FROM t2 LEFT JOIN t1 ON a = b + 1;
3474
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > UNIX_TIMESTAMP('2009-03-10 00:00:00');