| 1 | -- What one claim costs: make explain Q=claim |
| 2 | explain (analyze, costs off, timing off) |
| 3 | select id |
| 4 | from jobs |
| 5 | where status = 'waiting' and run_at <= now() |
| 6 | order by run_at, id |
| 7 | limit 1 |
| 8 | for update skip locked; |
| 9 | |
| 10 | -- The same claim without today's index. The index is dropped inside a transaction |
| 11 | -- that is rolled back, so it never really goes away. The table is locked meanwhile. |
| 12 | begin; |
| 13 | drop index jobs_run_at_id_idx; |
| 14 | explain (analyze, costs off, timing off) |
| 15 | select id |
| 16 | from jobs |
| 17 | where status = 'waiting' and run_at <= now() |
| 18 | order by run_at, id |
| 19 | limit 1 |
| 20 | for update skip locked; |
| 21 | rollback; |