May 1, 2013 at 12:01 am
Dear Experts,
I want to know what is difference between count(*), count(id) and count(1) base on performance issues.
We have some quires with count(*) that sometimes throws timeout and we have many Transactions on these tables in our other queries.
we guess that if we change it to count(id) or count(1) it will be better.
Is this change effective?
Any information will be helpful.
Faithfully Yours,
Ashkan
Best Regards,
Ashkan
May 1, 2013 at 12:16 am
Count(*) includes rows with null values whereas count(id) would not include rows with a null id. Unlikely if the id is a primary key though, so it does depend on the column itself to a certain extent.
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
May 1, 2013 at 12:23 am
http://msdn.microsoft.com/en-us/library/ms175997.aspx
Malleswarareddy
I.T.Analyst
MCITP(70-451)
May 1, 2013 at 12:43 am
Here's an article on this site discussing the issue: http://www.sqlservercentral.com/articles/Performance+Tuning/adviceoncount/808/
May 1, 2013 at 1:38 am
Steve Jones - SSC Editor (5/1/2013)
Here's an article on this site discussing the issue: http://www.sqlservercentral.com/articles/Performance+Tuning/adviceoncount/808/
This is a great article, it's amazing what you can forget over time.... 🙂
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply