pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Calculate extraUpdatedCols in query rewriter, not parser.
3+ messages / 1 participants
[nested] [flat]

* pgsql: Calculate extraUpdatedCols in query rewriter, not parser.
@ 2020-10-28 17:47  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2020-10-28 17:47 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Calculate extraUpdatedCols in query rewriter, not parser.
@ 2020-10-28 17:47  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2020-10-28 17:47 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/70492195be5e0283cf134c3c531ca0a23fdf9919

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Calculate extraUpdatedCols in query rewriter, not parser.
@ 2020-10-28 17:47  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2020-10-28 17:47 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/43330cdd40f12f352bc8f8100974c4b7eeb45d18

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2020-10-28 17:47 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 17:47 pgsql: Calculate extraUpdatedCols in query rewriter, not parser. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-28 17:47 pgsql: Calculate extraUpdatedCols in query rewriter, not parser. Tom Lane <tgl@sss.pgh.pa.us>
2020-10-28 17:47 pgsql: Calculate extraUpdatedCols in query rewriter, not parser. Tom Lane <tgl@sss.pgh.pa.us>

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