-- PostgreSQL 16; run against the intended ARTEX database/schema. -- Standalone migration: autocommit ON. Do not wrap in BEGIN or use psql -1. -- Before and after execution, run inspect-planning-index.sql. -- Deliberately no IF NOT EXISTS: a matching name does not prove a valid, -- equivalent index. Investigate an existing or INVALID index before retrying. -- The predicate matches db/planner_focus.go: PlanningContinuations. CREATE INDEX CONCURRENTLY idx_expnodes_planning_continuations ON exploration_nodes (exploration_id, id DESC) WHERE kind = 'fact' AND state = 'confirmed' AND ( ( COALESCE(payload->>'outcome', '') NOT IN ('verified', 'negative') AND length(btrim(COALESCE(payload->>'checkpoint', ''))) > 0 ) OR ( payload->>'outcome' = 'blocked' AND length(btrim(COALESCE(payload->>'revisit_condition', ''))) > 0 ) );