跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 4 千万的数据量, postgre order by 优化。
未分類
16 8 月 2020

4 千万的数据量, postgre order by 优化。

4 千万的数据量, postgre order by 优化。

資深大佬 : xmge 9

各位大佬,有个这样的数据库优化问题:

select xxxx,xxx from tables where a > xx order by update limit 100;  a 和 update 都有索引 

数据量 4 千万,执行 explain analyze 分析 sql 结果如下,主要的花费在于 Recheck Cond,

这个问题如何解决呢???

Sort  (cost=2058.65..2059.93 rows=512 width=89) (actual time=513.218..513.274 rows=333 loops=1)   Sort Key: updated   Sort Method: quicksort  Memory: 74kB   ->  Bitmap Heap Scan on Tables_XXX  (cost=20.53..2035.61 rows=512 width=89) (actual time=15.101..512.814 rows=333 loops=1)         Recheck Cond: ((user_id)::text = 'XXXXXXX'::text)         Heap Blocks: exact=318         ->  Bitmap Index Scan on XXXX_INDEX  (cost=0.00..20.41 rows=512 width=0) (actual time=11.006..11.006 rows=333 loops=1)               Index Cond: ((user_id)::text = 'XXXXXXX'::text) Planning time: 0.089 ms Execution time: 513.320 ms  

大佬有話說 (3)

  • 資深大佬 : MoYi123

    min_pk,max_pk = select min(primary_key), max(primary_key) from table where a > xx;
    select xxxx from tables where min_pk < pk and pk < max_pk and a > xx order by update limit 100;
    可以试一试这样有没有用。
    参考了这篇博客
    https://github.com/digoal/blog/blob/master/202007/20200710_01.md

  • 主 資深大佬 : xmge

    @MoYi123 好的,我看一下,感谢啦

  • 資深大佬 : yuan434356430

    把 postgre 的并行打开试试会不会变快

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具