pgsql: Fix calculation of which GENERATED columns need to be updated. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix calculation of which GENERATED columns need to be updated.
Date
Msg-id E1pDVfG-002Cs2-7E@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: Fix calculation of which GENERATED columns need to be updated.  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-committers
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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3f7836ff651ad710fef52fa87b248ecdfc6468dc

Modified Files
--------------
src/backend/executor/execMain.c          |   1 +
src/backend/executor/execUtils.c         |  25 ++---
src/backend/executor/nodeModifyTable.c   | 154 +++++++++++++++++++++----------
src/backend/nodes/outfuncs.c             |   1 -
src/backend/nodes/readfuncs.c            |   1 -
src/backend/optimizer/util/inherit.c     | 107 ++++++++++-----------
src/backend/optimizer/util/plancat.c     |  56 +++++++++++
src/backend/replication/logical/worker.c |   5 -
src/backend/rewrite/rewriteHandler.c     |  45 ---------
src/include/nodes/execnodes.h            |   3 +
src/include/nodes/parsenodes.h           |  10 --
src/include/optimizer/plancat.h          |   3 +
src/include/rewrite/rewriteHandler.h     |   4 -
src/test/regress/expected/generated.out  |  19 ++++
src/test/regress/sql/generated.sql       |   9 ++
15 files changed, 257 insertions(+), 186 deletions(-)


pgsql-committers by date:

Previous
From: Alexander Korotkov
Date:
Subject: pgsql: meson: Add 'running' test setup, as a replacement for installche
Next
From: Robert Haas
Date:
Subject: pgsql: Refactor permissions-checking for role grants.