Skip to content

feat: add support for index storage parameters (reloptions)#478

Open
ayusssmaan wants to merge 4 commits into
pgplex:mainfrom
ayusssmaan:feat/index-reloptions-storage-parameters
Open

feat: add support for index storage parameters (reloptions)#478
ayusssmaan wants to merge 4 commits into
pgplex:mainfrom
ayusssmaan:feat/index-reloptions-storage-parameters

Conversation

@ayusssmaan

Copy link
Copy Markdown
Contributor

pgschema was silently ignoring storage parameters (WITH (...) clauses) on
indexes. This caused indexes created with options like fillfactor=90 or
deduplicate_items=off to appear as a diff on every run — pgschema would
repeatedly re-create them because the emitted CREATE INDEX DDL omitted the
WITH clause, so the live index never matched the model.

What changed

  • ir/queries/queries.sql.go: query pg_class.reloptions for each index
  • ir/ir.go: add StorageParameters []string field to IndexDef
  • ir/inspector.go: populate StorageParameters from query results
  • internal/diff/table.go: emit WITH (...) in CREATE INDEX DDL when
    storage parameters are present, preserving Postgres-returned order

Test

New fixture testdata/diff/create_index/add_index_with_reloptions/ covers:

  • Single storage parameter: WITH (fillfactor=90)
  • Multiple storage parameters: WITH (fillfactor=100, deduplicate_items=true)
  • Combined with a partial index WHERE clause

All pre-existing tests continue to pass.

Add support for index WITH (...) storage parameters such as
fillfactor, deduplicate_items, gin_pending_list_limit, fastupdate.

- ir.go: add StorageParameters []string field to Index struct
- queries.sql.go: fetch pg_class.reloptions via COALESCE in index_base CTE
- inspector.go: map reloptions array to StorageParameters on Index
- table.go: order-insensitive StorageParameters comparison in indexesStructurallyEqual
- index.go: emit WITH (...) clause in generateIndexSQLWithName after NULLS NOT DISTINCT and before WHERE
@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds support for index storage parameters in schema inspection and diff output. The main changes are:

  • Adds StorageParameters to index IR.
  • Reads pg_class.reloptions for inspected indexes.
  • Compares index storage parameters during structural diffing.
  • Emits WITH (...) in generated CREATE INDEX SQL.
  • Adds fixtures for indexes with reloptions.

Confidence Score: 3/5

This should be fixed before merging.

  • The normal diff generator includes storage parameters.
  • The online plan path can still create indexes without the requested options.
  • The generated query file does not match the checked-in sqlc source query.

internal/plan/rewrite.go and ir/queries/queries.sql need follow-up.

Important Files Changed

Filename Overview
internal/diff/index.go Adds WITH (...) emission to the canonical diff-layer index generator.
internal/plan/rewrite.go The separate online index SQL generator still omits the new storage parameters.
ir/queries/queries.sql.go Generated inspection code includes reloptions, but its source query is not in sync.

Reviews (1): Last reviewed commit: "test: add fixture for index reloptions s..." | Re-trigger Greptile

Comment thread ir/queries/queries.sql.go
- ir/queries/queries.sql: add COALESCE(i.reloptions, '{}') AS reloptions to
  GetIndexesForSchema CTE and SELECT so the sqlc source matches the generated
  queries.sql.go (fixes generated-code drift flagged by Greptile)
- internal/plan/rewrite.go: emit WITH (...) for storage parameters in the
  online plan path's generateIndexSQL so CONCURRENTLY-built indexes also
  include reloptions (fixes gap flagged by Greptile)
Generate expected output files for the add_index_with_reloptions fixture so
TestPlanAndApply passes in CI.
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.

1 participant