Quantcast
Viewing latest article 2
Browse Latest Browse All 118

Answer by Frank Heikens for Ways to speed up IN queries under PostgreSQL

IN() using many parameters will result in many cases in a sequential table scan. That might be slow, depending on table size and speed of your system.

Create a temporary table with all your variables and join on this table:

CREATE TEMP TABLE t AS   SELECT * FROM (VALUES(1),(2),(3)) x(twitter_user_id);SELECT   twitter_personas.* FROM twitter_personas   JOIN t USING(twitter_user_id);

Use EXPLAIN to see the difference between the queryplans.


Viewing latest article 2
Browse Latest Browse All 118

Trending Articles