|
|
|
|
|
by feike
2487 days ago
|
|
Good set of tips, however "Not NOT IN" is not true in general, as a single counterexample: EXPLAIN (costs off)
SELECT relname, relpages
FROM pg_class
WHERE relname IN ('pg_class');
QUERY PLAN
---------------------------------------------------------
Index Scan using pg_class_relname_nsp_index on pg_class
Index Cond: (relname = 'pg_class'::name)
(2 rows)
In general, I'd like to echo other's comments, learning how to use EXPLAIN and how to interpret query plans is the single most important tool, as it allows you to verify your hypothesis instead of relying on rules-of-thumb. |
|
In my case `column IN ('value1', 'value2')` was converted to an array like this: `((column)::text ANY ('{value1,value2}'::text[]))`, an index on the column was completely ignored and PG performed a sequential scan.
After changing it to `column = ANY (VALUES ('value1'),('value2'))` it created a table in memory and used it when performing an index scan.
I have feeling this is maybe some kind of a bug in query planner? This is on PG 9.6.8.