April 12, 2010 at 9:33 am
My ENV : SQL Server 2008 on Windows Server 2003 64bit
-- create the the test table
create table test04
(
f01 int ,
f02 int ,
f03 int ,
f04 int
);
-- load null value in the table
declare @i int
set @i=0
while @i<10000
begin
set @i = @i+1 ;
insert into test04 values ( null,null,null,null );
end
-- create a nonclustered index on a field
create index i_t04f01 on test04(f01);
-- the test SQL
select COUNT(*) from test04 where f01 is null;
select COUNT(*) from test04 where f01 is not null;
select * from test04 where f01 is not null ;
the first and second SQL use "Index Seek"
the third SQL use "index seek" "RID Lookup"
Oracle Index never indexes the NULL value , But , SQL Server Index CONTAINS and INDEXES the NULL value ?
April 12, 2010 at 9:54 am
Yes, it does, because it makes that kind of query faster.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 12, 2010 at 10:13 am
Thanks for replies
by the way , is there some document like MSDN illustrate this point ?
In Our Site , Many Many Developer and DBA think that The Index of SQL Server never contains and indexes the NULL value .
I must to Overturn this view
April 12, 2010 at 10:35 am
Microsoft has an article on estimating index disk space at http://msdn.microsoft.com/en-us/library/ms190620.aspx. It includes data on the effect of nullable columns, which at least implies that indexes can contain null values.
If you need something more specific than that, you might just want to Google/Bing the subject and see what you can find. Otherwise, your own test seems like pretty good proof on the subject.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 12, 2010 at 10:43 am
Thank you very mush ,
may be my keywords has some problem , I will try to use bing to search again .
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy