June 14, 2006 at 11:51 am
Is there any performance gain to using LIKE '%' rather than IS NOT NULL?
Any other reason why one would choose the former over the latter (other than driving folks like me nuts ...)?
June 14, 2006 at 1:03 pm
I doubt there's any performance difference. I expect someone who didn't know SQL tried to use " <> NULL", found it didn't work, and rather than learning about NULLs, found a workaround.
[Edit] Actually, in testing, it appears that "LIKE '%'" should perform worse. Try the code below - even with a non-unique index and large percentage of Nulls in the entire set, using IS NOT NULL will generate an index seek, which should be faster:
Select *
Into #t
From
(
Select 1 As Id Union All
Select 2 Union All
Select 3 Union All
Select 4 Union All
Select 5 Union All
Select 6 Union All
Select 7 Union All
Select 8 Union All
Select 9 Union All
Select Null Union All
Select Null Union All
Select Null Union All
Select Null Union All
Select Null Union All
Select Null Union All
Select Null
) dt
Create index #ixt on #t (Id)
Select * from #t
Where Id Like '%'
Select * from #t
Where Id Is Not Null
June 15, 2006 at 10:43 am
Thanks for the feedback. Sometimes I just need a sanity check.
June 15, 2006 at 5:48 pm
You do get a slight perf gain from id > 0 (or some number assuming there is a fixed domain -- like identities are usually 1 or higher) but that is only with a good number of records.
June 15, 2006 at 8:26 pm
Considering we're talking about a VLDB that processes terabytes of data daily, even a "slight" improvement is a Good Thing.
June 19, 2006 at 3:45 am
might be worth trying
>=
''
then.
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply