1
1
drop table if exists t1, t2, t3;
4
type int DEFAULT '0' NOT NULL,
5
event_id int DEFAULT '0' NOT NULL,
3
event_date date DEFAULT '0000-00-00' NOT NULL,
4
type int(11) DEFAULT '0' NOT NULL,
5
event_id int(11) DEFAULT '0' NOT NULL,
6
6
PRIMARY KEY (event_date,type,event_id)
8
8
INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
45
45
1999-07-15 100600 16
48
PAPER_ID int DEFAULT '0' NOT NULL,
49
YEAR int DEFAULT '0' NOT NULL,
50
ISSUE int DEFAULT '0' NOT NULL,
51
CLOSED int DEFAULT '0' NOT NULL,
48
PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
49
YEAR smallint(6) DEFAULT '0' NOT NULL,
50
ISSUE smallint(6) DEFAULT '0' NOT NULL,
51
CLOSED tinyint(4) DEFAULT '0' NOT NULL,
52
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
53
53
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
55
55
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
80
80
Table Op Msg_type Msg_text
81
81
test.t1 check status OK
83
Table Op Msg_type Msg_text
84
test.t1 repair status OK
84
id int NOT NULL auto_increment,
85
parent_id int DEFAULT '0' NOT NULL,
86
level int DEFAULT '0' NOT NULL,
87
id int(11) NOT NULL auto_increment,
88
parent_id int(11) DEFAULT '0' NOT NULL,
89
level tinyint(4) DEFAULT '0' NOT NULL,
88
91
KEY parent_id (parent_id),
217
220
update t1 set y=x;
218
221
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
219
222
id select_type table type possible_keys key key_len ref rows Extra
220
1 SIMPLE t1 ref y y 5 const 1 Using where
221
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
223
1 SIMPLE t1 ref y y 5 const 1
224
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
222
225
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
223
226
id select_type table type possible_keys key key_len ref rows Extra
224
1 SIMPLE t1 ref y y 5 const 1 Using where
225
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
227
1 SIMPLE t1 ref y y 5 const 1
228
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
226
229
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
227
230
id select_type table type possible_keys key key_len ref rows Extra
228
1 SIMPLE t1 ref y y 5 const 1 Using where
229
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using join buffer
231
1 SIMPLE t1 ref y y 5 const 1
232
1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using MRR; Using join buffer
230
233
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
231
234
id select_type table type possible_keys key key_len ref rows Extra
232
1 SIMPLE t1 ref y y 5 const 1 Using where
233
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using join buffer
235
1 SIMPLE t1 ref y y 5 const 1
236
1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using MRR; Using join buffer
234
237
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
235
238
id select_type table type possible_keys key key_len ref rows Extra
236
1 SIMPLE t1 ref y y 5 const 1 Using where
237
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
239
1 SIMPLE t1 ref y y 5 const 1
240
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
238
241
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
239
242
id select_type table type possible_keys key key_len ref rows Extra
240
1 SIMPLE t1 ref y y 5 const 1 Using where
241
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
243
1 SIMPLE t1 ref y y 5 const 1
244
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
242
245
explain select count(*) from t1 where x in (1);
243
246
id select_type table type possible_keys key key_len ref rows Extra
244
1 SIMPLE t1 ref x x 5 const 1 Using where; Using index
247
1 SIMPLE t1 ref x x 5 const 1 Using index
245
248
explain select count(*) from t1 where x in (1,2);
246
249
id select_type table type possible_keys key key_len ref rows Extra
247
250
1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
249
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
252
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
250
253
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
251
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
254
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
252
255
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
253
256
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
254
257
id select_type table type possible_keys key key_len ref rows Extra
273
276
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
274
277
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
275
278
id select_type table type possible_keys key key_len ref rows Extra
276
1 SIMPLE t1 range a,b a 5 NULL 2 Using where
279
1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where; Using MRR
277
280
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
304
CREATE TEMPORARY TABLE t1 (
305
id int NOT NULL AUTO_INCREMENT ,
306
line int NOT NULL default '0',
307
columnid int NOT NULL default '0',
308
owner int NOT NULL default '0',
309
ordinal int NOT NULL default '0',
310
showid int NOT NULL default '1',
311
tableid int NOT NULL default '1',
312
content int NOT NULL default '188',
308
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
309
line int( 5 ) unsigned NOT NULL default '0',
310
columnid int( 3 ) unsigned NOT NULL default '0',
311
owner int( 3 ) unsigned NOT NULL default '0',
312
ordinal int( 3 ) unsigned NOT NULL default '0',
313
showid smallint( 6 ) unsigned NOT NULL default '1',
314
tableid int( 1 ) unsigned NOT NULL default '1',
315
content int( 5 ) unsigned NOT NULL default '188',
313
316
PRIMARY KEY ( owner, id ) ,
314
317
KEY menu( owner, showid, columnid ) ,
315
318
KEY `COLUMN` ( owner, columnid, line ) ,
415
418
analyze table t1,t2;
416
419
Table Op Msg_type Msg_text
417
420
test.t1 analyze status OK
418
test.t2 analyze status OK
421
test.t2 analyze status Table is already up to date
419
422
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
420
423
id select_type table type possible_keys key key_len ref rows Extra
421
1 SIMPLE # range uid_index uid_index 4 # # Using where
422
1 SIMPLE # ref uid_index uid_index 4 # #
424
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using index condition; Using MRR
425
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
423
426
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
424
427
id select_type table type possible_keys key key_len ref rows Extra
425
1 SIMPLE # range uid_index uid_index 4 # # Using where
426
1 SIMPLE # ref uid_index uid_index 4 # #
428
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using index condition; Using MRR
429
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
427
430
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
428
431
id select_type table type possible_keys key key_len ref rows Extra
429
1 SIMPLE # range uid_index uid_index 4 # # Using where
430
1 SIMPLE # ref uid_index uid_index 4 # #
432
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using index condition; Using MRR
433
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
431
434
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
432
435
id select_type table type possible_keys key key_len ref rows Extra
433
1 SIMPLE # range uid_index uid_index 4 # # Using where
434
1 SIMPLE # ref uid_index uid_index 4 # #
436
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using index condition; Using MRR
437
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
435
438
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
436
439
id name uid id name uid
437
440
1001 A 1 1001 A 1
584
587
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
585
588
select * from t1 where a <> -1;
588
592
explain select * from t1 where a > -1 or a < -1;
589
593
id select_type table type possible_keys key key_len ref rows Extra
590
594
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
591
595
select * from t1 where a > -1 or a < -1;
594
599
explain select * from t1 where a > -1;
595
600
id select_type table type possible_keys key key_len ref rows Extra
596
601
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
597
602
select * from t1 where a > -1;
599
606
explain select * from t1 where a < -1;
600
607
id select_type table type possible_keys key key_len ref rows Extra
601
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
608
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
602
609
select * from t1 where a < -1;
606
create table t1 (a char(10), b text, key (a));
613
create table t1 (a char(10), b text, key (a)) character set latin1;
607
614
INSERT INTO t1 (a) VALUES
608
615
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
609
616
explain select * from t1 where a='aaa';
610
617
id select_type table type possible_keys key key_len ref rows Extra
611
1 SIMPLE t1 ref a a 43 const 2 Using where
618
1 SIMPLE t1 ref a a 11 const 2 Using index condition
612
619
explain select * from t1 where a=binary 'aaa';
613
620
id select_type table type possible_keys key key_len ref rows Extra
614
1 SIMPLE t1 range a a 43 NULL 2 Using where
615
explain select * from t1 where a='aaa' collate utf8_bin;
616
id select_type table type possible_keys key key_len ref rows Extra
617
1 SIMPLE t1 range a a 43 NULL 2 Using where
621
1 SIMPLE t1 range a a 11 NULL 2 Using index condition; Using MRR
622
explain select * from t1 where a='aaa' collate latin1_bin;
623
id select_type table type possible_keys key key_len ref rows Extra
624
1 SIMPLE t1 range a a 11 NULL 2 Using index condition; Using MRR
625
explain select * from t1 where a='aaa' collate latin1_german1_ci;
626
id select_type table type possible_keys key key_len ref rows Extra
627
1 SIMPLE t1 ALL a NULL NULL NULL 9 Using where
619
629
CREATE TABLE t1 (
620
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
621
`ARG1` char(3) collate utf8_bin NOT NULL default '',
622
`ARG2` char(3) collate utf8_bin NOT NULL default '',
623
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
624
`FUNCTINT` int NOT NULL default '0',
630
`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
631
`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
632
`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
633
`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
634
`FUNCTINT` int(11) NOT NULL default '0',
625
635
KEY `VERI_CLNT~2` (`ARG1`)
636
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
627
637
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
628
638
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
629
639
('001',' 3',' 0','Text 017',0);
637
647
create table t1 (a int);
638
648
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
639
649
CREATE TABLE t2 (
650
pk1 int(11) NOT NULL,
651
pk2 int(11) NOT NULL,
652
pk3 int(11) NOT NULL,
653
pk4 int(11) NOT NULL,
645
655
PRIMARY KEY (pk1,pk2,pk3,pk4)
656
) DEFAULT CHARSET=latin1;
647
657
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
648
658
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
649
659
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
659
669
insert into t1 values ('x'), ('xx');
660
670
explain select a from t1 where a > 'x';
661
671
id select_type table type possible_keys key key_len ref rows Extra
662
1 SIMPLE t1 range a a 7 NULL 2 Using where
672
1 SIMPLE t1 range a a 2 NULL 2 Using where
663
673
select a from t1 where a > 'x';
667
677
CREATE TABLE t1 (
668
OXID varchar(32) NOT NULL DEFAULT '',
669
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
678
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
679
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
670
680
OXLEFT int NOT NULL DEFAULT '0',
671
681
OXRIGHT int NOT NULL DEFAULT '0',
672
OXROOTID varchar(32) NOT NULL DEFAULT '',
682
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
673
683
PRIMARY KEY (OXID),
674
684
KEY OXNID (OXID),
675
685
KEY OXLEFT (OXLEFT),
676
686
KEY OXRIGHT (OXRIGHT),
677
687
KEY OXROOTID (OXROOTID)
688
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
679
689
INSERT INTO t1 VALUES
680
690
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
681
691
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
694
704
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
695
705
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
696
706
id select_type table type possible_keys key key_len ref rows Extra
697
1 SIMPLE # ALL OXLEFT NULL NULL # # Range checked for each record (index map: 0x4)
698
1 SIMPLE # ALL OXLEFT,OXRIGHT,OXROOTID NULL NULL # # Using where
707
1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using index condition
708
1 SIMPLE s ALL OXLEFT NULL NULL NULL 6 Range checked for each record (index map: 0x4)
699
709
SELECT s.oxid FROM t1 v, t1 s
700
710
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
701
711
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
868
878
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
869
879
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
870
880
id select_type table type possible_keys key key_len ref rows Extra
871
1 SIMPLE t1 range status status 83 NULL 10 Using where; Using index
881
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
872
882
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
873
883
id select_type table type possible_keys key key_len ref rows Extra
874
1 SIMPLE t1 range status status 83 NULL 10 Using where; Using index
884
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
875
885
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
895
905
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
896
906
id select_type table type possible_keys key key_len ref rows Extra
897
1 SIMPLE t1 range status status 83 NULL 10 Using where; Using index
907
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
898
908
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
899
909
id select_type table type possible_keys key key_len ref rows Extra
900
1 SIMPLE t1 range status status 83 NULL 10 Using where; Using index
910
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
901
911
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
902
912
id select_type table type possible_keys key key_len ref rows Extra
903
1 SIMPLE t1 range status status 83 NULL 9 Using where; Using index
913
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
904
914
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
905
915
id select_type table type possible_keys key key_len ref rows Extra
906
1 SIMPLE t1 range status status 83 NULL 9 Using where; Using index
916
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
907
917
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
938
CREATE TABLE t1 (a int, b int, primary key(a,b));
939
INSERT INTO t1 VALUES
940
(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
941
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
942
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
943
id select_type table type possible_keys key key_len ref rows Extra
944
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
945
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
946
id select_type table type possible_keys key key_len ref rows Extra
947
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
948
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
949
id select_type table type possible_keys key key_len ref rows Extra
950
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
951
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
952
id select_type table type possible_keys key key_len ref rows Extra
953
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
954
SELECT a,b FROM t1 WHERE a < 2 and b=3;
957
SELECT a,b FROM v1 WHERE a < 2 and b=3;
928
962
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
929
963
INSERT INTO t1 VALUES ('Betty'), ('Anna');
930
964
SELECT * FROM t1;
986
create table t1 (a int, b int, primary key(a,b));
987
create view v1 as select a, b from t1;
988
INSERT INTO `t1` VALUES
989
(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)
990
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
991
explain select * from t1 where a in (3,4) and b in (1,2,3);
992
id select_type table type possible_keys key key_len ref rows Extra
993
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
994
explain select * from v1 where a in (3,4) and b in (1,2,3);
995
id select_type table type possible_keys key key_len ref rows Extra
996
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
997
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
998
id select_type table type possible_keys key key_len ref rows Extra
999
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
1000
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
1001
id select_type table type possible_keys key key_len ref rows Extra
1002
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
952
1005
create table t3 (a int);
953
1006
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
954
create table t1 (a varchar(10), filler char(200), key(a));
1007
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
955
1008
insert into t1 values ('a','');
956
1009
insert into t1 values ('a ','');
957
1010
insert into t1 values ('a ', '');
961
1014
insert into t2 select * from t1;
962
1015
explain select * from t1 where a between 'a' and 'a ';
963
1016
id select_type table type possible_keys key key_len ref rows Extra
964
1 SIMPLE # ref a a 43 # # Using where
1017
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
965
1018
explain select * from t1 where a = 'a' or a='a ';
966
1019
id select_type table type possible_keys key key_len ref rows Extra
967
1 SIMPLE # ref a a 43 # # Using where
1020
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
968
1021
explain select * from t2 where a between 'a' and 'a ';
969
1022
id select_type table type possible_keys key key_len ref rows Extra
970
1 SIMPLE # ref a a 43 # # Using where
1023
1 SIMPLE t2 ref a a 13 const # Using index condition
971
1024
explain select * from t2 where a = 'a' or a='a ';
972
1025
id select_type table type possible_keys key key_len ref rows Extra
973
1 SIMPLE # ref a a 43 # # Using where
1026
1 SIMPLE t2 ref a a 13 const # Using index condition
974
1027
update t1 set a='b' where a<>'a';
975
1028
explain select * from t1 where a not between 'b' and 'b';
976
1029
id select_type table type possible_keys key key_len ref rows Extra
977
1 SIMPLE # # # # # # # Using where
1030
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
978
1031
select a, hex(filler) from t1 where a not between 'b' and 'b';
1033
a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
983
1034
drop table t1,t2,t3;
1035
create table t1 (a int);
1036
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1037
create table t2 (a int, key(a));
1038
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
1039
set @a="select * from t2 force index (a) where a NOT IN(0";
1040
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
1043
set @a=concat(@a, ')');
1044
insert into t2 values (11),(13),(15);
1045
set @b= concat("explain ", @a);
1046
prepare stmt1 from @b;
1048
id select_type table type possible_keys key key_len ref rows Extra
1049
1 SIMPLE t2 index a a 5 NULL 1003 Using where; Using index
1050
prepare stmt1 from @a;
984
1057
CREATE TABLE t1 (
985
1058
id int NOT NULL DEFAULT '0',
986
1059
b int NOT NULL DEFAULT '0',
999
1072
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1000
1073
id select_type table type possible_keys key key_len ref rows Extra
1001
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where
1074
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using index condition; Using where; Using MRR
1002
1075
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1003
1076
id select_type table type possible_keys key key_len ref rows Extra
1004
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where
1077
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using where; Using MRR
1005
1078
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1028
1101
('A1','2005-11-15 00:00:00',2000),
1029
1102
('A1','2005-12-12 08:00:00',3000),
1030
1103
('A2','2005-12-01 08:00:00',1000);
1031
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
1032
id select_type table type possible_keys key key_len ref rows Extra
1033
1 SIMPLE # range PRIMARY PRIMARY 90 # # Using where
1034
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 23:59:59';
1036
A1 2005-11-01 08:00:00 1000.000
1037
A1 2005-11-15 00:00:00 2000.000
1104
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1105
id select_type table type possible_keys key key_len ref rows Extra
1106
1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 2 Using index condition
1108
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1109
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1110
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1112
A1 2005-11-01 08:00:00 1000.000
1113
A1 2005-11-15 00:00:00 2000.000
1115
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1116
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1117
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1119
A1 2005-11-01 08:00:00 1000.000
1120
A1 2005-11-15 00:00:00 2000.000
1121
DROP INDEX `PRIMARY` ON t1;
1122
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1123
id select_type table type possible_keys key key_len ref rows Extra
1124
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
1126
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1127
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1129
A1 2005-11-01 08:00:00 1000.000
1130
A1 2005-11-15 00:00:00 2000.000
1132
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1038
1133
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1039
1134
item started price
1040
1135
A1 2005-11-01 08:00:00 1000.000
1056
1151
This must use range access:
1057
1152
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1058
1153
id select_type table type possible_keys key key_len ref rows Extra
1059
1 SIMPLE t1 index dateval PRIMARY 4 NULL 11 Using where
1154
1 SIMPLE t1 range dateval dateval 4 NULL 2 Using index condition; Using MRR
1061
1156
CREATE TABLE t1 (
1062
1157
a varchar(32), index (a)
1063
) DEFAULT COLLATE=utf8_bin;
1158
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
1064
1159
INSERT INTO t1 VALUES
1065
1160
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1066
1161
SELECT a FROM t1 WHERE a='b' OR a='B';
1070
1165
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1071
1166
id select_type table type possible_keys key key_len ref rows Extra
1072
1 SIMPLE t1 range a a 131 NULL 3 Using where; Using index
1167
1 SIMPLE t1 range a a 35 NULL 3 Using where; Using index
1074
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
1169
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
1075
1170
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
1076
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
1079
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
1082
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
1171
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256;
1174
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256.0;
1177
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 255;
1085
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
1180
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
1088
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1183
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
1092
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1187
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
1093
1188
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1094
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
1097
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1100
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
1189
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128;
1192
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128.0;
1195
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 127;
1103
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
1106
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1109
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1198
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129;
1201
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129.0;
1204
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -128;
1120
1215
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1122
1217
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1123
create temporary table t2e like t2;
1124
alter table t2e engine=myisam;
1125
insert into t2e select * from t2;
1127
Table Op Msg_type Msg_text
1128
test.t2e analyze note The storage engine for the table doesn't support analyze
1129
explain select * from t2e where a=1000 and b<11;
1218
explain select * from t2 where a=1000 and b<11;
1130
1219
id select_type table type possible_keys key key_len ref rows Extra
1131
1 SIMPLE t2e ref a a 5 const 11 Using where
1220
1 SIMPLE t2 ref a a 5 const 502 Using index condition
1132
1221
drop table t1, t2;
1133
1222
End of 5.1 tests
1134
1223
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));