fix: preserve INCLUDE columns in CREATE INDEX CONCURRENTLY (#508)#512
Merged
Conversation
The duplicate generateIndexSQL in rewrite.go (used for concurrent index creation) was missing the INCLUDE clause entirely, causing covering indexes to lose their non-key columns. Also fix operator class vs direction ordering to match the canonical version in index.go. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes concurrent covering-index generation. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix: preserve INCLUDE columns in CREATE ..." | Re-trigger Greptile |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a drift bug in the online-plan rewrite path for CREATE INDEX CONCURRENTLY, ensuring covering indexes keep their INCLUDE columns (preventing repeated “rebuild index” loops in subsequent plans).
Changes:
- Emit
INCLUDE (...)columns in theinternal/plan/rewrite.goconcurrent index SQL generator. - Align index column syntax ordering with PostgreSQL grammar (operator class before sort direction).
- Add a new online diff fixture (
issue_508_include_columns_concurrent_index) validating concurrent index creation preservesINCLUDE.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/diff/online/issue_508_include_columns_concurrent_index/plan.txt | New expected plan output showing CREATE INDEX CONCURRENTLY ... INCLUDE (...) plus wait step. |
| testdata/diff/online/issue_508_include_columns_concurrent_index/plan.sql | New SQL fixture asserting concurrent index creation includes INCLUDE. |
| testdata/diff/online/issue_508_include_columns_concurrent_index/plan.json | New JSON plan fixture verifying the emitted SQL includes INCLUDE. |
| testdata/diff/online/issue_508_include_columns_concurrent_index/old.sql | Fixture “before” state table definition (no index). |
| testdata/diff/online/issue_508_include_columns_concurrent_index/new.sql | Fixture “desired” state adding covering index with INCLUDE. |
| testdata/diff/online/issue_508_include_columns_concurrent_index/diff.sql | Fixture diff output for non-concurrent CREATE INDEX ... INCLUDE (...). |
| internal/plan/rewrite.go | Fix concurrent index SQL generation to preserve INCLUDE columns and correct column clause ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move the INCLUDE columns concurrent index test case from standalone issue_508_include_columns_concurrent_index fixture into the existing add_composite_index fixture. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #508.
The
generateIndexSQLinrewrite.go(used exclusively forCREATE INDEX CONCURRENTLYstatements) was a duplicate of the canonical version inindex.gobut missing the INCLUDE clause. This caused covering indexes to lose their non-key columns when added to existing tables, creating an infinite plan loop.generateIndexSQLimplementations drifted apartTest plan
online/issue_508_include_columns_concurrent_index— adds a covering index(a) INCLUDE (b)to an existing table🤖 Generated with Claude Code