SQL获取行数优化 [英] SQL getting row count optimization
问题描述
可能重复:
)之间有什么区别?
Count()vs Count(1)
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?
推荐答案
它们是不同的。
COUNT(*)
将检索所有值(甚至 NULL
值计数)。
COUNT(t.id)
不计算 NULL
值。
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).
这篇关于SQL获取行数优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!