Postgresql SELECT .. WHERE id IN(..)

时间:2015-05-16 05:29:31

标签: performance postgresql

我有一个PostgreSQL数据库,表"用户",列" profile_id",以及以下查询:

EXPLAIN ANALYZE SELECT * FROM users_user WHERE profile_id IN (...50 ids...);

结果:

Index Scan using users_user_83a0eb3f on users_user  (cost=0.50..292.22 rows=50 
width=633) (actual time=0.039..0.622 rows=44 loops=1)                           
   Index Cond: (profile_id = ANY ('{2445564,1653724,1835514,1117638,2601196,1170
249,1047955,2347907,2634669,2599371,1876555,2932700,1428467,1339658,2415523,1723
718,2701644,1022031,2771698,1622452,1249248,2528480,2993708,1375534,2707715,1277
817,2480505,1783574,2725279,1918554,1624481,2849270,1670688,2297767,2292362,2552
167,1847346,2280547,2646439,1283920,2413143,2444275,2174779,2153671,1813451,1052
229,1832442,1555770,2245620,1982318}'::integer[]))
     Planning time: 0.322 ms                                                        
     Execution time: 5192.321 ms

此查询大约需要5秒钟。 (表中大约约500万行)。我在这个专栏上有一个btree索引。有没有办法加快查询速度?

0 个答案:

没有答案
相关问题