Skip to content

schemachanger: allow dropping column referenced in partial index predicate#169753

Draft
rafiss wants to merge 1 commit intocockroachdb:masterfrom
rafiss:lift-partial-idx-drop
Draft

schemachanger: allow dropping column referenced in partial index predicate#169753
rafiss wants to merge 1 commit intocockroachdb:masterfrom
rafiss:lift-partial-idx-drop

Conversation

@rafiss
Copy link
Copy Markdown
Collaborator

@rafiss rafiss commented May 5, 2026

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.

…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>
@rafiss rafiss force-pushed the lift-partial-idx-drop branch from b672c00 to a8d2f07 Compare May 5, 2026 15:32
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 5, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

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.

sql: allow dropping columns referenced in partial index predicates

2 participants