문제

Possible Duplicate:
In SQL, what's the difference between count(column) and count()?
Count(
) vs Count(1)

I have big tables which keep long texts for example email content or news. And my question is there any difference for performance for counting table rows :

SELECT COUNT(*) FROM table_name

SELECT COUNT(t.id) FROM table_name as t

Which one is better? or the latter one will be optimized by query optimizer? Is there any documentation regarding this?

도움이 되었습니까?

해결책

They are different.

COUNT(*) will retrieve all values (even the NULL values count). COUNT(t.id) doesn't count the NULL values.


In terms of performance, they are the same (the query optimizer is smart).

다른 팁

Query plan looks the same, but in testing, using * is faster (slightly).

Nulls are not taking into account when specifying a column name though.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top