max / makenotwork
| 1 | -- Drop idx_posts_not_removed (migration 024). It has no reader left. |
| 2 | -- |
| 3 | -- Supersedes the note in 034, which kept it pending production index stats. |
| 4 | -- Decision made without them: the code is unambiguous enough that the stats |
| 5 | -- would only confirm it. |
| 6 | -- |
| 7 | -- 034 moved every read that filters live posts onto `p.is_active`, served by |
| 8 | -- idx_posts_active with the same (thread_id, created_at) shape. After that |
| 9 | -- sweep, nothing left in the tree can use a `WHERE removed_at IS NULL` partial |
| 10 | -- index on posts: |
| 11 | -- |
| 12 | -- * No query filters `removed_at IS NULL` at all any more. The only remaining |
| 13 | -- query-side reads of the column are `removed_at IS NOT NULL` (is_post_removed, |
| 14 | -- the deleted-threads OP check), which a `WHERE removed_at IS NULL` partial |
| 15 | -- index cannot serve by construction. |
| 16 | -- * The write guards (auto_hide_if_threshold_met, mod_remove_post_cascade, |
| 17 | -- restore_post_cascade) are all `WHERE id = $1 AND removed_at IS NULL`. |
| 18 | -- Equality on the primary key is far more selective than a partial index |
| 19 | -- covering nearly every row, so those are posts_pkey lookups. |
| 20 | -- * The post_count trigger (029, hardened in 031) is row-level, acting on |
| 21 | -- NEW/OLD, and scans nothing. The `removed_at IS NULL` in 031 is its one-shot |
| 22 | -- backfill, already run. |
| 23 | -- * The images table has its own `removed_at`; this index is on posts and was |
| 24 | -- never involved there. |
| 25 | -- |
| 26 | -- So it is pure write amplification: maintained on every post insert and on |
| 27 | -- every removal or restore, read by nothing. Dropping it is a straight win on |
| 28 | -- write cost and disk. |
| 29 | -- |
| 30 | -- IF EXISTS mirrors 024's IF NOT EXISTS, so a partial re-run cannot hard-fail. |
| 31 | |
| 32 | IF EXISTS idx_posts_not_removed; |
| 33 |