V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
babyrjw
V2EX  ›  问与答

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

  •  
  •   babyrjw · 2019-04-18 14:01:13 +08:00 · 1043 次点击
    这是一个创建于 1834 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2019-04-19 09:51:39 +08:00
    leon0903
        1
    leon0903  
       2019-04-19 09:51:39 +08:00
    where 条件中的字段都有索引吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1317 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 23:33 · PVG 07:33 · LAX 16:33 · JFK 19:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.