Re: [HACKERS] Function Volatility and Views Unexpected Behavior - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Function Volatility and Views Unexpected Behavior
Date
Msg-id 24070.1499887438@sss.pgh.pa.us
Whole thread Raw
In response to [HACKERS] Function Volatility and Views Unexpected Behavior  (David Kohn <djk447@gmail.com>)
Responses Re: [HACKERS] Function Volatility and Views Unexpected Behavior
Re: [HACKERS] Function Volatility and Views Unexpected Behavior
List pgsql-hackers
David Kohn <djk447@gmail.com> writes:
> I encountered some unexpected behavior when debugging a query that was
> taking longer than expected, basically, a volatile function that makes a
> column in a view is called even when that column is not selected in the
> query, making it so that the function is called for every row in the view,
> I'm not sure that that would necessarily be the expected behavior, as it
> was my understanding that columns that are not selected are not evaluated,
> for instance if there was a join in a view that produced some columns and
> said columns were not selected, I would expect it to be optimized away.

No, this is the expected behavior; we don't like optimization to change
the number of calls of a volatile function from what would occur in naive
evaluation of the query.  If that prospect doesn't bother you, it's
likely because your function isn't really volatile ...

> The other problem is that the function call does not appear in the query
> plan.

I think "explain verbose" will fix that for you.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] PostgreSQL10 beta2 with ICU - initdb fails on MacOS
Next
From: Peter Geoghegan
Date:
Subject: Re: [HACKERS] [WIP] Zipfian distribution in pgbench