]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Install dependencies to prevent dropping partition key columns.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Jul 2019 18:55:23 +0000 (14:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Jul 2019 18:55:23 +0000 (14:55 -0400)
commit0e1deaa4c4247ad89d0d3d4226a2eb85a894c778
tree8cba43aecdf5a03f3b369feb0fe9c58bc3460a09
parent8a4fa297a5ddaa41390f76f04556556399cf9a29
Install dependencies to prevent dropping partition key columns.

The logic in ATExecDropColumn that rejects dropping partition key
columns is quite an inadequate defense, because it doesn't execute
in cases where a column needs to be dropped due to cascade from
something that only the column, not the whole partitioned table,
depends on.  That leaves us with a badly broken partitioned table;
even an attempt to load its relcache entry will fail.

We really need to have explicit pg_depend entries that show that the
column can't be dropped without dropping the whole table.  Hence,
add those entries.  In v12 and HEAD, bump catversion to ensure that
partitioned tables will have such entries.  We can't do that in
released branches of course, so in v10 and v11 this patch affords
protection only to partitioned tables created after the patch is
installed.  Given the lack of field complaints (this bug was found
by fuzz-testing not by end users), that's probably good enough.

In passing, fix ATExecDropColumn and ATPrepAlterColumnType
messages to be more specific about which partition key column
they're complaining about.

Per report from Manuel Rigger.  Back-patch to v10 where partitioned
tables were added.

Discussion: https://postgr.es/m/CA+u7OA4JKCPFrdrAbOs7XBiCyD61XJxeNav4LefkSmBLQ-Vobg@mail.gmail.com
Discussion: https://postgr.es/m/31920.1562526703@sss.pgh.pa.us
src/backend/catalog/dependency.c
src/backend/catalog/heap.c
src/backend/commands/tablecmds.c
src/bin/pg_dump/pg_dump_sort.c
src/include/catalog/dependency.h
src/test/regress/expected/alter_table.out
src/test/regress/expected/create_table.out
src/test/regress/sql/create_table.sql