Skip to content

sql: fix STORING clause position for hash sharded indexes in pg_indexes#161882

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:rafiss/fix-161516-storing-clause-order
Jan 27, 2026
Merged

sql: fix STORING clause position for hash sharded indexes in pg_indexes#161882
craig[bot] merged 1 commit intocockroachdb:masterfrom
rafiss:rafiss/fix-161516-storing-clause-order

Conversation

@rafiss
Copy link
Copy Markdown
Collaborator

@rafiss rafiss commented Jan 27, 2026

Previously, when displaying hash sharded indexes with STORING columns in pg_indexes, the STORING clause appeared after the WITH (bucket_count=...) clause. This produced invalid SQL that could not be re-executed:

CREATE INDEX idx ON tbl USING btree (c1, c2) USING HASH WITH (bucket_count=16) STORING (c3)

The SQL grammar requires STORING to come before storage parameters.

This commit fixes the output order so that STORING appears before WITH (bucket_count=...):

CREATE INDEX idx ON tbl USING btree (c1, c2) USING HASH STORING (c3) WITH (bucket_count=16)

This matches the grammar and allows the statement to be re-executed.

This bug was introduced in #76112.

Fixes #161516

Release note (bug fix): Fixed a bug where the index definition shown in pg_indexes for hash sharded indexes with STORING columns was not valid SQL. The STORING clause now appears in the correct position.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Previously, when displaying hash sharded indexes with STORING columns in
pg_indexes, the STORING clause appeared after the WITH (bucket_count=...)
clause. This produced invalid SQL that could not be re-executed:

  CREATE INDEX idx ON tbl USING btree (c1, c2) USING HASH WITH (bucket_count=16) STORING (c3)

The SQL grammar requires STORING to come before storage parameters.

This commit fixes the output order so that STORING appears before
WITH (bucket_count=...):

  CREATE INDEX idx ON tbl USING btree (c1, c2) USING HASH STORING (c3) WITH (bucket_count=16)

This matches the grammar and allows the statement to be re-executed.

This bug was introduced in cockroachdb#76112.

Fixes cockroachdb#161516

Release note (bug fix): Fixed a bug where the index definition shown in
pg_indexes for hash sharded indexes with STORING columns was not valid
SQL. The STORING clause now appears in the correct position.
@rafiss rafiss force-pushed the rafiss/fix-161516-storing-clause-order branch from 072168d to 2fa6991 Compare January 27, 2026 20:18
@rafiss rafiss marked this pull request as ready for review January 27, 2026 20:18
@rafiss rafiss requested review from a team as code owners January 27, 2026 20:18
@rafiss rafiss requested review from DrewKimball, eric-alton and fqazi and removed request for a team January 27, 2026 20:18
Copy link
Copy Markdown
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

@fqazi reviewed 4 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball and @eric-alton).

Copy link
Copy Markdown
Collaborator Author

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

tftr!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 27, 2026

@craig craig bot merged commit 3b78252 into cockroachdb:master Jan 27, 2026
31 checks passed
@rafiss rafiss deleted the rafiss/fix-161516-storing-clause-order branch January 27, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql,parser: STORING clause for hash sharded indexes appears in the wrong place in pg_indexes

3 participants