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(*)

  • 相关阅读:
    什么是级联
    @GeneratedValue
    Spring Data JPA中CrudRepository与JpaRepository的不同
    Spring Data JPA的方法命名规则
    C/S架构的渗透测试-请求加解密及测试
    各类Fuzz字典
    Nessus8.11破解
    xss实验1-20writeup
    IIS短文件名漏洞
    Linux挂载exfat文件系统的U盘
  • 原文地址:https://www.cnblogs.com/jiangfei5945/p/3396540.html
Copyright © 2011-2022 走看看