Skip to content

Fix deadlock adding named constraint with long partition name (#7799)#8540

Open
codeforall wants to merge 1 commit intomainfrom
muusama/7799
Open

Fix deadlock adding named constraint with long partition name (#7799)#8540
codeforall wants to merge 1 commit intomainfrom
muusama/7799

Conversation

@codeforall
Copy link
Copy Markdown
Contributor

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 Apr 9, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.91%. Comparing base (4d6fb1d) to head (f7045ef).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8540   +/-   ##
=======================================
  Coverage   88.90%   88.91%           
=======================================
  Files         286      286           
  Lines       63227    63230    +3     
  Branches     7937     7939    +2     
=======================================
+ Hits        56214    56218    +4     
- Misses       4736     4738    +2     
+ Partials     2277     2274    -3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codeforall codeforall marked this pull request as ready for review April 9, 2026 09:09
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.
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.

1 participant