babyrjw
V2EX  ›  问与答

mysql 2 千万记录全表扫描 2 小时

  •  
  •   babyrjw · Apr 18, 2019 · 1824 views
    This topic created in 2601 days ago, the information mentioned may be changed or developed.

    sql 如下,单条记录约 40 个字段,10 个索引,平均记录长度 1.5K ,2 千万记录表空间 16G 左右.
    16G 内存,高效云盘,该条 sql 执行 2 小时 10 分钟
    iostat 观察 r/s=450, rKB/s=11M. 11M 的速度,扫描完全表也就 2000s 吧,请教下为啥他要跑两个小时呢

    select o.enterprise_id, count(1) as num, sum(o.price) as price, now() as create_time
    from table_name as o
    where 1=1
    and (o.status = 6 or o.status = 2)
    and o.time >= '2015-06-01 00:00:00'
    and o.time <  '2025-07-01 00:00:00'
    group by o.enterprise_id
    order by null limit 1000
    
    1 replies    2019-04-19 09:51:39 +08:00
    leon0903
        1
    leon0903  
       Apr 19, 2019
    where 条件中的字段都有索引吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5404 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:13 · PVG 09:13 · LAX 18:13 · JFK 21:13
    ♥ Do have faith in what you're doing.