fix(query): built-in index dispatch fallback — no more idx->> seq-scans (#154)#155
Merged
Merged
Conversation
…ns (#154) _process_index fell through to _handle_field on registry miss, emitting idx->>'name' for path/effectiveRange/SearchableText/allowedRolesAndUsers. The generic field SQL bypasses the dedicated typed columns (path, allowed_roles, object_provides, searchable_text) and their indexes — 4-9 second seq-scans on 450k-row object_state on aaf-6 prod. New _builtin_index_type() helper: (1) hardcoded Plone-native specials (path, effectiveRange, SearchableText), (2) TEXT[]-typed ExtraIdxColumn entries (allowedRolesAndUsers, object_provides) derived at dispatch time. Explicit registry entries still win. Closes #154. Co-Authored-By: Claude Opus 4.7 (1M context) <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
Closes #154. On aaf-6 prod a folder-listing query produced 4-9 second seq-scans because `_process_index` fell through to `_handle_field` when the `IndexRegistry` didn't carry the queried index name. For Plone-built-in names (`path`, `allowedRolesAndUsers`, `effectiveRange`, `SearchableText`, …) the generic `idx->>'name'` SQL bypasses the dedicated typed columns — `path` column, `allowed_roles` GIN array, `object_provides` GIN array, `searchable_text` tsvector, and the `effective`/`expires` composite clause — and their indexes.
Observed SQL (slow, 9 seconds, seq-scan):
```sql
WHERE idx IS NOT NULL
AND idx->>'portal_type' = ANY(...)
AND idx->>'path' = ANY(...) -- should use path column
AND idx->>'allowedRolesAndUsers' = ANY(...) -- should use allowed_roles && ...
AND idx->>'effectiveRange' = -- nonsense scalar equality
```
Fix
`_process_index` now calls `_builtin_index_type(name)` on registry miss:
Explicit registry entries still win so addons can override handler behavior.
Test plan
🤖 Generated with Claude Code