pgsql: Add support for NOT ENFORCED in foreign key constraints
От | Peter Eisentraut |
---|---|
Тема | pgsql: Add support for NOT ENFORCED in foreign key constraints |
Дата | |
Msg-id | E1tzwW2-002HaO-0C@gemulon.postgresql.org обсуждение исходный текст |
Список | pgsql-committers |
Add support for NOT ENFORCED in foreign key constraints This expands the NOT ENFORCED constraint flag, previously only supported for CHECK constraints (commit ca87c415e2f), to foreign key constraints. Normally, when a foreign key constraint is created on a table, action and check triggers are added to maintain data integrity. With this patch, if a constraint is marked as NOT ENFORCED, integrity checks are no longer required, making these triggers unnecessary. Consequently, when creating a NOT ENFORCED foreign key constraint, triggers will not be created, and the constraint will be marked as NOT VALID. Similarly, if an existing foreign key constraint is changed to NOT ENFORCED, the associated triggers will be dropped, and the constraint will also be marked as NOT VALID. Conversely, if a NOT ENFORCED foreign key constraint is changed to ENFORCED, the necessary triggers will be created, and the will be changed to VALID by performing necessary validation. Since not-enforced foreign key constraints have no triggers, the shortcut used for example in psql and pg_dump to skip looking for foreign keys if the relation is known not to have triggers no longer applies. (It already didn't work for partitioned tables.) Author: Amul Sul <sulamul@gmail.com> Reviewed-by: Joel Jacobson <joel@compiler.org> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: jian he <jian.universality@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Isaac Morland <isaac.morland@gmail.com> Reviewed-by: Alexandra Wang <alexandra.wang.oss@gmail.com> Tested-by: Triveni N <triveni.n@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/CAAJ_b962c5AcYW9KUt_R_ER5qs3fUGbe4az-SP-vuwPS-w-AGA@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/eec0040c4bcd650993bb058ebdf61ab94171fda4 Modified Files -------------- doc/src/sgml/catalogs.sgml | 1 - doc/src/sgml/ref/alter_table.sgml | 5 +- doc/src/sgml/ref/create_table.sgml | 2 +- src/backend/catalog/pg_constraint.c | 5 +- src/backend/catalog/sql_features.txt | 2 +- src/backend/commands/tablecmds.c | 473 ++++++++++++++++++++++++------ src/backend/optimizer/util/plancat.c | 4 + src/backend/parser/gram.y | 9 +- src/backend/parser/parse_utilcmd.c | 14 +- src/backend/utils/cache/relcache.c | 6 +- src/bin/pg_dump/pg_dump.c | 8 +- src/bin/psql/describe.c | 216 +++++++------- src/include/nodes/parsenodes.h | 2 + src/include/utils/rel.h | 3 + src/test/regress/expected/constraints.out | 8 +- src/test/regress/expected/foreign_key.out | 194 +++++++++++- src/test/regress/expected/inherit.out | 81 ++--- src/test/regress/sql/foreign_key.sql | 119 +++++++- src/test/regress/sql/inherit.sql | 7 + 19 files changed, 885 insertions(+), 274 deletions(-)
В списке pgsql-committers по дате отправления: