perf(db): cf_items.subject_uri に GIN 索引を追加#9
Merged
Conversation
分野の逆引き(この分野を設定している項目)で使う 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
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.
概要
分野(CFSubject)の逆引き機能「この分野を設定している項目」の土台として、
cf_items.subject_uriに GIN 索引(jsonb_path_ops) を追加します。JSONB 包含クエリ
subject_uri @> '[{"identifier": "<subject-id>"}]'を索引で高速化し、大規模フレームワークでも seq scan を避けます(jsonb_path_opsは@>専用で小さく速い)。変更
d1a2b3c4e5f6(down_revisionc704faa62b4f)—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_indexesでUSING gin (subject_uri jsonb_path_ops))。逆引き機能本体(repository / router / template)は後続 PR。索引のみ先行マージします。
🤖 Generated with Claude Code