From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mathieu De Zutter <mathieu@dezutter.org>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Query plan change with multiple elements in IN clause
Date: Fri, 30 Aug 2013 10:00:28 -0400
Message-ID: <5899.1377871228@sss.pgh.pa.us> (raw)
In-Reply-To: <CAH7GKCzV_ZSBodUaT9ui406o-0Ak9WNHWW=yCMThj8CE_QJXQQ@mail.gmail.com>
References: <CAH7GKCzV_ZSBodUaT9ui406o-0Ak9WNHWW=yCMThj8CE_QJXQQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Mathieu De Zutter <mathieu@dezutter.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
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, mathieu@dezutter.org
Subject: Re: Query plan change with multiple elements in IN clause
In-Reply-To: <5899.1377871228@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox