Home Forums SQL Server 7,2000 T-SQL SELECT COUNT(*) or COUNT(1) Performance or Benefits? RE: SELECT COUNT(*) or COUNT(1) Performance or Benefits?

  • Well, it might of course turn out that I went too far when I said that "COUNT(*) and COUNT(1) will never return different results and will always use the same plan, since they are treated as identical queries by the optimizer", since I have no way of knowing that for 100% certainty. (Oh, what I wouldn't do for the SQL Server source code)

    That said, I would like more information from your example to be convinced that they were not treated the same in your specific situation. It is very probable that the reason is that the pages were fetched from disk in the first case and directly from cache in the second, just as you speculate.

    >i think of '1' taking up less memory internally to process, but there's no real foundation for that.

    In what way would it take up less memory than '*'? They are both nothing more than a character in a sql statement that is parsed by the optimizer into an execution plan. The execution plans for COUNT(*) and COUNT(1) have always been equal in the situations that I have encountered, but if they were not in your example (or any other situation) then of course there could be a difference in execution time.