Explain中的filtered列
Eg::创建表
create table t1 (
id int not null auto_increment,
filter char(200),
PRIMARY KEY(ID)
);
插入语句:
CREATE DEFINER=`root`@`localhost` FUNCTION `rand_string`(n INT) RETURNS varchar(255) CHARSET utf8
BEGIN
declare chars_str varchar(100) DEFAULT 'abvdefsf';
declare return_str varchar(255) default '';
declare i int default 0;
while i< n do
set return_str=concat(return_str,substring(chars_str,floor(1+rand()*52),1)); #52个字母中随机找出一个
set i=i+1;
end while;
return return_str;
END
CREATE DEFINER=`root`@`localhost` PROCEDURE `insert1`()
begin
set @a=1;
while <20000 do
set @b=rand_string(5);
insert into t1 (filter) values (@b);
set @a=@a+1;
end while;
end
call insert1();
explain select * from t1 where id <500
id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
1, SIMPLE, t1, null , range, PRIMARY, PRIMARY,,null, 4, , 499, 100.00, Using where
符合某条件的记录数百分比。