search

Home  >  Q&A  >  body text

java - count(*)和count(1)区别?

count(*)和count(1)区别?

PHPzPHPz2893 days ago517

reply all(2)I'll reply

  • 阿神

    阿神2017-04-18 09:42:38

    You can see how your sql will be translated by mysql using the following sql

    EXPLAIN EXTENDED
    SELECT count(*) FROM `table`;
    SHOW WARNINGS;

    My version is mysql 5.6.26, the following is the translated result:

    /* select#1 */ select count(0) AS `count(*)` from `test`.`table`

    So, in my opinion, newer versions of mysql no longer have this difference, but I still use count(1) as a habit.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:42:38

    When the data records are not empty, there will be no difference in the query results. But when the column queried by COUNT(1) is empty, the empty ones will be removed and not recorded in the statistics. The results of this query It’s different.

    reply
    0
  • Cancelreply