Re: A little cosmetic to convert_VALUES_to_ANY()

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: A little cosmetic to convert_VALUES_to_ANY()
Date: 2025-08-04 11:07:07
Message-ID: CAApHDvphU6T68p8JyM7pmpvTjfteUf5B2n_xPvG-dBEdUGcPbA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 27 Jul 2025 at 19:53, Tender Wang <tndrwang(at)gmail(dot)com> wrote:
> While debugging the pull-up sublink codes, I noticed the convert_VALUES_to_ANY().
> The function is to convert "where colX in VALUES(xxx)" into SAOP. It firstly scans the values_list to
> make sure no volatile function is in this list, then it scans this values_list again to check that it
> only includes Const items.
>
> We can merge the two scans into one. This can reduce the time complexity from 2O(n) to O(n).

I imagine that >95% of the time, probably more, the VALUES list is
going to contain only Consts, and if anything is done here, then it
likely should be to skip the convert_testexpr() /
eval_const_expressions() rigmarole when the input is already Const.

The proposal to move the contain_volatile_functions() doesn't seem
like a good idea to me as technically putting it where you propose
makes it mostly redundant (eval_const_expressions() will never
evaluate a volatile function and return a Const). I suspect it's there
because it's a slightly cheaper pre-check, and if you move it to
inside the loop then you may end up doing a bunch of work in
eval_const_expressions(), such as function inlining, which will just
be thrown away if you discover that the next item in the VALUES list
has a volatile.

Might be worth checking the planning overheads of large VALUES list
and seeing if it's worth putting the call to convert_testexpr() and
eval_const_expressions() inside an if (!IsA(value, Const)).

David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-08-04 12:05:04 Re: More protocol.h replacements this time into walsender.c
Previous Message Fujii Masao 2025-08-04 11:01:34 Re: Doc: Add note for running ANALYZE after ALTER TABLE ... SET EXPRESSION