Re: Optimze usage of immutable functions as relation

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Aleksandr Parfenov <a(dot)parfenov(at)postgrespro(dot)ru>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Optimze usage of immutable functions as relation
Date: 2018-05-08 10:15:23
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>>>> "Aleksandr" == Aleksandr Parfenov <a(dot)parfenov(at)postgrespro(dot)ru> writes:

>> From an implementation point of view your patch is obviously broken
>> in many ways (starting with not checking varattno anywhere, and not
>> actually checking anywhere if the expression is volatile).

Aleksandr> The actual checking if the expression volatile or not is
Aleksandr> done inside evaluate_function(). This is called through few
Aleksandr> more function in eval_const_experssion(). If it's volatile,
Aleksandr> the eval_const_expression() will return FuncExpr node, Const
Aleksandr> otherwise. It also checks are arguments immutable or not.

You're missing a ton of other possible cases, of which by far the most
notable is function inlining: eval_const_expressions will inline even a
volatile function and return a new expression tree (which could be
almost anything depending on the function body).

Aleksandr> I agree about varattno, it should be checked. Even in case
Aleksandr> of SRF not replaced, it is better to be sure that Var points
Aleksandr> to first (and the only) attribute.

It's not a matter of "better", but of basic correctness. Functions can
return composite values with columns.

Andrew (irc:RhodiumToad)

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-05-08 10:58:32 Re: [HACKERS] WIP Patch: Pgbench Serialization and deadlock errors
Previous Message Aleksandr Parfenov 2018-05-08 09:56:16 Re: Optimze usage of immutable functions as relation