Re: Optimze usage of immutable functions as relation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aleksandr Parfenov <asp437(at)gmail(dot)com>
Cc: a(dot)bykov(at)postgrespro(dot)ru, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Optimze usage of immutable functions as relation
Date: 2018-11-16 19:03:46
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Aleksandr Parfenov <asp437(at)gmail(dot)com> writes:
> [ funcscan_plan_optimizer_v4.patch ]

A small note here --- this would be noticeably cleaner if removal of
the no-longer-needed function RTE were done using the dummy-relation
infrastructure I proposed in

Maybe we should get that done first and then come back to this.

I'm a bit suspicious of the premise of this though, because it's
going to result in a single call of a function being converted
into possibly many calls, if the RTE is referenced in a lot of
places. Even if the function is immutable so that those calls
get evaluated at plan time not run time, it's still N calls not
one, which'd be bad if the function is expensive. See e.g.

for an example where we're specifically telling people that
they can put a function into FROM to avoid multiple evaluation.
This patch breaks that guarantee.

A possible fix for this is to do eval_const_expressions() on
function RTE expressions at this stage (and then not need to
do it later), and then pull up only when we find that the
RTE expression has been reduced to a single Const. I'm not
sure whether invoking eval_const_expressions() so early
would create any issues. But if it can be made to work, this
would eliminate quite a lot of the ad-hoc conditions that
you have in the patch now.

regards, tom lane

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-11-16 19:59:52 Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors
Previous Message Tom Lane 2018-11-16 18:35:15 Re: Problem while updating a foreign table pointing to a partitioned table on foreign server