From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Mathieu De Zutter <mathieu(at)dezutter(dot)org> |
Cc: | pgsql-performance <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: Query plan change with multiple elements in IN clause |
Date: | 2013-08-30 14:00:28 |
Message-ID: | 5899.1377871228@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Mathieu De Zutter <mathieu(at)dezutter(dot)org> writes:
> The problem is that this join is performing very badly when more than one
> work is involved. It chooses a plan that is orders of magnitude slower.
> I have attached
> - The (simplified) table definitions
> - The (simplified) view
> - Two queries with explain analyze plan: "IN (1)" => fast, "IN (1,3)" =>
> slow
> - postgresql.conf
The reason you get a nice plan in the first case is that "w.id in (1)"
is treated as "w.id = 1", and then there is logic that combines that with
"w.id = wps.id" to conclude that we can synthesize a condition "wps.id = 1".
None of that happens when there's more than one IN item, because it's not
an equality operator anymore.
You might be able to do something like
JOIN (VALUES (1),(3)) foo(x) ON w.id = foo.x
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Łukasz Walkowski | 2013-08-31 13:35:58 | Varchar vs foreign key vs enumerator - table and index size |
Previous Message | Mathieu De Zutter | 2013-08-30 09:05:46 | Query plan change with multiple elements in IN clause |