From 94dbe4b2284c095b16fe53292888b4f182dc3eff Mon Sep 17 00:00:00 2001 From: npeter83 Date: Tue, 18 Aug 2026 18:31:38 +0200 Subject: [PATCH] fix(jobs): match the boolean partial predicates to the IS TRUE/IS FALSE queries (E2 S6 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The via_search / shorts_probed partials used `WHERE via_search` / `WHERE NOT shorts_probed`, but the queries filter with `.is_(True)`/`.is_(False)` (SQL `IS TRUE`/`IS FALSE`), which Postgres's partial-index prover does NOT match to a bare-boolean predicate — so both fell back to a full seq scan (the shorts-probe job kept full-scanning for its work queue, the exact thing PERF-3 meant to fix). Align the predicates to the query form: `WHERE via_search IS TRUE` and `WHERE shorts_probed IS FALSE`. Verified on the prod-sized localdev: both now Index Only Scan (via_search 44,683 -> 3 buffers; shorts_probed 44,683 -> 1). Gate green (346 pytest). --- backend/alembic/versions/0069_job_index_hygiene.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/alembic/versions/0069_job_index_hygiene.py b/backend/alembic/versions/0069_job_index_hygiene.py index fbc7d878..59370115 100644 --- a/backend/alembic/versions/0069_job_index_hygiene.py +++ b/backend/alembic/versions/0069_job_index_hygiene.py @@ -45,14 +45,17 @@ def upgrade() -> None: op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_videos_is_short") op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_videos_via_explore") op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_videos_via_search") + # Predicate MUST match the query's `.is_(True)`/`.is_(False)` form (SQL `IS TRUE`/`IS FALSE`): + # Postgres's partial-index prover does NOT match a `col IS TRUE` clause to a bare `col` predicate, + # so `WHERE via_search` / `WHERE NOT shorts_probed` would leave the queries seq-scanning. op.execute( "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_videos_via_search " - "ON videos (id) WHERE via_search" + "ON videos (id) WHERE via_search IS TRUE" ) op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_videos_shorts_probed") op.execute( "CREATE INDEX CONCURRENTLY IF NOT EXISTS ix_videos_shorts_probed " - "ON videos (id) WHERE NOT shorts_probed" + "ON videos (id) WHERE shorts_probed IS FALSE" ) op.execute("DROP INDEX CONCURRENTLY IF EXISTS ix_videos_unavailable_since") op.execute(