1
1
drop table if exists t1, t2, t3;
3
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,
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,
52
52
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
53
53
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
81
81
test.t1 check status OK
83
83
Table Op Msg_type Msg_text
84
test.t1 repair status OK
84
test.t1 repair note The storage engine for the table doesn't support repair
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,
87
id int NOT NULL auto_increment,
88
parent_id int DEFAULT '0' NOT NULL,
89
level int DEFAULT '0' NOT NULL,
91
91
KEY parent_id (parent_id),
221
221
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
222
222
id select_type table type possible_keys key key_len ref rows Extra
223
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
224
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using MRR; Using join buffer
225
225
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
226
226
id select_type table type possible_keys key key_len ref rows Extra
227
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
228
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using MRR; Using join buffer
229
229
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
230
230
id select_type table type possible_keys key key_len ref rows Extra
231
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
232
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using MRR; Using join buffer
233
233
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
234
234
id select_type table type possible_keys key key_len ref rows Extra
235
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
236
1 SIMPLE t2 range x x 5 NULL 3 Using where; Using MRR; Using join buffer
237
237
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
238
238
id select_type table type possible_keys key key_len ref rows Extra
239
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
240
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using MRR; Using join buffer
241
241
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
242
242
id select_type table type possible_keys key key_len ref rows Extra
243
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
244
1 SIMPLE t2 range x x 5 NULL 2 Using where; Using MRR; Using join buffer
245
245
explain select count(*) from t1 where x in (1);
246
246
id select_type table type possible_keys key key_len ref rows Extra
247
247
1 SIMPLE t1 ref x x 5 const 1 Using index
249
249
id select_type table type possible_keys key key_len ref rows Extra
250
250
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));
252
CREATE TABLE t1 (key1 int NOT NULL default '0', KEY i1 (key1));
253
253
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));
254
CREATE TABLE t2 (keya int NOT NULL default '0', KEY j1 (keya));
255
255
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
256
256
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
257
257
id select_type table type possible_keys key key_len ref rows Extra
258
258
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
259
1 SIMPLE t1 range i1 i1 4 NULL 3 Using where; Using index; Using join buffer
260
260
explain select * from t1 force index(i1), t2 force index(j1) where
261
261
(t1.key1 <t2.keya + 1) and t2.keya=3;
262
262
id select_type table type possible_keys key key_len ref rows Extra
263
263
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
264
1 SIMPLE t1 range i1 i1 4 NULL 3 Using where; Using index; Using join buffer
265
265
DROP TABLE t1,t2;
266
266
CREATE TABLE t1 (
267
a int(11) default NULL,
268
b int(11) default NULL,
276
276
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
277
277
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
278
278
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
279
1 SIMPLE t1 range a,b a 5 NULL 2 Using where; Using MRR
280
280
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
307
307
CREATE TABLE t1 (
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',
308
id int NOT NULL AUTO_INCREMENT ,
309
line int NOT NULL default '0',
310
columnid int NOT NULL default '0',
311
owner int NOT NULL default '0',
312
ordinal int NOT NULL default '0',
313
showid int NOT NULL default '1',
314
tableid int NOT NULL default '1',
315
content int NOT NULL default '188',
316
316
PRIMARY KEY ( owner, id ) ,
317
317
KEY menu( owner, showid, columnid ) ,
318
318
KEY `COLUMN` ( owner, columnid, line ) ,
421
421
test.t2 analyze status Table is already up to date
422
422
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
423
423
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
424
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using where; Using MRR
425
425
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
426
426
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
427
427
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
428
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using where; Using MRR
429
429
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
430
430
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
431
431
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
432
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using where; Using MRR
433
433
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
434
434
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
435
435
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
436
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using where; Using MRR
437
437
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
438
438
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
439
439
id name uid id name uid
587
587
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
588
588
select * from t1 where a <> -1;
592
591
explain select * from t1 where a > -1 or a < -1;
593
592
id select_type table type possible_keys key key_len ref rows Extra
594
593
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
595
594
select * from t1 where a > -1 or a < -1;
599
597
explain select * from t1 where a > -1;
600
598
id select_type table type possible_keys key key_len ref rows Extra
601
599
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
602
600
select * from t1 where a > -1;
606
602
explain select * from t1 where a < -1;
607
603
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
604
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
609
605
select * from t1 where a < -1;
613
create table t1 (a char(10), b text, key (a)) character set latin1;
609
create table t1 (a char(10), b text, key (a));
614
610
INSERT INTO t1 (a) VALUES
615
611
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
616
612
explain select * from t1 where a='aaa';
617
613
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
614
1 SIMPLE t1 ref a a 43 const 2 Using where
619
615
explain select * from t1 where a=binary 'aaa';
620
616
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
617
1 SIMPLE t1 range a a 43 NULL 2 Using where; Using MRR
618
explain select * from t1 where a='aaa' collate utf8_bin;
619
id select_type table type possible_keys key key_len ref rows Extra
620
1 SIMPLE t1 range a a 43 NULL 2 Using where; Using MRR
629
622
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',
623
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
624
`ARG1` char(3) collate utf8_bin NOT NULL default '',
625
`ARG2` char(3) collate utf8_bin NOT NULL default '',
626
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
627
`FUNCTINT` int NOT NULL default '0',
635
628
KEY `VERI_CLNT~2` (`ARG1`)
636
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
637
630
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
638
631
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
639
632
('001',' 3',' 0','Text 017',0);
647
640
create table t1 (a int);
648
641
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
649
642
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
648
PRIMARY KEY (pk1,pk2,pk3,pk4)
656
) DEFAULT CHARSET=latin1;
657
650
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
658
651
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
659
652
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
669
662
insert into t1 values ('x'), ('xx');
670
663
explain select a from t1 where a > 'x';
671
664
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
665
1 SIMPLE t1 range a a 7 NULL 1 Using where
673
666
select a from t1 where a > 'x';
677
670
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',
671
OXID varchar(32) NOT NULL DEFAULT '',
672
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
680
673
OXLEFT int NOT NULL DEFAULT '0',
681
674
OXRIGHT int NOT NULL DEFAULT '0',
682
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
675
OXROOTID varchar(32) NOT NULL DEFAULT '',
683
676
PRIMARY KEY (OXID),
684
677
KEY OXNID (OXID),
685
678
KEY OXLEFT (OXLEFT),
686
679
KEY OXRIGHT (OXRIGHT),
687
680
KEY OXROOTID (OXROOTID)
688
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
689
682
INSERT INTO t1 VALUES
690
683
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
691
684
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
878
871
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
879
872
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
880
873
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
874
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
882
875
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
883
876
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
877
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
885
878
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
905
898
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
906
899
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
900
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
908
901
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
909
902
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
903
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
911
904
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
912
905
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
906
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
914
907
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
915
908
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
909
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
917
910
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
931
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
963
932
INSERT INTO t1 VALUES ('Betty'), ('Anna');
964
933
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
955
create table t3 (a int);
1006
956
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;
957
create table t1 (a varchar(10), filler char(200), key(a));
1008
958
insert into t1 values ('a','');
1009
959
insert into t1 values ('a ','');
1010
960
insert into t1 values ('a ', '');
1014
964
insert into t2 select * from t1;
1015
965
explain select * from t1 where a between 'a' and 'a ';
1016
966
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
967
1 SIMPLE t1 ref a a 43 const # Using where
1018
968
explain select * from t1 where a = 'a' or a='a ';
1019
969
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
970
1 SIMPLE t1 ref a a 43 const # Using where
1021
971
explain select * from t2 where a between 'a' and 'a ';
1022
972
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
973
1 SIMPLE t2 ref a a 43 const # Using where
1024
974
explain select * from t2 where a = 'a' or a='a ';
1025
975
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
976
1 SIMPLE t2 ref a a 43 const # Using where
1027
977
update t1 set a='b' where a<>'a';
1028
978
explain select * from t1 where a not between 'b' and 'b';
1029
979
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
980
1 SIMPLE t1 ALL a NULL NULL NULL # Using where
1031
981
select a, hex(filler) from t1 where a not between 'b' and 'b';
1033
a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1034
986
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
987
CREATE TABLE t1 (
1058
988
id int NOT NULL DEFAULT '0',
1059
989
b int NOT NULL DEFAULT '0',
1072
1002
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1073
1003
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
1004
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where; Using MRR
1075
1005
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1076
1006
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
1007
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where; Using MRR
1078
1008
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1151
1081
This must use range access:
1152
1082
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1153
1083
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
1084
1 SIMPLE t1 index dateval PRIMARY 4 NULL 11 Using where
1156
1086
CREATE TABLE t1 (
1157
1087
a varchar(32), index (a)
1158
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
1088
) DEFAULT COLLATE=utf8_bin;
1159
1089
INSERT INTO t1 VALUES
1160
1090
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1161
1091
SELECT a FROM t1 WHERE a='b' OR a='B';
1165
1095
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1166
1096
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
1097
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));
1099
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
1170
1100
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;
1101
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
1104
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
1107
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
1180
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
1110
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
1183
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
1113
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1187
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
1117
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1188
1118
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;
1119
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
1122
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1125
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;
1128
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
1131
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1134
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1208
1138
create table t1 (a int);
1209
1139
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1210
create table t2 (a int, b int, filler char(100));
1140
create table t2 (a int, b int, filler char(100)) ENGINE=myisam;
1211
1141
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
1212
1142
t1 B, t1 C where A.a < 5;
1213
1143
insert into t2 select 1000, b, 'filler' from t2;