Skip to content

fix(query): built-in index dispatch fallback — no more idx->> seq-scans (#154)#155

Merged
jensens merged 1 commit into
mainfrom
fix/builtin-index-fallback-dispatch
Apr 20, 2026
Merged

fix(query): built-in index dispatch fallback — no more idx->> seq-scans (#154)#155
jensens merged 1 commit into
mainfrom
fix/builtin-index-fallback-dispatch

Conversation

@jensens
Copy link
Copy Markdown
Member

@jensens jensens commented Apr 20, 2026

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:

  • Hardcoded Plone-native specials: `path` → PATH, `effectiveRange` → DATE_RANGE, `SearchableText` → TEXT. Their SQL lives inside the handlers (composite clauses, tsquery matching) so they can't be expressed via `ExtraIdxColumn`.
  • Derived from `ExtraIdxColumn`: every `TEXT[]`-typed column entry gets auto-registered as a KEYWORD keyword-like index. Currently `allowedRolesAndUsers` → `allowed_roles`, `object_provides` → `object_provides`. Addons that call `register_extra_idx_column(col)` with `column_type="TEXT[]"` get the fallback treatment for free.

Explicit registry entries still win so addons can override handler behavior.

Test plan

  • 7 new tests in `TestBuiltinIndexFallbackDispatch`:
    • `path` unregistered → uses `path` column, not `idx->>'path'`
    • `allowedRolesAndUsers` unregistered → uses `allowed_roles && %s::text[]`
    • `effectiveRange` unregistered → composite `effective/expires` clause
    • `SearchableText` unregistered → `searchable_text @@ tsquery`
    • `object_provides` unregistered → TEXT[] `&&` (proves the ExtraIdxColumn derivation works)
    • Explicit registry entry still wins (regression guard)
    • Truly custom/unknown index still falls through to `_handle_field` (addon-defined)
  • Full suite: 1450 passed / 23 skipped / 0 failed.
  • After deploy on aaf-prod: EXPLAIN on a folder-view query uses `Index Scan` on `idx_os_cat_path` and `idx_os_allowed_roles`, not `Seq Scan`. Magazin-view latency drops from 4-9 s to sub-100 ms.

🤖 Generated with Claude Code

…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>
@jensens jensens merged commit 3f9a918 into main Apr 20, 2026
5 checks passed
@jensens jensens deleted the fix/builtin-index-fallback-dispatch branch April 20, 2026 19:01
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.

'path' query falls through to idx->>'path' FieldIndex fallback — seq-scan of object_state

1 participant