1791
1788
# Test of bug with SUM(CASE...)
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;
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;
1795
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);
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;
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;
1797
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);
1798
--error ER_INVALID_DATETIME_VALUE # bad datetime
1795
--error 1686 # bad datetime
1799
1796
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
1797
# Testing the same select with NULL's instead of invalid datetime values
1801
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 >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
1865
1861
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
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;
1864
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
1865
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;
1866
CREATE TABLE t2 ( id int NOT NULL auto_increment, PRIMARY KEY (id)) ENGINE=MyISAM;
1871
1867
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
1872
1868
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0 order by t1.id LIMIT 0, 5;
1873
1869
drop table t1,t2;
2487
2483
INSERT INTO t1 VALUES (1),(2),(3);
2488
2484
INSERT INTO t2 VALUES (2);
2489
2485
INSERT INTO t3 VALUES (3);
2490
--error ER_NON_UNIQ_ERROR
2491
2487
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
2493
2489
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
2495
2491
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2496
--error ER_NON_UNIQ_ERROR
2497
2493
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
2499
2495
drop table t1, t2, t3;
2589
2585
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2590
2586
(4,'2005-10-01'),(5,'2005-12-30');
2591
2587
# should return all records
2592
--error ER_INVALID_DATE_VALUE # Bad date
2588
--error 1686 # Bad date
2593
2589
select * from t1 where f2 >= 0 order by f2;
2594
--error ER_INVALID_DATETIME_VALUE # Bad date
2590
--error 1686 # Bad date
2595
2591
select * from t1 where f2 >= '0000-00-00' order by f2;
2596
2592
# should return 4,5
2597
--error ER_INVALID_DATETIME_VALUE # Bad date
2593
--error 1686 # Bad date
2598
2594
select * from t1 where f2 >= '2005-09-31' order by f2;
2599
--error ER_INVALID_DATETIME_VALUE # Bad date
2595
--error 1686 # Bad date
2600
2596
select * from t1 where f2 >= '2005-09-3a' order by f2;
2601
--error ER_INVALID_DATETIME_VALUE # Bad date
2597
--error 1686 # Bad date
2602
2598
select * from t1 where f2 <= '2005-09-31' order by f2;
2603
--error ER_INVALID_DATETIME_VALUE # Bad date
2599
--error 1686 # Bad date
2604
2600
select * from t1 where f2 <= '2005-09-3a' order by f2;
2720
2716
create table t1 (a int);
2721
2717
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2722
2718
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;
2719
insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C;
2724
2720
analyze table t2;
2725
2721
select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
3456
3452
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
3457
3453
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
3461
# MySQL Bug#33546: Slowdown on re-evaluation of constant expressions.
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');