schemachanger: allow dropping column referenced in partial index predicate#169753
Draft
rafiss wants to merge 1 commit intocockroachdb:masterfrom
Draft
schemachanger: allow dropping column referenced in partial index predicate#169753rafiss wants to merge 1 commit intocockroachdb:masterfrom
rafiss wants to merge 1 commit intocockroachdb:masterfrom
Conversation
…icate The declarative schema changer previously rejected ALTER TABLE ... DROP COLUMN if the column was referenced in a partial index predicate, with a hint to drop the index first. The restriction was added in cockroachdb#97372 as a temporary safeguard for cockroachdb#96924, where the optimizer could need to read a column being dropped to evaluate the predicate when both the column and its dependent partial index were transitioning simultaneously. The dep rule "secondary index partial no longer public before referenced column" (added later) sequences the partial index into DELETE_ONLY before the column reaches WRITE_ONLY. In DELETE_ONLY the index issues blind DELs and does not need to evaluate its predicate, so the original hazard no longer applies for the declarative path. This commit lifts the restriction in the declarative DROP COLUMN path only. The legacy schema changer keeps the restriction (it lacks the dep-rule machinery), and partial unique-without-index predicates remain blocked in both schema changers — those will be addressed separately. ALTER PRIMARY KEY and ALTER COLUMN TYPE also keep the restriction, because their column-drop traversal can encounter element types that the existing walker does not yet handle. The restriction toggle on walkColumnDependencies changes from a bool to a small predicateRefPolicy enum (allow all / disallow UWI only / disallow all) so each caller can pick the policy that matches its actual constraints. The DML-injection test case "drop column with partial index" was re-enabled (previously skipped under cockroachdb#97813). Resolves: cockroachdb#97813 Epic: none Release note (sql change): ALTER TABLE ... DROP COLUMN no longer rejects columns referenced in a partial index predicate. The dependent partial index is dropped automatically as part of the same statement. The previous behavior — requiring the user to drop the index first — is still in effect when the legacy schema changer is in use, and when the column is referenced in a partial UNIQUE WITHOUT INDEX predicate. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
b672c00 to
a8d2f07
Compare
Contributor
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The declarative schema changer previously rejected ALTER TABLE ... DROP COLUMN if the column was referenced in a partial index predicate, with a hint to drop the index first. The restriction was added in #97372 as a temporary safeguard for #96924, where the optimizer could need to read a column being dropped to evaluate the predicate when both the column and its dependent partial index were transitioning simultaneously.
The dep rule "secondary index partial no longer public before referenced column" (added later) sequences the partial index into DELETE_ONLY before the column reaches WRITE_ONLY. In DELETE_ONLY the index issues blind DELs and does not need to evaluate its predicate, so the original hazard no longer applies for the declarative path.
This commit lifts the restriction in the declarative DROP COLUMN path only. The legacy schema changer keeps the restriction (it lacks the dep-rule machinery), and partial unique-without-index predicates remain blocked in both schema changers — those will be addressed separately. ALTER PRIMARY KEY and ALTER COLUMN TYPE also keep the restriction, because their column-drop traversal can encounter element types that the existing walker does not yet handle.
The restriction toggle on walkColumnDependencies changes from a bool to a small predicateRefPolicy enum (allow all / disallow UWI only / disallow all) so each caller can pick the policy that matches its actual constraints.
The DML-injection test case "drop column with partial index" was re-enabled (previously skipped under #97813).
Resolves: #97813
Epic: none
Release note (sql change): ALTER TABLE ... DROP COLUMN no longer rejects columns referenced in a partial index predicate. The dependent partial index is dropped automatically as part of the same statement. The previous behavior — requiring the user to drop the index first — is still in effect when the legacy schema changer is in use, and when the column is referenced in a partial UNIQUE WITHOUT INDEX predicate.