【发布时间】:2014-09-02 08:28:51
【问题描述】:
我想尽可能快地计算表中与我的条件匹配的所有行。
所以,我有四个 SQL,希望你解释所有这些,每个 SQL 有什么不同?
哪个查询时间和服务器性能最快或最好?
或者它有另一种方法可以比这些更好。谢谢。
select count(*) as total from table where my_condition
select count(1) as total from table where my_condition
select count(primary_key) as total from table where my_condition
或
select * from table where my_condition
//and then use mysql_num_rows()
【问题讨论】:
-
前三个中的任何一个都应该优化我的 MySQL 以提供相同的性能。 last 效率非常低,因为它需要 MySQL 准备所有要返回的数据
-
前三个都是相当的。最后一个可能是性能噩梦,因为所有数据都需要传回应用程序。