SELECT .. WHERE id IN(..)

From: Maks Materkov <materkov(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: SELECT .. WHERE id IN(..)
Date: 2015-05-17 03:44:37
Message-ID: CABVsJ4EPt5W+gCsdHss+B514FTdfPsk=Ei+5sM2fmJjCQM+GXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a database, table "users", with column "profile_id", and the
following query:

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

Result:

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,... 50 ids....}'::integer[]))

Planning time: 0.322 ms

Execution time: 5192.321 ms

This query takes ~5 seconds. (about ~5 million rows in table). I have a
btree index on this column. Is there any way to speed up query?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Samuel Smith 2015-05-17 04:49:37 Re: SELECT .. WHERE id IN(..)
Previous Message Mathew Moon 2015-05-16 20:14:14 Re: Removing and readding bdr nodes