COUNT SQL 函数的性能 [英] Performance of COUNT SQL function

查看:33
本文介绍了COUNT SQL 函数的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 COUNT 函数编写 SQL 语句时,我有两种选择.

I have two choices when writing an SQL statement with the COUNT function.

  1. SELECT COUNT(*) FROM
  2. SELECT COUNT(some_column_name) FROM

就性能而言,最好的 SQL 语句是什么?我可以通过使用选项 1 获得一些性能提升吗?

In terms of performance, what is the best SQL statement? Can I obtain some performance gain by using option 1?

推荐答案

性能不重要,因为它们做了 2 个不同的聚合

Performance should not matter because they do 2 different aggregates

  • COUNT(*) 是所有行,包括 NULLs
  • COUNT(some_column_name),排除some_column_name"中的NULL
  • COUNT(*) is all rows, including NULLs
  • COUNT(some_column_name), excludes NULL in "some_column_name"

有关更多信息,请参阅Count(*) vs Count(1)"问题

See the "Count(*) vs Count(1)" question for more

这篇关于COUNT SQL 函数的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆