Re: Speeding up query pulling comments from pg_catalog

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Speeding up query pulling comments from pg_catalog
Date: 2019-07-22 19:57:18
Message-ID: 28922.1563825438@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> writes:
> On Sat, Jul 20, 2019 at 12:25 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> There's been assorted talk about various optimizations to
>> avoid unnecessary duplicate function calls,

> So I had read the sentence below to mean my functions would only get called
> once. But is that sentence only supposed to apply to index scans? Or does
> it mean the planner is allowed to optimize, but it just doesn't know how
> yet?

> A STABLE function cannot modify the database and is guaranteed to return
> the same results given the same arguments for all rows within a single
> statement. *This category allows the optimizer to optimize multiple calls
> of the function to a single call.*

It says "allows", not "requires". But in particular, we've interpreted
that to mean trying to call a stable function (with constant or at least
stable arguments) once per query rather than once per row, as the naive
interpretation of SQL semantics would have us do. Matching up textually
distinct calls has not been on the radar --- it seems fairly expensive
to do, with no return in typical queries, and relatively small return
even if we find a match.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Kristian Ejvind 2019-07-23 08:07:55 zabbix on postgresql - very slow delete of events
Previous Message Merlin Moncure 2019-07-22 18:32:09 Re: benchmarking effective_io_concurrency