zoukankan      html  css  js  c++  java
  • count(*) vs count(1)--social.msdn.microsoft.com

    Clever response Dave, but insufficient. I'll admit I've suggested this myself for certain questions but I think more is needed here. The OP may run one query where count(*) and count(1) return the same result and have the same performance, but that doesn't mean they always will. Similarly OP could test count(*) and count (<mycolumn>) and get the same performance, so assume they are always the same.

    Count(*) and count(1) both just count the number of rows. SQL Server processes them the same way.

    I know this is not what the OP asked, but just in case you were wondering:

    count(*) and count(<mycolumn>) may or not behave the same. Count(<mycolumn>) counts how many rows have VALUES, i.e. are not NULL for <mycolumn>, so SQL Server has to actually look at the column. For count(*) no values need to be examined, and any nonclustered index can be used to quickly determine the count of the rows. For count(<mycolumn>) the actual value in <mycolumn> must be examined, so it could be a lot slower, UNLESS <mycolumn> does not even allow NULLs and then count(<mycolumn>) is identical to count(*)

  • 相关阅读:
    composer国内镜像配置
    composer.json和composer.lock作用
    工厂模式(描述语言PHP)
    PHP后期静态绑定
    js事件冒泡和事件捕获
    去帮助别人,并接受别人的帮助
    平静,问题本身也是问题
    总是被欲望折磨的我
    习惯产生力量
    秦岭野生动物园
  • 原文地址:https://www.cnblogs.com/jiangfei5945/p/3396540.html
Copyright © 2011-2022 走看看