From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Calculate extraUpdatedCols in query rewriter, not parser.
Date: Wed, 28 Oct 2020 17:47:16 +0000
Message-ID: <E1kXpXY-0002qU-MZ@gemulon.postgresql.org> (raw)
Calculate extraUpdatedCols in query rewriter, not parser.
It's unsafe to do this at parse time because addition of generated
columns to a table would not invalidate stored rules containing
UPDATEs on the table ... but there might now be dependent generated
columns that were not there when the rule was made. This also fixes
an oversight that rewriteTargetView failed to update extraUpdatedCols
when transforming an UPDATE on an updatable view. (Since the new
calculation is downstream of that, rewriteTargetView doesn't actually
need to do anything; but before, there was a demonstrable bug there.)
In v13 and HEAD, this leads to easily-visible bugs because (since
commit c6679e4fc) we won't recalculate generated columns that aren't
listed in extraUpdatedCols. In v12 this bitmap is mostly just used
for trigger-firing decisions, so you'd only notice a problem if a
trigger cared whether a generated column had been updated.
I'd complained about this back in May, but then forgot about it
until bug #16671 from Michael Paul Killian revived the issue.
Back-patch to v12 where this field was introduced. If existing
stored rules contain any extraUpdatedCols values, they'll be
ignored because the rewriter will overwrite them, so the bug will
be fixed even for existing rules. (But note that if someone were
to update to 13.1 or 12.5, store some rules with UPDATEs on tables
having generated columns, and then downgrade to a prior minor version,
they might observe issues similar to what this patch fixes. That
seems unlikely enough to not be worth going to a lot of effort to fix.)
Discussion: https://postgr.es/m/10206.1588964727@sss.pgh.pa.us
Discussion: https://postgr.es/m/16671-2fa55851859fb166@postgresql.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ad77039fad0f4128b0e4a05ddbf5dbc3ab5f3fa4
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 6 ++--
src/backend/parser/analyze.c | 33 ---------------------
src/backend/replication/logical/worker.c | 5 ++--
src/backend/rewrite/rewriteHandler.c | 41 +++++++++++++++++++++++++++
src/include/nodes/parsenodes.h | 16 +++++++----
src/include/parser/analyze.h | 2 --
src/include/rewrite/rewriteHandler.h | 3 ++
src/test/regress/expected/updatable_views.out | 35 +++++++++++++++++++++++
src/test/regress/sql/updatable_views.sql | 21 ++++++++++++++
9 files changed, 115 insertions(+), 47 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: Calculate extraUpdatedCols in query rewriter, not parser.
In-Reply-To: <E1kXpXY-0002qU-MZ@gemulon.postgresql.org>
References: <E1kXpXY-0002qU-MZ@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