pgsql: Fix bogus dependency handling for GENERATED expressions. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix bogus dependency handling for GENERATED expressions.
Date
Msg-id E1nWNFI-000kv4-L7@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix bogus dependency handling for GENERATED expressions.

For GENERATED columns, we record all dependencies of the generation
expression as AUTO dependencies of the column itself.  This means
that the generated column is silently dropped if any dependency
is removed, even if CASCADE wasn't specified.  This is at least
a POLA violation, but I think it's actually based on a misreading
of the standard.  The standard does say that you can't drop a
dependent GENERATED column in RESTRICT mode; but that's buried down
in a subparagraph, on a different page from some pseudocode that
makes it look like an AUTO drop is being suggested.

Change this to be more like the way that we handle regular default
expressions, ie record the dependencies as NORMAL dependencies of
the pg_attrdef entry.  Also, make the pg_attrdef entry's dependency
on the column itself be INTERNAL not AUTO.  That has two effects:

* the column will go away, not just lose its default, if any
dependency of the expression is dropped with CASCADE.  So we
don't need any special mechanism to make that happen.

* it provides an additional cross-check preventing someone from
dropping the default expression without dropping the column.

catversion bump because of change in the contents of pg_depend
(which also requires a change in one information_schema view).

Per bug #17439 from Kevin Humphreys.  Although this is a longstanding
bug, it seems impractical to back-patch because of the need for
catalog contents changes.

Discussion: https://postgr.es/m/17439-7df4421197e928f0@postgresql.org

Branch
------
master

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

Modified Files
--------------
src/backend/catalog/information_schema.sql |  12 ++-
src/backend/catalog/pg_attrdef.c           |  30 ++----
src/backend/commands/tablecmds.c           | 163 ++++++++++++++---------------
src/bin/pg_dump/pg_dump_sort.c             |   8 +-
src/include/catalog/catversion.h           |   2 +-
src/test/regress/expected/generated.out    |  11 +-
src/test/regress/sql/generated.sql         |   4 +-
7 files changed, 113 insertions(+), 117 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Move pg_attrdef manipulation code into new file catalog/pg_attrd
Next
From: Andres Freund
Date:
Subject: pgsql: pgstat: split different types of stats into separate files.