日期:2014-05-16  浏览次数:20407 次

关于is null和is not null


???
?网上有些资料说含有
null 的列不能创建索引,还有资料说因为一般的索引是 b_ 树结构,而 b+ 树不能存储 null 值,所以 is null is not null 都不能利用 索引。为了证明以上说法,我做了一下测试。

1. 测试含有 null 的列是否能创建索引

先创建测试数据 :

create table student
(
???
id int primary key not null ,
???
sid ? int
)

: 定义主键时系统自动创建索引,如果 DROP 表,关于这个表的所有索引也被删除,也包括系统创建的索引。

create procedure insertDate()
BEGIN
??? ? DECLARE v_id int;
??? ? set v_id = 0;
??? ? while v_id < 100000
??? ? DO
??? ?? insert into student values(v_id,v_id );
??? ?? set v_id = v_id + 1;
??? ? end while;
END
;

-- 插入数据

???????? call insertDate ()

???