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

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

问题描述

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

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


  1. SELECT COUNT(*)FROM< table_name>

  2. SELECT COUNT(some_column_name)FROM< table_name>

  1. SELECT COUNT(*) FROM <table_name>
  2. SELECT COUNT(some_column_name) FROM <table_name>

就性能而言,最佳的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(*)是所有行,包括NULL

  • COUNT(some_column_name),在 some_column_name
  • $ b $中排除NULL b
  • COUNT(*) is all rows, including NULLs
  • COUNT(some_column_name), excludes NULL in "some_column_name"

请参阅 Count(*)vs Count(1)更多问题

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

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