Skip to content

Backport 8540: Fix deadlock adding named constraint with long partition name (#7799)…#8560

Open
codeforall wants to merge 1 commit intorelease-14.0from
muusama/8540-14
Open

Backport 8540: Fix deadlock adding named constraint with long partition name (#7799)…#8560
codeforall wants to merge 1 commit intorelease-14.0from
muusama/8540-14

Conversation

@codeforall
Copy link
Copy Markdown
Contributor

… (#8540)

DESCRIPTION: Fix deadlock when adding named constraint on partitioned table with long partition name.

Previously, SwitchToSequentialAndLocalExecutionIfConstraintNameTooLong was only called when the user did NOT provide an explicit constraint name. When a name was provided (e.g., ALTER TABLE ... ADD CONSTRAINT myname UNIQUE(...)), the code fell through to the standard parallel DDL path without checking if the auto-generated constraint names on partition shards would exceed NAMEDATALEN, causing potential self-deadlocks.

This commit adds calls to
SwitchToSequentialAndLocalExecutionIfConstraintNameTooLong for both named foreign key constraints and named non-FK constraints (PRIMARY KEY, UNIQUE, EXCLUDE, CHECK) in PreprocessAlterTableStmt, so that the long partition shard name check is performed regardless of whether the user specified a constraint name.

Also adds regression tests covering named PRIMARY KEY, UNIQUE, and CHECK constraints on partitioned tables with long partition names, including the error case when a parallel query has already been executed in the same transaction.

DESCRIPTION: PR description that will go into the change log, up to 78 characters

DESCRIPTION: PR description that will go into the change log, up to 78 characters

…#8540)

DESCRIPTION: Fix deadlock when adding named constraint on partitioned
table with long partition name.

Previously, SwitchToSequentialAndLocalExecutionIfConstraintNameTooLong
was only called when the user did NOT provide an explicit constraint
name. When a name was provided (e.g., ALTER TABLE ... ADD CONSTRAINT
myname UNIQUE(...)), the code fell through to the standard parallel DDL
path without checking if the auto-generated constraint names on
partition shards would exceed NAMEDATALEN, causing potential
self-deadlocks.

This commit adds calls to
SwitchToSequentialAndLocalExecutionIfConstraintNameTooLong for both
named foreign key constraints and named non-FK constraints (PRIMARY KEY,
UNIQUE, EXCLUDE, CHECK) in PreprocessAlterTableStmt, so that the long
partition shard name check is performed regardless of whether the user
specified a constraint name.

Also adds regression tests covering named PRIMARY KEY, UNIQUE, and CHECK
constraints on partitioned tables with long partition names, including
the error case when a parallel query has already been executed in the
same transaction.

DESCRIPTION: PR description that will go into the change log, up to 78
characters
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.24%. Comparing base (d5731d7) to head (fce1660).

❌ Your project check has failed because the head coverage (63.24%) is below the target coverage (87.50%). You can increase the head coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (d5731d7) and HEAD (fce1660). Click for more details.

HEAD has 110 uploads less than BASE
Flag BASE (d5731d7) HEAD (fce1660)
18_regress_check-query-generator 1 0
18_regress_check-tap 1 0
18_regress_check-follower-cluster 1 0
16_regress_check-tap 1 0
17_regress_check-follower-cluster 1 0
18_regress_check-columnar-isolation_14.0-1_v14.0.0_workeronly 1 0
18_regress_check-follower-cluster_14.0-1_all 1 0
17_regress_check-columnar-isolation 1 0
17_regress_check-pytest 1 0
18_regress_check-enterprise-isolation-logicalrep-2 1 0
18_regress_check-columnar_v14.0.0_all 1 0
18_regress_check-columnar 1 0
17_regress_check-enterprise-isolation-logicalrep-2 1 0
18_regress_check-add-backup-node_14.0-1_all 1 0
18_regress_check-columnar_14.0-1_all 1 0
18_regress_check-enterprise-isolation-logicalrep-3 1 0
18_regress_check-columnar-isolation 1 0
16_regress_check-columnar-isolation 1 0
17_regress_check-add-backup-node 1 0
18_regress_check-follower-cluster_14.0-1_v14.0.0_coordinatoronly 1 0
16_regress_check-add-backup-node 1 0
18_regress_check-columnar-isolation_14.0-1_all 1 0
16_regress_check-vanilla 1 0
18_regress_check-vanilla 1 0
17_regress_check-enterprise 1 0
16_regress_check-enterprise-isolation-logicalrep-2 1 0
18_regress_check-enterprise_14.0-1_all 1 0
17_regress_check-multi-1-create-citus 1 0
16_regress_check-enterprise-isolation 1 0
18_regress_check-enterprise-isolation_14.0-1_all 1 0
17_regress_check-query-generator 1 0
18_regress_check-enterprise-isolation 1 0
16_regress_check-follower-cluster 1 0
17_regress_check-multi-mx 1 0
16_regress_check-enterprise-isolation-logicalrep-3 1 0
18_regress_check-columnar_14.0-1_v14.0.0_workeronly 1 0
18_regress_check-split_14.0-1_all 1 0
18_regress_check-enterprise-failure 1 0
18_regress_check-enterprise-isolation-logicalrep-1 1 0
18_regress_check-enterprise-isolation-logicalrep-1_14.0-1_v14.0.0_workeronly 1 0
18_regress_check-enterprise_14.0-1_v14.0.0_workeronly 1 0
16_regress_check-multi-1-create-citus 1 0
17_regress_check-columnar 1 0
18_cdc_installcheck 1 0
18_regress_check-operations_14.0-1_v14.0.0_workeronly 1 0
16_regress_check-operations 1 0
18_regress_check-operations_v14.0.0_all 1 0
18_regress_check-operations_14.0-1_all 1 0
18_regress_check-isolation 1 0
18_regress_check-operations_14.0-1_v14.0.0_coordinatoronly 1 0
16_regress_check-failure 1 0
18_regress_check-enterprise-isolation-logicalrep-1_14.0-1_all 1 0
18_regress_check-enterprise 1 0
16_regress_check-enterprise-isolation-logicalrep-1 1 0
18_regress_check-enterprise-isolation-logicalrep-1_14.0-1_v14.0.0_coordinatoronly 1 0
18_regress_check-multi-1-create-citus 1 0
17_regress_check-enterprise-isolation 1 0
17_regress_check-enterprise-isolation-logicalrep-1 1 0
18_regress_check-enterprise-isolation-logicalrep-3_14.0-1_all 1 0
16_arbitrary_configs_5 1 0
17_arbitrary_configs_5 1 0
16_regress_check-multi-1 1 0
18_regress_check-multi-1_v14.0.0_all 1 0
18_regress_check-isolation_14.0-1_v14.0.0_coordinatoronly 1 0
18_regress_check-isolation_14.0-1_v14.0.0_workeronly 1 0
17_regress_check-isolation 1 0
16_regress_check-isolation 1 0
18_regress_check-multi-1_14.0-1_v14.0.0_workeronly 1 0
18_arbitrary_configs_4 1 0
17_arbitrary_configs_4 1 0
17_regress_check-multi 1 0
18_regress_check-multi_v14.0.0_all 1 0
16_arbitrary_configs_3 1 0
16_arbitrary_configs_2 1 0
18_regress_check-multi-1_14.0-1_v14.0.0_coordinatoronly 1 0
17_regress_check-vanilla 1 0
18_regress_check-enterprise-isolation-logicalrep-3_14.0-1_v14.0.0_workeronly 1 0
18_regress_check-enterprise-isolation-logicalrep-2_14.0-1_all 1 0
17_regress_check-split 1 0
16_regress_check-query-generator 1 0
16_regress_check-split 1 0
18_regress_check-split 1 0
18_regress_check-enterprise-isolation-logicalrep-2_14.0-1_v14.0.0_workeronly 1 0
16_regress_check-multi-mx 1 0
18_regress_check-multi-1_14.0-1_all 1 0
18_regress_check-multi-1 1 0
17_arbitrary_configs_0 1 0
18_regress_check-add-backup-node 1 0
17_regress_check-enterprise-isolation-logicalrep-3 1 0
18_regress_check-add-backup-node_14.0-1_v14.0.0_workeronly 1 0
18_arbitrary_configs_0 1 0
18_regress_check-operations 1 0
17_regress_check-operations 1 0
17_regress_check-multi-1 1 0
17_regress_check-tap 1 0
18_regress_check-multi-mx 1 0
16_regress_check-enterprise 1 0
18_regress_check-multi 1 0
18_regress_check-multi_14.0-1_all 1 0
18_regress_check-multi_14.0-1_v14.0.0_coordinatoronly 1 0
16_regress_check-multi 1 0
18_regress_check-split_14.0-1_v14.0.0_workeronly 1 0
18_regress_check-split_14.0-1_v14.0.0_coordinatoronly 1 0
16_regress_check-columnar 1 0
18_regress_check-enterprise-isolation_14.0-1_v14.0.0_coordinatoronly 1 0
18_regress_check-isolation_14.0-1_all 1 0
18_arbitrary_configs_3 1 0
18_arbitrary_configs_5 1 0
17_arbitrary_configs_2 1 0
18_arbitrary_configs_2 1 0
Additional details and impacted files
@@                Coverage Diff                @@
##           release-14.0    #8560       +/-   ##
=================================================
- Coverage         88.73%   63.24%   -25.49%     
=================================================
  Files               287      287               
  Lines             63238    63239        +1     
  Branches           7925     7923        -2     
=================================================
- Hits              56114    39997    -16117     
- Misses             4862    20212    +15350     
- Partials           2262     3030      +768     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codeforall codeforall changed the title Fix deadlock adding named constraint with long partition name (#7799)… Backport 8540: Fix deadlock adding named constraint with long partition name (#7799)… May 4, 2026
@ihalatci ihalatci added this to the 14.1 milestone May 5, 2026
@ihalatci ihalatci removed this from the 14.1 milestone May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadlock when specifying constraint name for a parent table with a partition with a long name

2 participants