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(