Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


“SELECT 1″ rather than a “SELECT *” when using an EXISTS or a NOT EXISTS clause”.


“SELECT 1″ rather than a “SELECT *” when using an EXISTS or a NOT EXISTS clause”.

Author
Message
amenjonathan
amenjonathan
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 434
I also use SELECT NULL.

Personally if something is faster and there's virtually no complexity difference, I use the faster version. Why waste where there is no need is my motto.

-------------------------------------------------------------------------------------------------
My SQL Server Blog
luckysql.kinda
luckysql.kinda
Old Hand
Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)Old Hand (314 reputation)

Group: General Forum Members
Points: 314 Visits: 659
Cost Analysis Among EXISTS (SELECT 1), EXISTS (SELECT COUNT(1)), EXISTS (SELECT *) AND EXISTS (SELECT TOP 1) should help

-lucky
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47427 Visits: 44405


Not really. Firstly there's no cost analysis there, no testing, no numbers, nothing other than the blogger's untested opinion, and one of the queries he lists is logically different from the others.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47427 Visits: 44405
amenjonathan (2/11/2011)
I also use SELECT NULL.

Personally if something is faster and there's virtually no complexity difference, I use the faster version. Why waste where there is no need is my motto.


The point is, it's not significantly faster, it's a couple of nanoseconds at best. It's micro-optimisation, it's a waste of time for no value.

Use EXISTS (Select *, EXISTS (Select 1, EXISTS (Select NULL, or any other form as they are not going to make anything resembling a noticeable difference.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


amenjonathan
amenjonathan
SSC-Enthusiastic
SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)SSC-Enthusiastic (140 reputation)

Group: General Forum Members
Points: 140 Visits: 434
GilaMonster (2/12/2011)
amenjonathan (2/11/2011)
I also use SELECT NULL.

Personally if something is faster and there's virtually no complexity difference, I use the faster version. Why waste where there is no need is my motto.


The point is, it's not significantly faster, it's a couple of nanoseconds at best. It's micro-optimisation, it's a waste of time for no value.

Use EXISTS (Select *, EXISTS (Select 1, EXISTS (Select NULL, or any other form as they are not going to make anything resembling a noticeable difference.


If I'm typing it out for the first time and I type SELECT NULL instead of SELECT *, I don't see how that wastes any time. Yes it does not provide a lot of value, but hey a tiny amount of value for free is still better than no value for free. Also, again this is just the way I do things, it helps me stay vigilant with optimization.

Again my motto is why not do what's most optimal if it doesn't require any additional work?

-------------------------------------------------------------------------------------------------
My SQL Server Blog
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search