From: Philipp Specht <phlybye@phlybye.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Stable function optimisation
Date: Wed, 15 Aug 2007 22:48:34 +0200
Message-ID: <62CBC6C5-93D8-4667-8143-02F6AF2B9C09@phlybye.de> (raw)
In-Reply-To: <21918.1187038900@sss.pgh.pa.us>
References: <2E281675-B282-41F6-B7A2-86853250850A@phlybye.de>
<21918.1187038900@sss.pgh.pa.us>
Hi Tom,
Thank you very much for your explanation.
On 13.08.2007, at 23:01, Tom Lane wrote:
> Philipp Specht <phlybye@phlybye.de> writes:
>> The biggest question here is: Why is the runtime of the query with
>> the stable function not near the runtime of the immutable function?
>
> Stable functions don't get folded to constants.
I tried to force this by using the following construct:
SELECT t.id, t.a FROM public.t WHERE t.a=(VALUES(public.f()));
Is this a bad practice and will destroy some other thing I can't
think of at the moment? What it means for me at the moment is about
half the query time of a high usage query directly linked to a gui.
That's a big gain for a user interface and takes the query under the
magical 500ms response time...
>> It's definitely one query and the manual states that a stable
>> function does not change in one statement and therefore can be
>> optimised.
>
> That's not the type of optimization that gets done with it. What
> "STABLE" is for is marking functions that are safe to use in index
> conditions. If you'd been using an indexable condition you'd have
> seen three different behaviors here.
>
> (I see that you do have an index on t.a, but apparently there are
> too many matching rows for the planner to think the index is worth
> using.)
Yes, that's not the real problem here. It's only a test database and
the real data behaves a bit differently.
Have a nice day,
Philipp
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: phlybye@phlybye.de, tgl@sss.pgh.pa.us
Subject: Re: Stable function optimisation
In-Reply-To: <62CBC6C5-93D8-4667-8143-02F6AF2B9C09@phlybye.de>
References: <2E281675-B282-41F6-B7A2-86853250850A@phlybye.de> <21918.1187038900@sss.pgh.pa.us> <62CBC6C5-93D8-4667-8143-02F6AF2B9C09@phlybye.de>
* 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