Commit 4f1eeed
committed
fix(flowsheet): switch nextPlayOrder index to composite (show_id, play_order DESC) (#1133)
`flowsheet_play_order_idx` was introduced by 0073 as a single-column DESC index to back the then-global `SELECT max(play_order) FROM flowsheet`. #693 then scoped `nextPlayOrder()` to `WHERE show_id = ?`, leaving the index misaligned with the actual query shape: on the 2.6M-row flowsheet the planner has to either backward-scan the global DESC index and filter by show_id (slow for any non-current show), bitmap-scan `flowsheet_show_id_idx` + aggregate (multiple heap reads), or seq scan for small mis-estimated shows — none are the O(1) leaf lookup the original migration claimed.
This swaps in a composite `(show_id, play_order DESC)` that makes the per-show MAX a true O(1) leaf-page lookup, with each show's rows forming a contiguous run inside the index whose leading edge is the per-show max. The same shape also covers the legacy mirror's `WHERE show_id = ? ORDER BY play_order DESC LIMIT 1` announcement lookups and `getEntriesByShow`'s `WHERE show_id IN (...) ORDER BY play_order DESC` listing — both of which the misaligned single-column index never served well either.
The predecessor `flowsheet_play_order_idx` is dropped in the same migration. The only remaining global-MAX(play_order) caller is `jobs/flowsheet-etl/job.ts:resetSequences()`, a one-shot post-bulk-load sequence reset that runs occasionally and is not performance-sensitive.
Test pins the migration shape (DROP + CREATE composite), the schema declaration (column order + DESC), and the post-#693 query shape in `nextPlayOrder()` so future drift either way trips before reaching prod.
Closes #11331 parent c22a9f6 commit 4f1eeed
6 files changed
Lines changed: 4870 additions & 9 deletions
Lines changed: 78 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
0 commit comments