From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix calculation of which GENERATED columns need to be updated.
Date: Thu, 05 Jan 2023 19:12:34 +0000
Message-ID: <E1pDVfG-002Cs8-8v@gemulon.postgresql.org> (raw)
Fix calculation of which GENERATED columns need to be updated.
We were identifying the updatable generated columns of inheritance
children by transposing the calculation made for their parent.
However, there's nothing that says a traditional-inheritance child
can't have generated columns that aren't there in its parent, or that
have different dependencies than are in the parent's expression.
(At present it seems that we don't enforce that for partitioning
either, which is likely wrong to some degree or other; but the case
clearly needs to be handled with traditional inheritance.)
Hence, drop the very-klugy-anyway "extraUpdatedCols" RTE field
in favor of identifying which generated columns depend on updated
columns during executor startup. In HEAD we can remove
extraUpdatedCols altogether; in back branches, it's still there but
always empty. Another difference between the HEAD and back-branch
versions of this patch is that in HEAD we can add the new bitmap field
to ResultRelInfo, but that would cause an ABI break in back branches.
Like 4b3e37993, add a List field at the end of struct EState instead.
Back-patch to v13. The bogus calculation is also being made in v12,
but it doesn't have the same visible effect because we don't use it
to decide which generated columns to recalculate; as a consequence of
which the patch doesn't apply easily. I think that there might still
be a demonstrable bug associated with trigger firing conditions, but
that's such a weird corner-case usage that I'm content to leave it
unfixed in v12.
Amit Langote and Tom Lane
Discussion: https://postgr.es/m/CA+HiwqFshLKNvQUd1DgwJ-7tsTp=dwv7KZqXC4j2wYBV1aCDUA@mail.gmail.com
Discussion: https://postgr.es/m/2793383.1672944799@sss.pgh.pa.us
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/ad38e2f89116435cffd56507380d94e4eb588789
Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c | 4 +-
src/backend/executor/execUtils.c | 34 +++----
src/backend/executor/nodeModifyTable.c | 160 ++++++++++++++++++++++---------
src/backend/optimizer/util/inherit.c | 97 +++++++++++++++++--
src/backend/optimizer/util/plancat.c | 56 +++++++++++
src/backend/replication/logical/worker.c | 3 -
src/backend/rewrite/rewriteHandler.c | 40 --------
src/include/nodes/execnodes.h | 16 ++++
src/include/nodes/parsenodes.h | 9 +-
src/include/optimizer/inherit.h | 2 +
src/include/optimizer/plancat.h | 3 +
src/include/rewrite/rewriteHandler.h | 3 -
src/test/regress/expected/generated.out | 19 ++++
src/test/regress/sql/generated.sql | 9 ++
14 files changed, 329 insertions(+), 126 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix calculation of which GENERATED columns need to be updated.
In-Reply-To: <E1pDVfG-002Cs8-8v@gemulon.postgresql.org>
References: <E1pDVfG-002Cs8-8v@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