-- +goose Up -- The operator's two surfaces for stalled work — `tmplatformctl runs --stalled` and the -- `tm_platform_runs_stalled` gauge — cover TWO populations since PD-385: a run the reconciler cannot -- finish, and a run that ENDED whose money never closed. The first has had an index since 00009 -- (`run_attempts_live_idx`, partial on `ended_at is null`). The second had none — and WITHOUT this -- index the widened query is a sequential scan of every attempt ever, whatever shape it is written -- in: measured on 200 000 attempts, 3647 buffers as one WHERE with an OR and 3653 as a UNION of two -- arms, against 2 for the narrow query it replaced. Its twin runs on the daemon's fifteen-second -- ticker forever. With this index both shapes come back to ten-odd buffers. That is register row -- PD-364's class exactly — an index that cannot serve the query it was meant for — arriving from the -- other side: here the query outgrew the indexes rather than the index missing the query. -- -- PARTIAL, on the failures and not on the whole table: an attempt that ended and never failed to -- settle is the ordinary case and is most of this table, while an attempt that ended and DID fail is -- the population an operator is looking for — a handful on a healthy deployment, and empty on a -- perfect one. `>= 1` and not `>= 5` because `runs` without `--stalled` shows the settling half from -- one failure, and an index that stopped at the threshold could not serve the plain form. create index run_attempts_settling_idx on run_attempts (run_id) where ended_at is not null and reconcile_failures >= 1; -- +goose Down drop index run_attempts_settling_idx;