小编ale*_*tos的帖子

提高查询速度:大postgres表中的简单SELECT

我在Postgres数据库的SELECT查询中遇到速度问题.

我有一个表有两个整数列作为键:(int1,int2)这个表有大约7000万行.

我需要在这种环境中进行两种简单的SELECT查询:

SELECT * FROM table WHERE int1=X;
SELECT * FROM table WHERE int2=X;
Run Code Online (Sandbox Code Playgroud)

这两个选择在这7000万个中返回大约10,000行.为了尽可能快地工作,我考虑使用两个HASH索引,每列一个.不幸的是结果并不那么好:

                                                               QUERY PLAN                                                               
----------------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on lec_sim  (cost=232.21..25054.38 rows=6565 width=36) (actual time=14.759..23339.545 rows=7871 loops=1)
   Recheck Cond: (lec2_id = 11782)
   ->  Bitmap Index Scan on lec_sim_lec2_hash_ind  (cost=0.00..230.56 rows=6565 width=0) (actual time=13.495..13.495 rows=7871 loops=1)
         Index Cond: (lec2_id = 11782)
 Total runtime: 23342.534 ms
(5 rows)
Run Code Online (Sandbox Code Playgroud)

这是其中一个查询的EXPLAIN ANALYZE示例.这需要大约23秒.我的期望是在不到一秒的时间内获得这些信息.

这些是postgres db config的一些参数:

work_mem = 128MB
shared_buffers = 2GB
maintenance_work_mem = 512MB
fsync = off
synchronous_commit = off …
Run Code Online (Sandbox Code Playgroud)

sql postgresql performance postgresql-performance

28
推荐指数
2
解决办法
5万
查看次数