Block creation of partitions with open references to its parent
authorMichael Paquier <michael@paquier.xyz>
Mon, 5 Nov 2018 02:04:02 +0000 (11:04 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 5 Nov 2018 02:04:02 +0000 (11:04 +0900)
commitdc3e436b191a8f8d6f35fad952dd3dc314ccabf9
tree892ae581aef96ed59ec942bea0df3544d5a2bfef
parent4bc772e2afa55f26734ff3fbdf27601db030b7e5
Block creation of partitions with open references to its parent

When a partition is created as part of a trigger processing, it is
possible that the partition which just gets created changes the
properties of the table the executor of the ongoing command relies on,
causing a subsequent crash.  This has been found possible when for
example using a BEFORE INSERT which creates a new partition for a
partitioned table being inserted to.

Any attempt to do so is blocked when working on a partition, with
regression tests added for both CREATE TABLE PARTITION OF and ALTER
TABLE ATTACH PARTITION.

Reported-by: Dmitry Shalashov
Author: Amit Langote
Reviewed-by: Michael Paquier, Tom Lane
Discussion: https://postgr.es/m/15437-3fe01ee66bd1bae1@postgresql.org
Backpatch-through: 10
src/backend/commands/tablecmds.c
src/test/regress/expected/alter_table.out
src/test/regress/expected/create_table.out
src/test/regress/sql/alter_table.sql
src/test/regress/sql/create_table.sql