Skip to content

release-26.1: scbuild: fix CREATE INDEX on PARTITION ALL BY tables with explicit PK columns#164754

Merged
rafiss merged 1 commit intocockroachdb:release-26.1from
rafiss:blathers/backport-release-26.1-161083
Mar 6, 2026
Merged

release-26.1: scbuild: fix CREATE INDEX on PARTITION ALL BY tables with explicit PK columns#164754
rafiss merged 1 commit intocockroachdb:release-26.1from
rafiss:blathers/backport-release-26.1-161083

Conversation

@rafiss
Copy link
Copy Markdown
Collaborator

@rafiss rafiss commented Mar 3, 2026

Backport 1/1 commits from #161083 on behalf of @rafiss.


Previously, when creating an index on a table with PARTITION ALL BY, the declarative schema changer's maybeAddPartitionDescriptorForIndex looked for columns marked as Implicit on the source index to determine partition columns. This failed when partition columns were explicitly part of the primary key, since those columns aren't marked as implicit. This caused CREATE INDEX to fail during PostCommitNonRevertiblePhase with "table has PARTITION ALL BY defined, but index does not have matching PARTITION BY".

To address this, the code now uses NumColumns from the source index's IndexPartitioning element to get the first N key columns regardless of whether they're marked implicit. The partitioning descriptor is cloned from the source index and NumImplicitColumns is updated after column prepending to reflect the actual number of implicitly added columns.

Epic: None
resolves https://github.com/cockroachlabs/support/issues/3521

Release note (bug fix): Fixed a bug where CREATE INDEX on a table with PARTITION ALL BY would fail if the partition columns were explicitly included in the primary key definition.


Release justification: bug fix

… columns

Previously, when creating an index on a table with PARTITION ALL BY,
the declarative schema changer's `maybeAddPartitionDescriptorForIndex`
looked for columns marked as `Implicit` on the source index to determine
partition columns. This failed when partition columns were explicitly
part of the primary key, since those columns aren't marked as implicit.
This caused CREATE INDEX to fail during PostCommitNonRevertiblePhase with
"table has PARTITION ALL BY defined, but index does not have matching
PARTITION BY".

To address this, the code now uses `NumColumns` from the source index's
`IndexPartitioning` element to get the first N key columns regardless of
whether they're marked implicit. The partitioning descriptor is cloned
from the source index and `NumImplicitColumns` is updated after column
prepending to reflect the actual number of implicitly added columns.

This also includes a minor fix to show the column name for stored
columns in the crdb_internal.index_columns table, which we use for
testing this change.

Release note (bug fix): Fixed a bug where CREATE INDEX on a table with
PARTITION ALL BY would fail if the partition columns were explicitly
included in the primary key definition.
@rafiss rafiss requested a review from a team as a code owner March 3, 2026 19:10
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Mar 3, 2026
@blathers-crl blathers-crl bot requested review from shghasemi and spilchen March 3, 2026 19:10
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 3, 2026

Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@blathers-crl blathers-crl bot added backport Label PR's that are backports to older release branches T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Mar 3, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@spilchen spilchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rafiss rafiss merged commit 28cfa1a into cockroachdb:release-26.1 Mar 6, 2026
30 of 31 checks passed
@rafiss rafiss deleted the blathers/backport-release-26.1-161083 branch March 9, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) target-release-26.1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants