10
event_date date DEFAULT '0000-00-00' NOT NULL,
11
type int(11) DEFAULT '0' NOT NULL,
12
event_id int(11) DEFAULT '0' NOT NULL,
11
type int DEFAULT '0' NOT NULL,
12
event_id int DEFAULT '0' NOT NULL,
13
13
PRIMARY KEY (event_date,type,event_id)
41
PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
42
YEAR smallint(6) DEFAULT '0' NOT NULL,
43
ISSUE smallint(6) DEFAULT '0' NOT NULL,
44
CLOSED tinyint(4) DEFAULT '0' NOT NULL,
45
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
41
PAPER_ID int DEFAULT '0' NOT NULL,
42
YEAR int DEFAULT '0' NOT NULL,
43
ISSUE int DEFAULT '0' NOT NULL,
44
CLOSED int DEFAULT '0' NOT NULL,
46
46
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
48
48
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
62
62
(3,1999,35,0,'1999-07-12');
63
63
select YEAR,ISSUE from t1 where PAPER_ID=3 and (YEAR>1999 or (YEAR=1999 and ISSUE>28)) order by YEAR,ISSUE;
69
id int(11) NOT NULL auto_increment,
70
parent_id int(11) DEFAULT '0' NOT NULL,
71
level tinyint(4) DEFAULT '0' NOT NULL,
68
id int NOT NULL auto_increment,
69
parent_id int DEFAULT '0' NOT NULL,
70
level int DEFAULT '0' NOT NULL,
73
72
KEY parent_id (parent_id),
116
115
# Problem with binary strings
120
t1ID int(10) unsigned NOT NULL auto_increment,
121
art binary(1) NOT NULL default '',
118
CREATE TEMPORARY TABLE t1 (
119
t1ID int NOT NULL auto_increment,
120
art varbinary(1) NOT NULL default '',
122
121
KNR char(5) NOT NULL default '',
123
122
RECHNR char(6) NOT NULL default '',
124
123
POSNR char(2) NOT NULL default '',
198
197
# bug #1172: "Force index" option caused server crash
200
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
199
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
201
200
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
202
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
201
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
203
202
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
204
203
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
205
204
explain select * from t1 force index(i1), t2 force index(j1) where
261
260
# Test of problem with IN on many different keyparts. (Bug #4157)
265
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
266
line int( 5 ) unsigned NOT NULL default '0',
267
columnid int( 3 ) unsigned NOT NULL default '0',
268
owner int( 3 ) unsigned NOT NULL default '0',
269
ordinal int( 3 ) unsigned NOT NULL default '0',
270
showid smallint( 6 ) unsigned NOT NULL default '1',
271
tableid int( 1 ) unsigned NOT NULL default '1',
272
content int( 5 ) unsigned NOT NULL default '188',
263
CREATE TEMPORARY TABLE t1 (
264
id int NOT NULL AUTO_INCREMENT ,
265
line int NOT NULL default '0',
266
columnid int NOT NULL default '0',
267
owner int NOT NULL default '0',
268
ordinal int NOT NULL default '0',
269
showid int NOT NULL default '1',
270
tableid int NOT NULL default '1',
271
content int NOT NULL default '188',
273
272
PRIMARY KEY ( owner, id ) ,
274
273
KEY menu( owner, showid, columnid ) ,
275
274
KEY `COLUMN` ( owner, columnid, line ) ,
286
285
# test for a bug with in() and unique key
289
create table t1 (id int(10) primary key);
288
create table t1 (id int primary key);
290
289
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
292
291
select id from t1 where id in (2,5,9) ;
381
380
analyze table t1,t2;
382
--replace_column 3 # 8 # 9 #
383
383
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
384
--replace_column 3 # 8 # 9 #
384
385
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
386
--replace_column 3 # 8 # 9 #
385
387
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
388
--replace_column 3 # 8 # 9 #
386
389
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
388
391
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
393
396
# Fix for bug#4488
395
create table t1 (x bigint unsigned not null);
396
insert into t1(x) values (0xfffffffffffffff0);
397
insert into t1(x) values (0xfffffffffffffff1);
398
create table t1 (x bigint not null);
399
insert into t1(x) values (0x0ffffffffffffff0);
400
insert into t1(x) values (0x0ffffffffffffff1);
398
401
select * from t1;
399
402
select count(*) from t1 where x>0;
400
403
select count(*) from t1 where x=0;
419
422
drop table t1,t2;
421
424
--disable_warnings
422
create table t1 (x bigint unsigned not null primary key) engine=innodb;
425
create table t1 (x bigint not null primary key) engine=innodb;
423
426
--enable_warnings
424
insert into t1(x) values (0xfffffffffffffff0);
425
insert into t1(x) values (0xfffffffffffffff1);
427
insert into t1(x) values (0x0ffffffffffffff0);
428
insert into t1(x) values (0x0ffffffffffffff1);
426
429
select * from t1;
427
430
select count(*) from t1 where x>0;
428
431
select count(*) from t1 where x=0;
438
# Bug #11185 incorrect comparison of unsigned int to signed constant
441
# Bug #11185 incorrect comparison of int to signed constant
440
create table t1 (a bigint unsigned);
443
create table t1 (a bigint);
441
444
create index t1i on t1(a);
442
445
insert into t1 select 18446744073709551615;
443
446
insert into t1 select 18446744073709551614;
457
460
# Bug #6045: Binary Comparison regression in MySQL 4.1
458
461
# Binary searches didn't use a case insensitive index.
461
create table t1 (a char(10), b text, key (a)) character set latin1;
463
create table t1 (a char(10), b text, key (a));
462
464
INSERT INTO t1 (a) VALUES
463
465
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
464
466
# all these three can be optimized
465
467
explain select * from t1 where a='aaa';
466
468
explain select * from t1 where a=binary 'aaa';
467
explain select * from t1 where a='aaa' collate latin1_bin;
469
explain select * from t1 where a='aaa' collate latin1_german1_ci;
469
explain select * from t1 where a='aaa' collate utf8_bin;
472
472
# Test for BUG#9348 "result for WHERE A AND (B OR C) differs from WHERE a AND (C OR B)"
473
473
--disable_warnings
474
474
CREATE TABLE t1 (
475
`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
476
`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
477
`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
478
`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
479
`FUNCTINT` int(11) NOT NULL default '0',
475
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
476
`ARG1` char(3) collate utf8_bin NOT NULL default '',
477
`ARG2` char(3) collate utf8_bin NOT NULL default '',
478
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
479
`FUNCTINT` int NOT NULL default '0',
480
480
KEY `VERI_CLNT~2` (`ARG1`)
481
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
482
482
--enable_warnings
484
484
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
496
496
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
498
498
CREATE TABLE t2 (
499
pk1 int(11) NOT NULL,
500
pk2 int(11) NOT NULL,
501
pk3 int(11) NOT NULL,
502
pk4 int(11) NOT NULL,
504
504
PRIMARY KEY (pk1,pk2,pk3,pk4)
505
) DEFAULT CHARSET=latin1;
507
507
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
508
508
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
532
532
CREATE TABLE t1 (
533
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
534
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
533
OXID varchar(32) NOT NULL DEFAULT '',
534
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
535
535
OXLEFT int NOT NULL DEFAULT '0',
536
536
OXRIGHT int NOT NULL DEFAULT '0',
537
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
537
OXROOTID varchar(32) NOT NULL DEFAULT '',
538
538
PRIMARY KEY (OXID),
539
539
KEY OXNID (OXID),
540
540
KEY OXLEFT (OXLEFT),
541
541
KEY OXRIGHT (OXRIGHT),
542
542
KEY OXROOTID (OXROOTID)
543
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
545
545
INSERT INTO t1 VALUES
546
546
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
555
555
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
556
556
'd8c4177d09f8b11f5.52725521');
558
--replace_column 3 # 8 # 9 #
559
560
SELECT s.oxid FROM t1 v, t1 s
560
561
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
758
# Test for bug #10031: range to be used over a view
761
CREATE TABLE t1 (a int, b int, primary key(a,b));
763
INSERT INTO t1 VALUES
764
(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
766
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
768
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
769
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
771
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
772
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
774
SELECT a,b FROM t1 WHERE a < 2 and b=3;
775
SELECT a,b FROM v1 WHERE a < 2 and b=3;
781
759
# Bug #11853: DELETE statement with a NOT (LIKE/<=>) where condition
782
760
# for an indexed attribute
804
# BUG#13317: range optimization doesn't work for IN over VIEW.
806
create table t1 (a int, b int, primary key(a,b));
807
create view v1 as select a, b from t1;
809
INSERT INTO `t1` VALUES
810
(0,0),(1,0),(2,0),(3,0),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(11,2),(12,2)
811
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
814
explain select * from t1 where a in (3,4) and b in (1,2,3);
816
explain select * from v1 where a in (3,4) and b in (1,2,3);
818
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
820
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
826
782
create table t3 (a int);
827
783
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
829
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
785
create table t1 (a varchar(10), filler char(200), key(a));
830
786
insert into t1 values ('a','');
831
787
insert into t1 values ('a ','');
832
788
insert into t1 values ('a ', '');
836
792
create table t2 (a varchar(10), filler char(200), key(a));
837
793
insert into t2 select * from t1;
795
--replace_column 3 # 8 # 9 #
840
796
explain select * from t1 where a between 'a' and 'a ';
797
--replace_column 3 # 8 # 9 #
842
798
explain select * from t1 where a = 'a' or a='a ';
800
--replace_column 3 # 8 # 9 #
845
801
explain select * from t2 where a between 'a' and 'a ';
802
--replace_column 3 # 8 # 9 #
847
803
explain select * from t2 where a = 'a' or a='a ';
849
805
update t1 set a='b' where a<>'a';
806
--replace_column 3 # 8 # 9 #
851
807
explain select * from t1 where a not between 'b' and 'b';
852
808
select a, hex(filler) from t1 where a not between 'b' and 'b';
854
810
drop table t1,t2,t3;
859
create table t1 (a int);
860
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
861
create table t2 (a int, key(a));
862
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
864
set @a="select * from t2 force index (a) where a NOT IN(0";
865
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
866
set @a=concat(@a, ')');
868
insert into t2 values (11),(13),(15);
870
set @b= concat("explain ", @a);
872
prepare stmt1 from @b;
875
prepare stmt1 from @a;
881
813
# Bug #18165: range access for BETWEEN with a constant for the first argument
910
842
# when a range condition use an invalid datetime constant
845
CREATE TEMPORARY TABLE t1 (
914
846
item char(20) NOT NULL default '',
915
started datetime NOT NULL default '0000-00-00 00:00:00',
916
848
price decimal(16,3) NOT NULL default '0.000',
917
849
PRIMARY KEY (item,started)
923
855
('A1','2005-12-12 08:00:00',3000),
924
856
('A2','2005-12-01 08:00:00',1000);
926
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
927
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
928
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
930
DROP INDEX `PRIMARY` ON t1;
932
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
933
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
934
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
858
--replace_column 3 # 8 # 9 #
859
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
860
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
861
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
863
# Disabling for now, since it fails. Likely due to only currently
864
# checking for bad datetimes on string conversions...
866
#DROP INDEX `PRIMARY` ON t1;
868
#EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
869
#SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
870
#SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
939
875
--echo BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
941
877
CREATE TABLE t1 (
942
id int(11) NOT NULL auto_increment,
878
id int NOT NULL auto_increment,
943
879
dateval date default NULL,
944
880
PRIMARY KEY (id),
945
881
KEY dateval (dateval)
963
899
CREATE TABLE t1 (
964
900
a varchar(32), index (a)
965
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
901
) DEFAULT COLLATE=utf8_bin;
967
903
INSERT INTO t1 VALUES
968
904
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
979
915
# test UNSIGNED. only occurs when indexed.
980
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
916
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
982
918
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
984
920
# test upper bound
986
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256;
987
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256.0;
922
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
923
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
989
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 255;
925
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
991
927
# show we don't fiddle with lower bound on UNSIGNED
993
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
929
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
995
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
931
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1000
936
# test signed. only occurs when index.
1001
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
937
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1003
939
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1005
941
# test upper bound
1007
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128;
1008
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128.0;
943
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
944
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1010
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 127;
946
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
1012
948
# test lower bound
1014
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129;
1015
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129.0;
950
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
951
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1017
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -128;
953
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1042
978
# 500 rows, 1 row
1044
980
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1045
explain select * from t2 where a=1000 and b<11;
981
create temporary table t2e like t2;
982
alter table t2e engine=myisam;
983
insert into t2e select * from t2;
985
explain select * from t2e where a=1000 and b<11;
1047
987
drop table t1, t2;