V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zbl430
V2EX  ›  PostgreSQL

Postgresql count 性能提升, 请大佬支招

  •  
  •   zbl430 · 2017-09-26 17:51:48 +08:00 · 2789 次点击
    这是一个创建于 2375 天前的主题,其中的信息可能已经有所发展或是发生改变。

    数据 3000w+,有两个 index

    select count(index) from table
    

    时间大概 10 分钟 google 等搜了很多,不是很清楚,这里向 v2 大佬请教, 如何提高 count 速度!

    4 条回复    2017-09-27 10:30:39 +08:00
    jetbillwin
        1
    jetbillwin  
       2017-09-26 20:51:50 +08:00   ❤️ 1
    你这个问题值几万块,找个靠谱的 DBA 咨询一下吧
    tomczhen
        2
    tomczhen  
       2017-09-26 21:08:41 +08:00   ❤️ 1
    通常这样做的目的是为了分页,实际阿里的 pgsql adb 德哥有专门发过一篇博客吐槽这个

    http://blog.163.com/digoal@126/blog/static/1638770402016468349463

    实际上根据业务情况也有一些不用 count 的方法来解决这个问题

    https://stackoverflow.com/questions/109232/what-is-the-best-way-to-paginate-results-in-sql-server
    est
        3
    est  
       2017-09-26 21:17:08 +08:00   ❤️ 1
    写入频繁不?

    写入频繁没法做。
    peihanw
        4
    peihanw  
       2017-09-27 10:30:39 +08:00   ❤️ 1
    升级到 9.6.x 版,启用 parallel 查询(根据 CPU 线程数调整配置文件中的 max_worker_processes 和 max_parallel_workers_per_gather 配置项),能大幅提高 OLAP 性能,分区表性能提高尤其明显。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3108 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:56 · PVG 20:56 · LAX 05:56 · JFK 08:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.