pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix ALTER TABLE DETACH for inconsistent indexes 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/83917791385a601bfe8afe95f250cb2ae6c1fde7 Modified Files -------------- src/backend/commands/tablecmds.c | 17 ++++++++++--- src/test/regress/expected/constraints.out | 42 +++++++++++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 40 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/30ca4e1ab1ffc1d7c4d5fe4afc800d946a585d96 Modified Files -------------- src/backend/commands/tablecmds.c | 17 ++++++++++--- src/test/regress/expected/constraints.out | 42 +++++++++++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 40 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/00a40e33c0a4b34e5c8456cd0b5ab4084bba78a0 Modified Files -------------- src/backend/commands/tablecmds.c | 17 ++++++++++--- src/test/regress/expected/constraints.out | 42 +++++++++++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 40 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4ae09c59d6f563531c456eda3147c849773ceaa7 Modified Files -------------- src/backend/commands/tablecmds.c | 17 ++++++++++--- src/test/regress/expected/constraints.out | 42 +++++++++++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 40 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/66aaa7a71841f0dda4c5e2918d4a7fe371c4b701 Modified Files -------------- src/backend/commands/tablecmds.c | 17 +++++++++--- src/test/regress/expected/sanity_check.out | 2 ++ src/test/regress/input/constraints.source | 40 ++++++++++++++++++++++++++++ src/test/regress/output/constraints.source | 42 ++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/05748256939b02bb1cfa23c0dea1c2ff02602587 Modified Files -------------- src/backend/commands/tablecmds.c | 17 +++++++++--- src/test/regress/expected/sanity_check.out | 2 ++ src/test/regress/input/constraints.source | 40 ++++++++++++++++++++++++++++ src/test/regress/output/constraints.source | 42 ++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix ALTER TABLE DETACH for inconsistent indexes @ 2024-07-12 10:55 Alvaro Herrera <alvherre@alvh.no-ip.org> 0 siblings, 0 replies; 7+ messages in thread From: Alvaro Herrera @ 2024-07-12 10:55 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix ALTER TABLE DETACH for inconsistent indexes When a partitioned table has an index that doesn't support a constraint, but a partition has an equivalent index that does, then a DETACH operation would misbehave: a crash in assertion-enabled systems (because we fail to find the constraint in the parent that we expect to), or a broken coninhcount value (-1) in production systems (because we blindly believe that we've successfully detached the parent). While we should reject an ATTACH of a partition with such an index, we have failed to do so in existing releases, so adding an error in stable releases might break the (unlikely) existing applications that rely on this behavior. At this point I don't even want to reject them in master, because it'd break pg_upgrade if such databases exist, and there would be no easy way to fix existing databases without expensive index rebuilds. (Later on we could add ALTER TABLE ... ADD CONSTRAINT USING INDEX to partitioned tables, which would allow the user to fix such patterns. At that point we could add more restrictions to prevent the problem from its root.) Also, add a test case that leaves one table in this condition, so that we can verify that pg_upgrade continues to work if we later decide to change the policy on the master branch. Backpatch to all supported branches. Co-authored-by: Tender Wang <tndrwang@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/18500-62948b6fe5522f56@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d0054432d480e958e4650c4b56de4a4a6e05da78 Modified Files -------------- src/backend/commands/tablecmds.c | 17 +++++++++--- src/test/regress/expected/sanity_check.out | 2 ++ src/test/regress/input/constraints.source | 40 ++++++++++++++++++++++++++++ src/test/regress/output/constraints.source | 42 ++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2024-07-12 10:55 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes Alvaro Herrera <alvherre@alvh.no-ip.org> 2024-07-12 10:55 pgsql: Fix ALTER TABLE DETACH for inconsistent indexes 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