<bdo id='hEHEb'></bdo><ul id='hEHEb'></ul>

    <small id='hEHEb'></small><noframes id='hEHEb'>

    1. <tfoot id='hEHEb'></tfoot>
      <legend id='hEHEb'><style id='hEHEb'><dir id='hEHEb'><q id='hEHEb'></q></dir></style></legend>
      <i id='hEHEb'><tr id='hEHEb'><dt id='hEHEb'><q id='hEHEb'><span id='hEHEb'><b id='hEHEb'><form id='hEHEb'><ins id='hEHEb'></ins><ul id='hEHEb'></ul><sub id='hEHEb'></sub></form><legend id='hEHEb'></legend><bdo id='hEHEb'><pre id='hEHEb'><center id='hEHEb'></center></pre></bdo></b><th id='hEHEb'></th></span></q></dt></tr></i><div id='hEHEb'><tfoot id='hEHEb'></tfoot><dl id='hEHEb'><fieldset id='hEHEb'></fieldset></dl></div>
    2. MYSQL count(*) 和 count(1) 哪个更好?

      时间:2023-06-03

      <legend id='R3p1H'><style id='R3p1H'><dir id='R3p1H'><q id='R3p1H'></q></dir></style></legend>
      • <tfoot id='R3p1H'></tfoot>
            <tbody id='R3p1H'></tbody>

            <i id='R3p1H'><tr id='R3p1H'><dt id='R3p1H'><q id='R3p1H'><span id='R3p1H'><b id='R3p1H'><form id='R3p1H'><ins id='R3p1H'></ins><ul id='R3p1H'></ul><sub id='R3p1H'></sub></form><legend id='R3p1H'></legend><bdo id='R3p1H'><pre id='R3p1H'><center id='R3p1H'></center></pre></bdo></b><th id='R3p1H'></th></span></q></dt></tr></i><div id='R3p1H'><tfoot id='R3p1H'></tfoot><dl id='R3p1H'><fieldset id='R3p1H'></fieldset></dl></div>

              • <bdo id='R3p1H'></bdo><ul id='R3p1H'></ul>

              • <small id='R3p1H'></small><noframes id='R3p1H'>

                本文介绍了MYSQL count(*) 和 count(1) 哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                相关(SQL Server): Count(*) vs Count(1)

                你能告诉我什么是更好的性能(MySQL)吗?计数(*)还是计数(1)?

                Could you please tell me what is better in performance (MySQL)? Count(*) or count(1)?

                推荐答案

                这是 MySQL 的答案.

                This is a MySQL answer.

                它们的执行完全相同 - 除非您使用的是 MyISAM,否则存在 COUNT(*) 的特殊情况.无论如何,我总是使用 COUNT(*).

                They perform exactly the same - unless you are using MyISAM, then a special case for COUNT(*) exists. I always use COUNT(*) anyway.

                https://dev.mysql.com/doc/refman/5.6/en/aggregate-functions.html#function_count

                对于 MyISAM 表,COUNT(*) 被优化为快速返回,如果SELECT 从一张表中检索,不检索其他列,并且没有 WHERE 子句.例如:

                For MyISAM tables, COUNT(*) is optimized to return very quickly if the SELECT retrieves from one table, no other columns are retrieved, and there is no WHERE clause. For example:

                mysql> SELECT COUNT(*) FROM student;
                

                此优化仅适用于MyISAM表,因为为此存储引擎存储了精确的行数并且可以非常快速地访问.COUNT(1) 只受相同如果第一列定义为NOT NULL,则优化.

                This optimization only applies to MyISAM tables, because an exact row count is stored for this storage engine and can be accessed very quickly. COUNT(1) is only subject to the same optimization if the first column is defined as NOT NULL.

                <小时>###编辑你们中的一些人可能错过了幽默的黑暗尝试.我更愿意将此作为一个非重复的问题,以便 MySQL 对 SQL Server 做一些不同的事情.所以我投票重新提出这个问题(答案显然是错误的).

                上述MyISAM优化同样适用于


                ###EDIT Some of you may have missed the dark attempt at humour. I prefer to keep this as a non-duplicate question for any such day when MySQL will do something different to SQL Server. So I threw a vote to reopen the question (with a clearly wrong answer).

                The above MyISAM optimization applies equally to

                COUNT(*)
                COUNT(1)
                COUNT(pk-column)
                COUNT(any-non-nullable-column)
                

                所以真正的答案是它们总是相同.

                So the real answer is that they are always the same.

                这篇关于MYSQL count(*) 和 count(1) 哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 MySQL 中按 SUM() 排序? 下一篇:在 MYSQL 中批量插入

                相关文章

                  <bdo id='W5diP'></bdo><ul id='W5diP'></ul>

                1. <i id='W5diP'><tr id='W5diP'><dt id='W5diP'><q id='W5diP'><span id='W5diP'><b id='W5diP'><form id='W5diP'><ins id='W5diP'></ins><ul id='W5diP'></ul><sub id='W5diP'></sub></form><legend id='W5diP'></legend><bdo id='W5diP'><pre id='W5diP'><center id='W5diP'></center></pre></bdo></b><th id='W5diP'></th></span></q></dt></tr></i><div id='W5diP'><tfoot id='W5diP'></tfoot><dl id='W5diP'><fieldset id='W5diP'></fieldset></dl></div>

                2. <legend id='W5diP'><style id='W5diP'><dir id='W5diP'><q id='W5diP'></q></dir></style></legend>

                3. <small id='W5diP'></small><noframes id='W5diP'>

                4. <tfoot id='W5diP'></tfoot>