Skip to main content

max / makenotwork

multithreaded: drop idx_posts_not_removed, it has no reader left Supersedes 034's note, which kept it pending production index stats. 034 moved every live-post read onto p.is_active, served by idx_posts_active with the same (thread_id, created_at) shape. After that sweep nothing in the tree can use a WHERE removed_at IS NULL partial index on posts: no query filters removed_at IS NULL any more, the only query-side reads of the column are IS NOT NULL (which such an index cannot serve by construction), the write guards are all WHERE id = $1 AND removed_at IS NULL and belong to posts_pkey, and the post_count trigger is row-level and scans nothing. So it was maintained on every insert, removal and restore, and read by nothing. Dropping it is a straight win on write cost and disk.
Co-Authored-By
Claude Opus 5 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-27 15:02 UTC
Signed with PGP, not checked
Commit: 6c8a6b40f0ce6094c7692c4ef247a53d624c5669
Parent: 5ecfc4a
1 file changed, +32 insertions, -0 deletions
@@ -1,0 +1,32 @@
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 + DROP INDEX IF EXISTS idx_posts_not_removed;