SchemaIntegrityVerifier reports false drift on partial + functional indexes (indpred unread, ParseIndexExpressions mis-parses)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 72/100
調査の方向性
Start in PostgresSchemaInspector, reading the index read-back query and ParseIndexExpressions, then follow how IndexDefinition is checked by SchemaIntegrityVerifier.SameSql. Reproduce the schema with the partial functional index and verify that the inspector round-trips its filter and expressions without reporting drift.
索引モデルが issue の本文から書いたものです。
説明
Summary
A unique index that is both functional and partial always reports drift in the post-apply SchemaIntegrityVerifier, even immediately after migrate creates it. Two independent bugs in Nimblesite.DataProvider.Migration.Postgres.PostgresSchemaInspector cause this.
Reproduced with DataProviderMigrate 0.9.12-beta against postgres:16.
Repro schema.yaml index
- name: uq_invitations_pending_email
expressions:
- tenant_id
- lower(email)
isUnique: true
filter: "accepted_at IS NULL AND revoked_at IS NULL"
Observed
migrate creates the index, then the integrity check fails:
public.invitations: index uq_invitations_pending_email expressions drifted
public.invitations: index uq_invitations_pending_email filter drifted
Postgres stores the index as:
CREATE UNIQUE INDEX uq_invitations_pending_email ON public.invitations
USING btree (tenant_id, lower(email))
WHERE ((accepted_at IS NULL) AND (revoked_at IS NULL))
Bug 1 — Filter is never read back
PostgresSchemaInspector builds IndexDefinition from the read-back query but never reads pg_index.indpred (pg_get_expr(indpred, indrelid)), so actual.Filter is always null. SchemaIntegrityVerifier.SameSql(null, "accepted_at IS NULL AND revoked_at IS NULL") is therefore always false → "filter drifted" for ANY partial index.
Bug 2 — ParseIndexExpressions mis-parses functional / partial indexes
ParseIndexExpressions(indexDef) locates the column list with indexDef.LastIndexOf('(') and LastIndexOf(')'). For ... (tenant_id, lower(email)) WHERE (...) the last (/) belong to the WHERE clause (or to lower(), so the substring extracted is not the index column list. Result: parsed Expressions are garbage → "expressions drifted". This also misfires on a functional index with no WHERE ((tenant_id, lower(email)) → parses email only).
Suggested fix
- Read
pg_get_expr(i.indpred, i.indrelid, true)and populateIndexDefinition.Filter; normalize parenthesisation inSameSql(Postgres re-parenthesises predicates). - Replace the
LastIndexOfbracket scan with a depth-aware scan anchored onUSING <method> (… matching)so the WHERE clause and nested function parens are not mistaken for the column-list bounds.
Impact / workaround
NAP's [INVITE-EMAIL] wanted a partial+functional unique index ((tenant_id, lower(email)) WHERE accepted_at IS NULL AND revoked_at IS NULL). Because the verifier fails it, NAP currently enforces the invariant in the application layer instead and omits the DB index. We'd like to restore the DB constraint once the verifier round-trips filtered/expression indexes.
- 主要言語
- C#
- スター
- 68
- フォーク
- 4
- 平均マージ
- 50分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Nimblesite/DataProvider のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
Nimblesite/DataProvider#137 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Nimblesite/DataProvider#72 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Nimblesite/DataProvider#121 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
Nimblesite/DataProvider#108 ·
メンテナーはふだん 1 日以内に返信
-
A check constraint the schema cannot name can never be retired, and keeps enforcing the old ruleオープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
Nimblesite/DataProvider#107 ·
メンテナーはふだん 1 日以内に返信
Nimblesite/DataProvider の issue をすべて見る
似ている issue
-
kronos:develop:queued priority:P0
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
nopSolutions/nopCommerce#8512 ·
メンテナーはふだん 4 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#2061 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信