Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

“SELECT 1″ rather than a “SELECT *” when using an EXISTS or a NOT EXISTS clause”. Expand / Collapse
Author
Message
Posted Friday, February 11, 2011 1:48 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, December 16, 2013 10:42 AM
Points: 96, 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
Post #1062821
Posted Friday, February 11, 2011 4:31 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, September 11, 2014 12:39 PM
Points: 310, Visits: 659
Cost Analysis Among EXISTS (SELECT 1), EXISTS (SELECT COUNT(1)), EXISTS (SELECT *) AND EXISTS (SELECT TOP 1) should help

-lucky
Post #1062892
Posted Saturday, February 12, 2011 1:17 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053


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 2008, MVP
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

Post #1062946
Posted Saturday, February 12, 2011 1:20 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 40,596, Visits: 37,053
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 2008, MVP
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

Post #1062947
Posted Monday, February 14, 2011 9:25 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, December 16, 2013 10:42 AM
Points: 96, 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
Post #1063623
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse