Hi There,

Thank You for visiting my blog. I have moved this blog to a new address http://dattatreysindol.com/. Please visit the blog at new address and re-point your feeds to the new address to continue to receive regular updates.
Thanks,
Dattatrey Sindol (Datta)

Datta's Ramblings on Business Intelligence 'N' Life

COUNT(*) vs. COUNT(1) - Myth vs. Reality

» 17 Nov 2010 | | |

You might have seen in many T-SQL scripts that some people use SELECT COUNT(*) FROM MyTable and some people use SELECT COUNT(1) FROM MyTable. Both of these return the same value and perform the same task of getting record count from a table. However, some techies believe that COUNT(1) is better in terms of performance when compared to COUNT(*). Let us see if this is a Myth or a Reality.

Query Execution Results:

Query Execution Plans:

In the above execution plans the Stream Aggregate (Read it Right to Left. Second from Right.) performs the count operation. Now when you click on the Stream Aggregate and go to the properties (press F4) window, you can see that the underlying query that gets executed uses COUNT(*) in both the above cases. Below is the screenshot of properties window of Stream Aggregate for both these execution plans.



From the above results, it is evident that there is no performance difference between COUNT(*) & COUNT(1) and both of them boil down to COUNT(*) in the background.

Readers Feedback:
Did you like this article?
If Yes, then please share it:
Did you like my blog?
If Yes, then please help spread the word by sharing this blog with your colleagues, friends, & anyone else in the MSBI Space: Like us on Facebook , Follow us on Twitter .

2 comments:

Anonymous,  July 10, 2011  

Thanks for the info.Wanted to know whether you have cleaned the cache after executing the count(*) statement and then executed the count(1) statement?.

Dattatrey Sindol (Datta),  July 13, 2011  

Hi There,

I did clean the cache between each of the runs.
Irrespective of that, if you look at the execution plan, it is exactly the same.

Best Regards,
Datta

Post a Comment

Related Posts Plugin for WordPress, Blogger...

About the Author

Dattatrey Sindol is a BI Tech Lead & a passionate SQL Server Developer in a leading IT company.  read more »
Connect with Datta:

Thank You Visitors!

Hi There, Thanks for Visiting my Blog. Please feel free to leave your Comments/Suggestions about any of my Articles/My Blog.

Do Not Copy this Blog's Content !

Protected by Copyscape Online Copyright Checker