1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| select version();
drop table t1;
create table t1 ( a int primary key, b int, c int, d int, e varchar(20) ) engine=InnoDB;
show index from t1;
insert into t1 value (4,3,1,1,'d'); insert into t1 value (1,1,1,1,'a'); insert into t1 value (8,8,8,8,'h'); insert into t1 value (2,2,2,2,'b'); insert into t1 value (5,2,3,5,'e'); insert into t1 value (3,3,2,2,'c'); insert into t1 value (7,4,5,5,'g'); insert into t1 value (6,6,4,4,'f');
create index idx_ti_bcd on t1(b,c,d); create index idx_ti_e on t1(e);
explain select * from t1 where a + 1 = 1; explain select * from t1 where a = 1; explain select * from t1 where a = '1'; explain select * from t1 where e = 1; explain select * from t1 where e = '1';
select 0=0; select 0='a'; select 0='1';
explain select * from t1 where b = 1 and c = 1 and d = 1;
explain select * from t1 where c = 1 and d = 1;
explain select * from t1 where b = 1 and d = 1;
# 查询优化器 全表扫描 explain select * from t1 where b > 1;
explain select d,c,d,a from t1 where b > 1;
explain select d,c,d,a from t1;
explain select * from t1 where b > 6;
|