Re: Function Volatility and Views Unexpected Behavior

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Kohn <djk447(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Function Volatility and Views Unexpected Behavior
Date: 2017-07-12 19:23:58
Message-ID: 24070.1499887438@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

David Kohn <djk447(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2017-07-12 19:30:46 Re: [WIP] Zipfian distribution in pgbench
Previous Message Tom Lane 2017-07-12 19:14:20 Re: PostgreSQL10 beta2 with ICU - initdb fails on MacOS