zoukankan      html  css  js  c++  java
  • count(1) count(*)

    mysql> select 1 from t;
    +---+
    | 1 |
    +---+
    | 1 |
    | 1 |
    | 1 |
    | 1 |
    +---+
    4 rows in set (0.00 sec)
    mysql> select count(1) from t;    
    +----------+
    | count(1) |
    +----------+
    |        4 |
    +----------+
    1 row in set (0.00 sec)
    mysql> select count(*) from t; 
    +----------+
    | count(*) |
    +----------+
    |        4 |
    +----------+
    1 row in set (0.00 sec)
    mysql> select count(a) from t; 
    +----------+
    | count(a) |
    +----------+
    |        4 |
    +----------+
    1 row in set (0.00 sec)
    mysql> explain  extended SELECT count(*) FROM `employees`;
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    | id | select_type | table     | type  | possible_keys | key     | key_len | ref  | rows   | filtered | Extra       |
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    |  1 | SIMPLE      | employees | index | NULL          | PRIMARY | 4       | NULL | 299689 |   100.00 | Using index |
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    1 row in set, 1 warning (0.17 sec)
    
    mysql> show warnings;
    +-------+------+---------------------------------------------------------------------------+
    | Level | Code | Message                                                                   |
    +-------+------+---------------------------------------------------------------------------+
    | Note  | 1003 | /* select#1 */ select count(0) AS `count(*)` from `employees`.`employees` |
    +-------+------+---------------------------------------------------------------------------+
    1 row in set (0.17 sec)
    
    mysql> explain  extended SELECT count(1) FROM `employees`; 
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    | id | select_type | table     | type  | possible_keys | key     | key_len | ref  | rows   | filtered | Extra       |
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    |  1 | SIMPLE      | employees | index | NULL          | PRIMARY | 4       | NULL | 299689 |   100.00 | Using index |
    +----+-------------+-----------+-------+---------------+---------+---------+------+--------+----------+-------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> show warnings;
    +-------+------+---------------------------------------------------------------------------+
    | Level | Code | Message                                                                   |
    +-------+------+---------------------------------------------------------------------------+
    | Note  | 1003 | /* select#1 */ select count(1) AS `count(1)` from `employees`.`employees` |
    +-------+------+---------------------------------------------------------------------------+
    1 row in set (0.00 sec)
  • 相关阅读:
    「Wallace 笔记」K-D tree 区域查询时间复杂度简易证明
    「LOJ #2980」「THUSCH 2017」大魔法师
    「Wallace 笔记」快速上手回文自动机(PAM)
    「ZJU Summer Training 2020
    「AtCoder AGC002F」Leftmost Ball
    文案高手的18项修炼
    高性能MySQL实战
    300分钟搞懂 Spring Cloud
    腾讯产品启示录
    300分钟吃透分布式缓存
  • 原文地址:https://www.cnblogs.com/zengkefu/p/5635908.html
Copyright © 2011-2022 走看看