pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix self-referencing foreign keys with partitioned tables 5+ messages / 1 participants [nested] [flat]
* pgsql: Fix self-referencing foreign keys with partitioned tables @ 2022-10-07 17:39 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-10-07 17:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix self-referencing foreign keys with partitioned tables There are a number of bugs in this area. Two of them are fixed here, namely: 1. get_relation_idx_constraint_oid does not restrict the type of constraint that's returned, so with sufficient bad luck it can return the OID of a foreign key constraint. This has the effect that a primary key in a partition can end up as a child of a foreign key, which makes no sense (it needs to be the child of the equivalent primary key.) Change the API contract so that only index-backed constraints are returned, mimicking get_constraint_index(). 2. Both CloneFkReferenced and CloneFkReferencing clone a self-referencing foreign key, so the partition ends up with a duplicate foreign key. Change the former function to ignore such constraints. Add some tests to verify that things are better now. (However, these new tests show some additional misbehavior that will be fixed later -- namely that there's a constraint marked NOT VALID.) Backpatch to 12, where these constraints are possible at all. Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://postgr.es/m/20220603154232.1715b14c@karst Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/614a406b4ff1b6f0f84b89fb56dca5175978177d Modified Files -------------- src/backend/catalog/pg_constraint.c | 13 ++++- src/backend/commands/tablecmds.c | 13 +++++ src/test/regress/expected/foreign_key.out | 81 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 55 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix self-referencing foreign keys with partitioned tables @ 2022-10-07 17:39 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-10-07 17:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix self-referencing foreign keys with partitioned tables There are a number of bugs in this area. Two of them are fixed here, namely: 1. get_relation_idx_constraint_oid does not restrict the type of constraint that's returned, so with sufficient bad luck it can return the OID of a foreign key constraint. This has the effect that a primary key in a partition can end up as a child of a foreign key, which makes no sense (it needs to be the child of the equivalent primary key.) Change the API contract so that only index-backed constraints are returned, mimicking get_constraint_index(). 2. Both CloneFkReferenced and CloneFkReferencing clone a self-referencing foreign key, so the partition ends up with a duplicate foreign key. Change the former function to ignore such constraints. Add some tests to verify that things are better now. (However, these new tests show some additional misbehavior that will be fixed later -- namely that there's a constraint marked NOT VALID.) Backpatch to 12, where these constraints are possible at all. Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://postgr.es/m/20220603154232.1715b14c@karst Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6083132abdd46462a0eca15412bb35fa3495eab2 Modified Files -------------- src/backend/catalog/pg_constraint.c | 13 ++++- src/backend/commands/tablecmds.c | 13 +++++ src/test/regress/expected/foreign_key.out | 81 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 55 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix self-referencing foreign keys with partitioned tables @ 2022-10-07 17:39 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-10-07 17:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix self-referencing foreign keys with partitioned tables There are a number of bugs in this area. Two of them are fixed here, namely: 1. get_relation_idx_constraint_oid does not restrict the type of constraint that's returned, so with sufficient bad luck it can return the OID of a foreign key constraint. This has the effect that a primary key in a partition can end up as a child of a foreign key, which makes no sense (it needs to be the child of the equivalent primary key.) Change the API contract so that only index-backed constraints are returned, mimicking get_constraint_index(). 2. Both CloneFkReferenced and CloneFkReferencing clone a self-referencing foreign key, so the partition ends up with a duplicate foreign key. Change the former function to ignore such constraints. Add some tests to verify that things are better now. (However, these new tests show some additional misbehavior that will be fixed later -- namely that there's a constraint marked NOT VALID.) Backpatch to 12, where these constraints are possible at all. Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://postgr.es/m/20220603154232.1715b14c@karst Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/483d26930b4c804cecb9b074021244bd4b1c8499 Modified Files -------------- src/backend/catalog/pg_constraint.c | 13 ++++- src/backend/commands/tablecmds.c | 13 +++++ src/test/regress/expected/foreign_key.out | 81 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 55 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix self-referencing foreign keys with partitioned tables @ 2022-10-07 17:39 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-10-07 17:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix self-referencing foreign keys with partitioned tables There are a number of bugs in this area. Two of them are fixed here, namely: 1. get_relation_idx_constraint_oid does not restrict the type of constraint that's returned, so with sufficient bad luck it can return the OID of a foreign key constraint. This has the effect that a primary key in a partition can end up as a child of a foreign key, which makes no sense (it needs to be the child of the equivalent primary key.) Change the API contract so that only index-backed constraints are returned, mimicking get_constraint_index(). 2. Both CloneFkReferenced and CloneFkReferencing clone a self-referencing foreign key, so the partition ends up with a duplicate foreign key. Change the former function to ignore such constraints. Add some tests to verify that things are better now. (However, these new tests show some additional misbehavior that will be fixed later -- namely that there's a constraint marked NOT VALID.) Backpatch to 12, where these constraints are possible at all. Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://postgr.es/m/20220603154232.1715b14c@karst Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7d520e68ea1e38a9f7ad1d04bd5f95d53eef6cd4 Modified Files -------------- src/backend/catalog/pg_constraint.c | 13 ++++- src/backend/commands/tablecmds.c | 13 +++++ src/test/regress/expected/foreign_key.out | 81 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 55 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
* pgsql: Fix self-referencing foreign keys with partitioned tables @ 2022-10-07 17:39 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 5+ messages in thread From: Alvaro Herrera @ 2022-10-07 17:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix self-referencing foreign keys with partitioned tables There are a number of bugs in this area. Two of them are fixed here, namely: 1. get_relation_idx_constraint_oid does not restrict the type of constraint that's returned, so with sufficient bad luck it can return the OID of a foreign key constraint. This has the effect that a primary key in a partition can end up as a child of a foreign key, which makes no sense (it needs to be the child of the equivalent primary key.) Change the API contract so that only index-backed constraints are returned, mimicking get_constraint_index(). 2. Both CloneFkReferenced and CloneFkReferencing clone a self-referencing foreign key, so the partition ends up with a duplicate foreign key. Change the former function to ignore such constraints. Add some tests to verify that things are better now. (However, these new tests show some additional misbehavior that will be fixed later -- namely that there's a constraint marked NOT VALID.) Backpatch to 12, where these constraints are possible at all. Author: Jehan-Guillaume de Rorthais <jgdr@dalibo.com> Discussion: https://postgr.es/m/20220603154232.1715b14c@karst Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/669803af04e6b4309b1b098162cce0cea7a82764 Modified Files -------------- src/backend/catalog/pg_constraint.c | 13 ++++- src/backend/commands/tablecmds.c | 13 +++++ src/test/regress/expected/foreign_key.out | 81 +++++++++++++++++++++++++++++++ src/test/regress/sql/foreign_key.sql | 55 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2022-10-07 17:39 UTC | newest] Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2022-10-07 17:39 pgsql: Fix self-referencing foreign keys with partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org> 2022-10-07 17:39 pgsql: Fix self-referencing foreign keys with partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org> 2022-10-07 17:39 pgsql: Fix self-referencing foreign keys with partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org> 2022-10-07 17:39 pgsql: Fix self-referencing foreign keys with partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org> 2022-10-07 17:39 pgsql: Fix self-referencing foreign keys with partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org>
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