Skip to content

perf(db): cf_items.subject_uri に GIN 索引を追加#9

Merged
kentalow merged 1 commit into
mainfrom
feat/subject-uri-gin-index
Jun 20, 2026
Merged

perf(db): cf_items.subject_uri に GIN 索引を追加#9
kentalow merged 1 commit into
mainfrom
feat/subject-uri-gin-index

Conversation

@kentalow

Copy link
Copy Markdown
Member

概要

分野(CFSubject)の逆引き機能「この分野を設定している項目」の土台として、cf_items.subject_uriGIN 索引(jsonb_path_ops) を追加します。

JSONB 包含クエリ subject_uri @> '[{"identifier": "<subject-id>"}]' を索引で高速化し、大規模フレームワークでも seq scan を避けます(jsonb_path_ops@> 専用で小さく速い)。

変更

  • migration d1a2b3c4e5f6(down_revision c704faa62b4f)— CREATE INDEX ... USING gin (subject_uri jsonb_path_ops)。upgrade/downgrade 往復確認済み。
  • src/models/cf_item.py__table_args__ に同索引をミラー(autogenerate 整合)。
  • docs/spec/db-schema.md(英/日)の cf_item 索引一覧に追記。

検証

  • alembic upgrade head で索引作成を確認(pg_indexesUSING gin (subject_uri jsonb_path_ops))。
  • downgrade → upgrade 往復OK。
  • 全 677 テスト pass / ruff clean。

逆引き機能本体(repository / router / template)は後続 PR。索引のみ先行マージします。

🤖 Generated with Claude Code

分野の逆引き(この分野を設定している項目)で使う JSONB 包含クエリ
subject_uri @> '[{"identifier": ...}]' を高速化する GIN(jsonb_path_ops)
索引を追加。大規模フレームワークでも seq scan を避ける。

- migration d1a2b3c4e5f6(down_revision c704faa62b4f)
- cf_item.py の __table_args__ に同索引をミラー(autogenerate 整合)
- db-schema.md(英/日)の cf_item 索引一覧に追記

逆引き機能(router/template)は後続 PR。索引のみ先行。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXFogp18twGiPFBAZcqJw2
@kentalow kentalow merged commit 4f2fe16 into main Jun 20, 2026
2 checks passed
@kentalow kentalow deleted the feat/subject-uri-gin-index branch June 20, 2026 08:55
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