1
1
drop table if exists t1, t2, t3;
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,
4
type int DEFAULT '0' NOT NULL,
5
event_id int 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 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,
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,
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
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,
84
id int NOT NULL auto_increment,
85
parent_id int DEFAULT '0' NOT NULL,
86
level int DEFAULT '0' NOT NULL,
91
88
KEY parent_id (parent_id),
221
218
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
222
219
id select_type table type possible_keys key key_len ref rows Extra
223
220
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
221
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
225
222
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
226
223
id select_type table type possible_keys key key_len ref rows Extra
227
224
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
225
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
229
226
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
230
227
id select_type table type possible_keys key key_len ref rows Extra
231
228
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
229
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using join buffer
233
230
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
234
231
id select_type table type possible_keys key key_len ref rows Extra
235
232
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
233
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using join buffer
237
234
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
238
235
id select_type table type possible_keys key key_len ref rows Extra
239
236
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
237
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
241
238
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
242
239
id select_type table type possible_keys key key_len ref rows Extra
243
240
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
241
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using join buffer
245
242
explain select count(*) from t1 where x in (1);
246
243
id select_type table type possible_keys key key_len ref rows Extra
247
244
1 SIMPLE t1 ref x x 5 const 1 Using index
249
246
id select_type table type possible_keys key key_len ref rows Extra
250
247
1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
252
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
249
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
253
250
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
254
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
251
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
255
252
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
256
253
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
257
254
id select_type table type possible_keys key key_len ref rows Extra
258
255
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
259
1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer
256
1 SIMPLE t1 range i1 i1 4 NULL 3 Using where; Using index; Using join buffer
260
257
explain select * from t1 force index(i1), t2 force index(j1) where
261
258
(t1.key1 <t2.keya + 1) and t2.keya=3;
262
259
id select_type table type possible_keys key key_len ref rows Extra
263
260
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
264
1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer
261
1 SIMPLE t1 range i1 i1 4 NULL 3 Using where; Using index; Using join buffer
265
262
DROP TABLE t1,t2;
267
a int(11) default NULL,
268
b int(11) default NULL,
263
CREATE TEMPORARY TABLE t1 (
276
273
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
277
274
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
278
275
id select_type table type possible_keys key key_len ref rows Extra
279
1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where; Using MRR
276
1 SIMPLE t1 range a,b a 5 NULL 2 Using where
280
277
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
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',
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',
316
313
PRIMARY KEY ( owner, id ) ,
317
314
KEY menu( owner, showid, columnid ) ,
318
315
KEY `COLUMN` ( owner, columnid, line ) ,
418
415
analyze table t1,t2;
419
416
Table Op Msg_type Msg_text
420
417
test.t1 analyze status OK
421
test.t2 analyze status Table is already up to date
418
test.t2 analyze status OK
422
419
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
423
420
id select_type table type possible_keys key key_len ref rows Extra
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
421
1 SIMPLE t1 range uid_index uid_index 4 NULL # Using where
422
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid #
426
423
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
427
424
id select_type table type possible_keys key key_len ref rows Extra
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
425
1 SIMPLE t1 range uid_index uid_index 4 NULL # Using where
426
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid #
430
427
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
431
428
id select_type table type possible_keys key key_len ref rows Extra
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
429
1 SIMPLE t1 range uid_index uid_index 4 NULL # Using where
430
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid #
434
431
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
435
432
id select_type table type possible_keys key key_len ref rows Extra
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
433
1 SIMPLE t1 range uid_index uid_index 4 NULL # Using where
434
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid #
438
435
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
439
436
id name uid id name uid
440
437
1001 A 1 1001 A 1
587
584
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
588
585
select * from t1 where a <> -1;
592
588
explain select * from t1 where a > -1 or a < -1;
593
589
id select_type table type possible_keys key key_len ref rows Extra
594
590
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
595
591
select * from t1 where a > -1 or a < -1;
599
594
explain select * from t1 where a > -1;
600
595
id select_type table type possible_keys key key_len ref rows Extra
601
596
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
602
597
select * from t1 where a > -1;
606
599
explain select * from t1 where a < -1;
607
600
id select_type table type possible_keys key key_len ref rows Extra
608
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
601
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
609
602
select * from t1 where a < -1;
613
create table t1 (a char(10), b text, key (a)) character set latin1;
606
create table t1 (a char(10), b text, key (a));
614
607
INSERT INTO t1 (a) VALUES
615
608
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
616
609
explain select * from t1 where a='aaa';
617
610
id select_type table type possible_keys key key_len ref rows Extra
618
1 SIMPLE t1 ref a a 11 const 2 Using index condition
611
1 SIMPLE t1 ref a a 43 const 2 Using where
619
612
explain select * from t1 where a=binary 'aaa';
620
613
id select_type table type possible_keys key key_len ref rows Extra
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
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
629
619
CREATE TABLE t1 (
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',
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',
635
625
KEY `VERI_CLNT~2` (`ARG1`)
636
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
637
627
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
638
628
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
639
629
('001',' 3',' 0','Text 017',0);
647
637
create table t1 (a int);
648
638
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
649
639
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,
655
645
PRIMARY KEY (pk1,pk2,pk3,pk4)
656
) DEFAULT CHARSET=latin1;
657
647
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
658
648
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
659
649
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
669
659
insert into t1 values ('x'), ('xx');
670
660
explain select a from t1 where a > 'x';
671
661
id select_type table type possible_keys key key_len ref rows Extra
672
1 SIMPLE t1 range a a 2 NULL 2 Using where
662
1 SIMPLE t1 range a a 7 NULL 1 Using where
673
663
select a from t1 where a > 'x';
677
667
CREATE TABLE t1 (
678
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
679
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
668
OXID varchar(32) NOT NULL DEFAULT '',
669
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
680
670
OXLEFT int NOT NULL DEFAULT '0',
681
671
OXRIGHT int NOT NULL DEFAULT '0',
682
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
672
OXROOTID varchar(32) NOT NULL DEFAULT '',
683
673
PRIMARY KEY (OXID),
684
674
KEY OXNID (OXID),
685
675
KEY OXLEFT (OXLEFT),
686
676
KEY OXRIGHT (OXRIGHT),
687
677
KEY OXROOTID (OXROOTID)
688
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
689
679
INSERT INTO t1 VALUES
690
680
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
691
681
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
704
694
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
705
695
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
706
696
id select_type table type possible_keys key key_len ref rows Extra
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)
697
1 SIMPLE v ALL OXLEFT,OXRIGHT,OXROOTID NULL NULL NULL # Using where
698
1 SIMPLE s ALL OXLEFT NULL NULL NULL # Range checked for each record (index map: 0x4)
709
699
SELECT s.oxid FROM t1 v, t1 s
710
700
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
711
701
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
878
868
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
879
869
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
880
870
id select_type table type possible_keys key key_len ref rows Extra
881
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
871
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
882
872
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
883
873
id select_type table type possible_keys key key_len ref rows Extra
884
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
874
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
885
875
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
905
895
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
906
896
id select_type table type possible_keys key key_len ref rows Extra
907
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
897
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
908
898
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
909
899
id select_type table type possible_keys key key_len ref rows Extra
910
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
900
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
911
901
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
912
902
id select_type table type possible_keys key key_len ref rows Extra
913
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
903
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
914
904
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
915
905
id select_type table type possible_keys key key_len ref rows Extra
916
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
906
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
917
907
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;
962
928
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
963
929
INSERT INTO t1 VALUES ('Betty'), ('Anna');
964
930
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
1005
952
create table t3 (a int);
1006
953
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1007
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
954
create table t1 (a varchar(10), filler char(200), key(a));
1008
955
insert into t1 values ('a','');
1009
956
insert into t1 values ('a ','');
1010
957
insert into t1 values ('a ', '');
1014
961
insert into t2 select * from t1;
1015
962
explain select * from t1 where a between 'a' and 'a ';
1016
963
id select_type table type possible_keys key key_len ref rows Extra
1017
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
964
1 SIMPLE t1 ref a a 43 const # Using where
1018
965
explain select * from t1 where a = 'a' or a='a ';
1019
966
id select_type table type possible_keys key key_len ref rows Extra
1020
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
967
1 SIMPLE t1 ref a a 43 const # Using where
1021
968
explain select * from t2 where a between 'a' and 'a ';
1022
969
id select_type table type possible_keys key key_len ref rows Extra
1023
1 SIMPLE t2 ref a a 13 const # Using index condition
970
1 SIMPLE t2 ref a a 43 const # Using where
1024
971
explain select * from t2 where a = 'a' or a='a ';
1025
972
id select_type table type possible_keys key key_len ref rows Extra
1026
1 SIMPLE t2 ref a a 13 const # Using index condition
973
1 SIMPLE t2 ref a a 43 const # Using where
1027
974
update t1 set a='b' where a<>'a';
1028
975
explain select * from t1 where a not between 'b' and 'b';
1029
976
id select_type table type possible_keys key key_len ref rows Extra
1030
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
977
1 SIMPLE t1 ALL a NULL NULL NULL # Using where
1031
978
select a, hex(filler) from t1 where a not between 'b' and 'b';
1033
a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1034
983
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;
1057
984
CREATE TABLE t1 (
1058
985
id int NOT NULL DEFAULT '0',
1059
986
b int NOT NULL DEFAULT '0',
1072
999
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1073
1000
id select_type table type possible_keys key key_len ref rows Extra
1074
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using index condition; Using where; Using MRR
1001
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where
1075
1002
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1076
1003
id select_type table type possible_keys key key_len ref rows Extra
1077
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using where; Using MRR
1004
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where
1078
1005
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1101
1028
('A1','2005-11-15 00:00:00',2000),
1102
1029
('A1','2005-12-12 08:00:00',3000),
1103
1030
('A2','2005-12-01 08:00:00',1000);
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
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 t1 range PRIMARY PRIMARY 90 NULL # 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
1133
1038
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1134
1039
item started price
1135
1040
A1 2005-11-01 08:00:00 1000.000
1151
1056
This must use range access:
1152
1057
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1153
1058
id select_type table type possible_keys key key_len ref rows Extra
1154
1 SIMPLE t1 range dateval dateval 4 NULL 2 Using index condition; Using MRR
1059
1 SIMPLE t1 index dateval PRIMARY 4 NULL 11 Using where
1156
1061
CREATE TABLE t1 (
1157
1062
a varchar(32), index (a)
1158
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
1063
) DEFAULT COLLATE=utf8_bin;
1159
1064
INSERT INTO t1 VALUES
1160
1065
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1161
1066
SELECT a FROM t1 WHERE a='b' OR a='B';
1165
1070
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1166
1071
id select_type table type possible_keys key key_len ref rows Extra
1167
1 SIMPLE t1 range a a 35 NULL 3 Using where; Using index
1072
1 SIMPLE t1 range a a 131 NULL 3 Using where; Using index
1169
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
1074
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
1170
1075
INSERT INTO t1 VALUES (127),(254),(0),(1),(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;
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;
1180
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
1085
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
1183
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
1088
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1187
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
1092
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1188
1093
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-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;
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;
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;
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;
1215
1120
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1217
1122
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1218
explain select * from t2 where a=1000 and b<11;
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;
1219
1130
id select_type table type possible_keys key key_len ref rows Extra
1220
1 SIMPLE t2 ref a a 5 const 502 Using index condition
1131
1 SIMPLE t2e ref a a 5 const 11 Using where
1221
1132
drop table t1, t2;
1222
1133
End of 5.1 tests
1223
1134
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));