okwork
V2EX  ›  问与答

MySQL 统计总数 count 算全表扫描吗?

  •  
  •   okwork · May 21, 2019 via Android · 3716 views
    This topic created in 2594 days ago, the information mentioned may be changed or developed.
    每隔一段时间要统计下表中的三个子类的总数目,count 汇总值,算全表扫描吗?
    6 replies    2019-05-22 14:54:02 +08:00
    WytheHuang
        1
    WytheHuang  
       May 22, 2019 via Android
    explain
    msg7086
        2
    msg7086  
       May 22, 2019
    请用等同生产的环境做 Explain。
    不同的版本、不同的变体、不同的引擎,甚至不同的表结构,都会导致优化不同。
    carlclone
        3
    carlclone  
       May 22, 2019
    计数器递增
    agostop
        4
    agostop  
       May 22, 2019
    用索引 count
    sdot96
        5
    sdot96  
       May 22, 2019 via Android
    看引擎
    nekoneko
        6
    nekoneko  
       May 22, 2019
    InnoDB:count(主键) 全表扫描累加,count(1)全表扫描累加,count(字段)分为字段可为空和字段不可为空,不可为空则读到后累加,可为空则读到后判断不为空累加。count(*) 不取值累加。除了 count(*)外其他都要取值基本上 count(*)是最快的

    MyISAM: 会记录一张表的行数,count 时直接返回行数
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   920 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 19:41 · PVG 03:41 · LAX 12:41 · JFK 15:41
    ♥ Do have faith in what you're doing.