pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Ensure that MERGE recomputes GENERATED expressions properly.
2+ messages / 1 participants
[nested] [flat]

* pgsql: Ensure that MERGE recomputes GENERATED expressions properly.
@ 2023-01-30 10:10 Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Dean Rasheed @ 2023-01-30 10:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Ensure that MERGE recomputes GENERATED expressions properly.

This fixes a bug that, under some circumstances, would cause MERGE to
fail to properly recompute expressions for GENERATED STORED columns.

Formerly, ExecInitModifyTable() did not call ExecInitStoredGenerated()
for a MERGE command, which meant that the generated expressions
information was not computed until later, when the first merge action
was executed. However, if the first merge action to execute was an
UPDATE, then ExecInitStoredGenerated() could decide to skip some some
generated columns, if the columns on which they depended were not
updated, which was a problem if the MERGE also contained an INSERT
action, for which no generated columns should be skipped.

So fix by having ExecInitModifyTable() call ExecInitStoredGenerated()
for MERGE, and assume that it isn't safe to skip any generated columns
in a MERGE. Possibly that could be relaxed, by allowing some generated
columns to be skipped for a MERGE without an INSERT action, but it's
not clear that it's worth the effort.

Noticed while investigating bug #17759. Back-patch to v15, where MERGE
was added.

Dean Rasheed, reviewed by Tom Lane.

Discussion:
  https://postgr.es/m/17759-e76d9bece1b5421c%40postgresql.org
  https://postgr.es/m/CAEZATCXb_ezoMCcL0tzKwRGA1x0oeE%3DawTaysRfTPq%2B3wNJn8g%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fe9e658f4d7fbc12d2b6a74c4ee90c73e53d68ef

Modified Files
--------------
src/backend/executor/nodeModifyTable.c  |  4 ++--
src/test/regress/expected/generated.out | 20 ++++++++++++++++++++
src/test/regress/sql/generated.sql      | 15 +++++++++++++++
3 files changed, 37 insertions(+), 2 deletions(-)



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

* pgsql: Ensure that MERGE recomputes GENERATED expressions properly.
@ 2023-01-30 10:10 Dean Rasheed <dean.a.rasheed@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Dean Rasheed @ 2023-01-30 10:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Ensure that MERGE recomputes GENERATED expressions properly.

This fixes a bug that, under some circumstances, would cause MERGE to
fail to properly recompute expressions for GENERATED STORED columns.

Formerly, ExecInitModifyTable() did not call ExecInitStoredGenerated()
for a MERGE command, which meant that the generated expressions
information was not computed until later, when the first merge action
was executed. However, if the first merge action to execute was an
UPDATE, then ExecInitStoredGenerated() could decide to skip some some
generated columns, if the columns on which they depended were not
updated, which was a problem if the MERGE also contained an INSERT
action, for which no generated columns should be skipped.

So fix by having ExecInitModifyTable() call ExecInitStoredGenerated()
for MERGE, and assume that it isn't safe to skip any generated columns
in a MERGE. Possibly that could be relaxed, by allowing some generated
columns to be skipped for a MERGE without an INSERT action, but it's
not clear that it's worth the effort.

Noticed while investigating bug #17759. Back-patch to v15, where MERGE
was added.

Dean Rasheed, reviewed by Tom Lane.

Discussion:
  https://postgr.es/m/17759-e76d9bece1b5421c%40postgresql.org
  https://postgr.es/m/CAEZATCXb_ezoMCcL0tzKwRGA1x0oeE%3DawTaysRfTPq%2B3wNJn8g%40mail.gmail.com

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4785af9e6318856d45e51fbc328d52f6c5340e13

Modified Files
--------------
src/backend/executor/nodeModifyTable.c  |  4 ++--
src/test/regress/expected/generated.out | 20 ++++++++++++++++++++
src/test/regress/sql/generated.sql      | 15 +++++++++++++++
3 files changed, 37 insertions(+), 2 deletions(-)



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


end of thread, other threads:[~2023-01-30 10:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30 10:10 pgsql: Ensure that MERGE recomputes GENERATED expressions properly. Dean Rasheed <dean.a.rasheed@gmail.com>
2023-01-30 10:10 pgsql: Ensure that MERGE recomputes GENERATED expressions properly. Dean Rasheed <dean.a.rasheed@gmail.com>

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