discardKeys updated with `release_key = ANY(subquery)`, which locks rows in the plan's scan order, and deadlocked against a batch upsert that takes its rows by key (LOG.md (137)). It now updates from a subquery that selects the rows ORDER BY release_key FOR UPDATE, so the locks are taken sorted (the plan: LockRows above Sort). record() runs the same SELECT ... FOR UPDATE over its taken rows before its UPDATE ... FROM jsonb_to_recordset, whose join order the planner chooses. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>