Re: functions: VOLATILE performs better than STABLE

From: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Peter <pmc(at)citylink(dot)dinoex(dot)sub(dot)org>, pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: functions: VOLATILE performs better than STABLE
Date: 2018-03-25 12:24:00
Message-ID: CAKJS1f8QwuNP9anQbPwcr4RLDR3JvW31c3L_H95tpn9HB2Fj8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 25 March 2018 at 18:00, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
> Peter wrote:
>> Over all, VOLATILE performs better than STABLE.
>
> The reason is that the subquery with the VOLATILE function can be
> flattened; see the EXPLAIN (VERBOSE) output.
>
> There is not guarantee that less volatility means better performance.

Although, it would be nice.

TPC-H Q1 does appear to be crafted to allow database with smarter
expression evaluation to get a better score.

It would probably require some sort of recursive expression evaluation
where at each level we check if that expression has already been seen,
if it has, then replace it with some sort of placeholder, then
evaluate each placeholder in the required order.

Probably the first part could be done during planning. It would mean
targetlists would need to carry a bit more weight.

It would be an interesting project to work on, but not planning to personally.

--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message bk 2018-03-25 18:18:44 Re: Slow planning time for custom function
Previous Message Laurenz Albe 2018-03-25 05:12:08 Re: Should from_collapse be switched off? (queries 10 times faster)