From: Tom Lane <tgl@sss.pgh.pa.us>
To: David McNett <pglists@macnugget.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: Can query planner prefer a JOIN over a high-cost Function?
Date: Tue, 20 Aug 2013 15:52:52 -0400
Message-ID: <12172.1377028372@sss.pgh.pa.us> (raw)
In-Reply-To: <20130820180651.GA72756@macnugget.org>
References: <20130820180651.GA72756@macnugget.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
David McNett <pglists@macnugget.org> writes:
> Is there any way for me to influence the query planner so that it can
> know that the JOIN is far less expensive than the function for planning?
> The COST attribute on the function appears to have no effect.
I think what you're missing is an index on examples.code_id, which
would allow for a plan like this one:
Nested Loop (cost=154.41..205263.18 rows=2185 width=16)
-> Seq Scan on codes c (cost=0.00..1.06 rows=1 width=8)
Filter: ((code)::text = 'three'::text)
-> Bitmap Heap Scan on examples e (cost=154.41..205234.81 rows=2731 width=1
2)
Recheck Cond: (code_id = c.code_id)
Filter: (painfully_slow_function(example_id, value) IS TRUE)
-> Bitmap Index Scan on examples_code_id_idx (cost=0.00..153.73 rows=
8192 width=0)
Index Cond: (code_id = c.code_id)
If you really want to force the join to occur separately, you could
probably do something involving a sub-select with OFFSET 0, but I wouldn't
recommend pursuing that path unless you can't get a decent result without
contorting the query.
Another thing worth thinking about is whether you could precalculate the
expensive function via a functional index. It'd have to be immutable,
but if it is, this is a useful way of changing the ground rules.
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, pglists@macnugget.org
Subject: Re: Can query planner prefer a JOIN over a high-cost Function?
In-Reply-To: <12172.1377028372@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