Files
insights/rust/cyclotron-node-migrations/20260622000001_add_email_fair_dequeue_composite_index.sql
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

23 lines
1.2 KiB
SQL

-- no-transaction
--
-- Replaces the email fair-dequeue index with a composite-key variant that
-- adds `scheduled` as a secondary key column. This lets the planner apply
-- `scheduled <= NOW()` as an `Index Cond` evaluated during the index walk,
-- instead of a heap-level `Filter:` that fetches every walked-past row.
--
-- Why not `INCLUDE (scheduled)`? Empirically (EXPLAIN ANALYZE BUFFERS at
-- 1M future-scheduled rows + 100K dequeueable), `INCLUDE` does NOT cause
-- Postgres to skip heap fetches for filtered rows under this query shape.
-- The filter is still evaluated after the heap visit, so the buffer count
-- and execution time match the un-INCLUDE'd index. A composite key with
-- `scheduled` as a non-leading key column flips the planner to `Index Cond`
-- — walked-past rows are eliminated in-index, dropping buffer reads ~4x
-- and execution time ~10x at the same scale.
--
-- The leading key is still `dequeue_seq NULLS FIRST`, so the worker's
-- `ORDER BY dequeue_seq ASC NULLS FIRST` is satisfied by the index sort
-- order without a separate Sort node.
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_cyclotron_jobs_email_fair_dequeue_v2
ON cyclotron_jobs (dequeue_seq NULLS FIRST, scheduled)
WHERE status = 'available' AND queue_name = 'email';