From 3301216aa8f510f72f5ade33916ebbf9ce3d2d3b Mon Sep 17 00:00:00 2001 From: Daan Meijer Date: Mon, 12 Oct 2026 10:33:27 +0200 Subject: [PATCH] Probe candidates: an index on (kind, id) of the waiting ones for the prober's claims A slice of a claim filtered ~700k rows by kind through the id index (0.37 s a slice, 20 slices and up to 5 tiers a claim, the lanes waiting meanwhile). Co-Authored-By: Claude Opus 5.5 --- ...70000002400_probe_candidates_kind_index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 database/migrations/1770000002400_probe_candidates_kind_index.ts diff --git a/database/migrations/1770000002400_probe_candidates_kind_index.ts b/database/migrations/1770000002400_probe_candidates_kind_index.ts new file mode 100644 index 0000000..0e4d63b --- /dev/null +++ b/database/migrations/1770000002400_probe_candidates_kind_index.ts @@ -0,0 +1,19 @@ +import { BaseSchema } from '@adonisjs/lucid/schema' + +/** + * The prober claims waiting candidates by kind from random points of the + * queue (Prober.claim): by the id index alone a slice filtered ~700k rows for + * the rarer kinds (0.37 s a slice, 20 slices and up to 5 tiers a claim, the + * lanes waiting meanwhile; LOG.md 2026-10-12 (17)). Built concurrently. + */ +export default class extends BaseSchema { + static disableTransactions = true + + async up() { + this.schema.raw(`CREATE INDEX CONCURRENTLY IF NOT EXISTS probe_candidates_kind_waiting_idx ON probe_candidates (kind, id) WHERE status = 'waiting'`) + } + + async down() { + this.schema.raw(`DROP INDEX CONCURRENTLY IF EXISTS probe_candidates_kind_waiting_idx`) + } +}