pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Implement new optimization rule for updates of expanded variable
Date: Tue, 11 Feb 2025 17:49:46 +0000
Message-ID: <E1thuOI-006aao-2h@gemulon.postgresql.org> (raw)

Implement new optimization rule for updates of expanded variables.

If a read/write expanded variable is declared locally to the
assignment statement that is updating it, and it is referenced
exactly once in the assignment RHS, then we can optimize the
operation as a direct update of the expanded value, whether
or not the function(s) operating on it can be trusted not to
modify the value before throwing an error.  This works because
if an error does get thrown, we no longer care what value the
variable has.

In cases where that doesn't work, fall back to the previous
rule that checks for safety of the top-level function.

In any case, postpone determination of whether these optimizations
are feasible until we are executing a Param referencing the target
variable and that variable holds a R/W expanded object.  While the
previous incarnation of exec_check_rw_parameter was pretty cheap,
this is a bit less so, and our plan to invoke support functions
will make it even less so.  So avoiding the check for variables
where it couldn't be useful should be a win.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com>
Discussion: https://postgr.es/m/CACxu=vJaKFNsYxooSnW1wEgsAO5u_v1XYBacfVJ14wgJV_PYeg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6c7251db0ce12a83dd03c840e7d0ff7516b27229

Modified Files
--------------
src/include/executor/execExpr.h               |   1 +
src/pl/plpgsql/src/expected/plpgsql_array.out |   9 +
src/pl/plpgsql/src/pl_exec.c                  | 383 ++++++++++++++++++++++----
src/pl/plpgsql/src/plpgsql.h                  |  22 +-
src/pl/plpgsql/src/sql/plpgsql_array.sql      |   9 +
src/tools/pgindent/typedefs.list              |   2 +
6 files changed, 364 insertions(+), 62 deletions(-)



Message-ID: <E1thuOI-006aao-2h@gemulon.postgresql.org>
Permalink:  ../E1thuOI-006aao-2h@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1thuOI-006aao-2h@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Implement new optimization rule for updates of expanded variable
  In-Reply-To: <E1thuOI-006aao-2h@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox