📄 range.result
字号:
count(*)0drop table t1,t2;create table t1 (x bigint unsigned not null primary key) engine=innodb;insert into t1(x) values (0xfffffffffffffff0);insert into t1(x) values (0xfffffffffffffff1);select * from t1;x1844674407370955160018446744073709551601select count(*) from t1 where x>0;count(*)2select count(*) from t1 where x=0;count(*)0select count(*) from t1 where x<0;count(*)0select count(*) from t1 where x < -16;count(*)0select count(*) from t1 where x = -16;count(*)0select count(*) from t1 where x > -16;count(*)2select count(*) from t1 where x = 18446744073709551601;count(*)1drop table t1;create table t1 (a bigint unsigned);create index t1i on t1(a);insert into t1 select 18446744073709551615;insert into t1 select 18446744073709551614;explain select * from t1 where a <> -1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using indexselect * from t1 where a <> -1;a1844674407370955161418446744073709551615explain select * from t1 where a > -1 or a < -1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using indexselect * from t1 where a > -1 or a < -1;a1844674407370955161418446744073709551615explain select * from t1 where a > -1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using indexselect * from t1 where a > -1;a1844674407370955161418446744073709551615explain select * from t1 where a < -1;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tablesselect * from t1 where a < -1;adrop table t1;set names latin1;create table t1 (a char(10), b text, key (a)) character set latin1;INSERT INTO t1 (a) VALUES('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');explain select * from t1 where a='aaa';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ref a a 11 const 2 Using whereexplain select * from t1 where a=binary 'aaa';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 11 NULL 2 Using whereexplain select * from t1 where a='aaa' collate latin1_bin;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 11 NULL 2 Using whereexplain select * from t1 where a='aaa' collate latin1_german1_ci;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 ALL a NULL NULL NULL 9 Using wheredrop table t1;CREATE TABLE t1 (`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',`FUNCTINT` int(11) NOT NULL default '0',KEY `VERI_CLNT~2` (`ARG1`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),('001',' 3',' 0','Text 017',0);SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 1' OR ARG1 != ' 2');count(*)4SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 2' OR ARG1 != ' 1');count(*)4drop table t1;CREATE TABLE t1 (id int(11) NOT NULL auto_increment,status varchar(20),PRIMARY KEY (id),KEY (status));INSERT INTO t1 VALUES(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'),(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'),(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'),(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'), (25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'),(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'),(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'),(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'),(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'),(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 11 Using whereEXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 11 Using whereSELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';id status53 C54 C55 C56 C57 C58 C59 C60 CSELECT * FROM t1 WHERE status NOT IN ('A','B');id status53 C54 C55 C56 C57 C58 C59 C60 CEXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 11 Using where; Using indexEXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 11 Using where; Using indexEXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 10 Using whereEXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range status status 23 NULL 10 Using whereSELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';id status53 C54 C55 C56 C57 C58 C59 C60 CSELECT * FROM t1 WHERE status < 'A' OR status > 'B';id status53 C54 C55 C56 C57 C58 C59 C60 CDROP TABLE t1;CREATE TABLE t1 (a int, b int, primary key(a,b));INSERT INTO t1 VALUES(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using indexEXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;id select_type table type possible_keys key key_len ref rows Extra1 PRIMARY t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using indexEXPLAIN SELECT a,b FROM t1 WHERE a < 2;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using indexEXPLAIN SELECT a,b FROM v1 WHERE a < 2;id select_type table type possible_keys key key_len ref rows Extra1 PRIMARY t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using indexSELECT a,b FROM t1 WHERE a < 2 and b=3;a b1 3SELECT a,b FROM v1 WHERE a < 2 and b=3;a b1 3DROP VIEW v1;DROP TABLE t1;CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));INSERT INTO t1 VALUES ('Betty'), ('Anna');SELECT * FROM t1;nameAnnaBettyDELETE FROM t1 WHERE name NOT LIKE 'A%a';SELECT * FROM t1;nameAnnaDROP TABLE t1;CREATE TABLE t1 (a int, KEY idx(a));INSERT INTO t1 VALUES (NULL), (1), (2), (3);SELECT * FROM t1;aNULL123DELETE FROM t1 WHERE NOT(a <=> 2);SELECT * FROM t1;a2DROP TABLE t1;create table t1 (a int, b int, primary key(a,b));create view v1 as select a, b from t1;INSERT INTO `t1` VALUES(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),(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);explain select * from t1 where a in (3,4) and b in (1,2,3);id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using indexexplain select * from v1 where a in (3,4) and b in (1,2,3);id select_type table type possible_keys key key_len ref rows Extra1 PRIMARY t1 range PRIMARY PRIMARY 8 NULL # Using where; Using indexexplain select * from t1 where a between 3 and 4 and b between 1 and 2;id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using indexexplain select * from v1 where a between 3 and 4 and b between 1 and 2;id select_type table type possible_keys key key_len ref rows Extra1 PRIMARY t1 range PRIMARY PRIMARY 8 NULL # Using where; Using indexdrop view v1;drop table t1;create table t3 (a int);insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;insert into t1 values ('a','');insert into t1 values ('a ','');insert into t1 values ('a ', '');insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), '' from t3 A, t3 B, t3 C;create table t2 (a varchar(10), filler char(200), key(a));insert into t2 select * from t1;explain select * from t1 where a between 'a' and 'a ';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 13 NULL # Using whereexplain select * from t1 where a = 'a' or a='a ';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 13 NULL # Using whereexplain select * from t2 where a between 'a' and 'a ';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref a a 13 const # Using whereexplain select * from t2 where a = 'a' or a='a ';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t2 ref a a 13 const # Using whereupdate t1 set a='b' where a<>'a';explain select * from t1 where a not between 'b' and 'b';id select_type table type possible_keys key key_len ref rows Extra1 SIMPLE t1 range a a 13 NULL # Using whereselect a, hex(filler) from t1 where a not between 'b' and 'b';a hex(filler)a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000drop table t1,t2,t3;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -