Skip to content

sql: foreign key should skip internal column in a hash-sharded pk#162608

Open
eric-alton wants to merge 1 commit intocockroachdb:masterfrom
eric-alton:161618_fk_on_hash_pk
Open

sql: foreign key should skip internal column in a hash-sharded pk#162608
eric-alton wants to merge 1 commit intocockroachdb:masterfrom
eric-alton:161618_fk_on_hash_pk

Conversation

@eric-alton
Copy link
Contributor

Previously, an error would occur when defining a foreign key which references a hash-sharded primary key without explicitly providing the primary key columns. The parser was incorrectly including the internal shard key column when identifying the columns to use from the primary index.

To address this, we now skip over the internal shard column when defining a foreign key.

Epic: CRDB-58150
Fixes: #161618

Release note (bug fix): Fixed a bug where an error would occur when defining a foreign key on a hash-sharded primary key without explicitly providing the primary key columns.

Previously, an error would occur when defining a foreign key which
references a hash-sharded primary key without explicitly providing the
primary key columns. The parser was incorrectly including the internal
shard key column when identifying the columns to use from the primary
index.

To address this, we now skip over the internal shard column when
defining a foreign key.

Epic: CRDB-58150
Fixes: cockroachdb#161618

Release note (bug fix): Fixed a bug where an error would occur when
defining a foreign key on a hash-sharded primary key without
explicitly providing the primary key columns.
@eric-alton eric-alton requested review from fqazi and shghasemi February 6, 2026 20:40
@eric-alton eric-alton requested a review from a team as a code owner February 6, 2026 20:40
@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 6, 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.

@cockroach-teamcity
Copy link
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, parser: foreign key referencing a hash index primary key fails when not explicitly providing columns

2 participants