Summary
The jobs-list endpoint search (?endpoint=..., added in #35) matches with a
leading-wildcard ILIKE '%' || $n || '%'. A leading % cannot use a B-tree
index, so this is a sequential scan of the workspace's jobs table on every
filtered request. Combined filters beyond status (which has
idx_jobs_status) also have no supporting index.
This is fine at current data volumes and was intentionally deferred from the
pagination/filter hardening PR — filing it so the perf work isn't lost.
Where
crates/common/src/db/jobs.rs — build_list_query, the endpoint ILIKE ...
condition.
- Per-workspace schema template:
migrations/workspace_v1.sql.
Proposed fix
Add a trigram GIN index so leading-wildcard ILIKE can be index-assisted:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX IF NOT EXISTS idx_{p}jobs_endpoint_trgm
ON {p}jobs USING gin (endpoint gin_trgm_ops);
Considerations:
- Requires the
pg_trgm extension to be available/enabled in each tenant
schema's database; add to the workspace provisioning template.
- Measure first — for small per-workspace tables the planner may still prefer a
seq scan, and the index has write-amplification cost.
Acceptance
Follow-up to #35.
Summary
The jobs-list endpoint search (
?endpoint=..., added in #35) matches with aleading-wildcard
ILIKE '%' || $n || '%'. A leading%cannot use a B-treeindex, so this is a sequential scan of the workspace's
jobstable on everyfiltered request. Combined filters beyond
status(which hasidx_jobs_status) also have no supporting index.This is fine at current data volumes and was intentionally deferred from the
pagination/filter hardening PR — filing it so the perf work isn't lost.
Where
crates/common/src/db/jobs.rs—build_list_query, theendpoint ILIKE ...condition.
migrations/workspace_v1.sql.Proposed fix
Add a trigram GIN index so leading-wildcard
ILIKEcan be index-assisted:Considerations:
pg_trgmextension to be available/enabled in each tenantschema's database; add to the workspace provisioning template.
seq scan, and the index has write-amplification cost.
Acceptance
pg_trgm+ GIN index toworkspace_v1.sqland verifyEXPLAINshows it used for a representativeILIKE '%x%'query.Follow-up to #35.