Add indexes for re-executor, spot-check and challenge lookups
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 88/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- postgresql, typescript
- Área
- database, performance
Línea de trabajo
Empieza leyendo db/migrations/0002_indexes_and_fks.ts, en especial reexecutor_active_stake_idx, para copiar la forma sql de Kysely que usa un índice descendente. Crea db/migrations/0005_hot_indexes.ts con los tres índices con nombre y un down en orden inverso. Luego ejecuta pnpm db:migrate, pnpm --filter @verity/db migrate:down, pnpm db:migrate y pnpm typecheck, y revisa en pg_indexes las definiciones de los tres índices. Está terminado cuando up y down se vuelven a aplicar sin errores y ninguna migración anterior cambia.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Three frequently-run queries filter or sort on columns that no index leads with: re-executor lookups on replay and spot_check, and the challenge list ordered by opened_at. Add a migration that creates the missing indexes, with a working down.
Background
Postgres (managed with Kysely migrations in db/migrations/, see CONTRIBUTING.md, "Changing the database") is the backend's mirror of chain state (docs/ARCHITECTURE.md, "Database"). Re-executor workers poll GET /v1/reexecutors/:id/assignments every few seconds, and the dashboard's re-executor pages compute per-worker statistics, so these queries are on the hot path. Postgres does not create an index for a foreign key automatically.
Current behaviour
db/migrations/0002_indexes_and_fks.ts creates, among others, a unique index on replay (submission_id, reexecutor_id) and one on spot_check (submission_id, reexecutor_id). Both lead with submission_id, so they cannot serve a filter on reexecutor_id alone. Queries that do that:
backend/src/modules/reexecutors/routes.ts, the assignments poll:.where("replay.reexecutor_id", "=", params.id)with.where("replay.status", "=", "assigned")(around line 256), and.where("spot_check.reexecutor_id", "=", params.id)with.where("spot_check.result", "is", null)(around line 266).statsByReexecutor()in the same file:.groupBy("replay.reexecutor_id")and, for one worker,.where("replay.reexecutor_id", "=", reexecutorId).backend/src/modules/challenges/routes.ts, lines 39-40:.orderBy("challenge.opened_at", "desc").orderBy("challenge.id"). The only index onchallengethat could help is the partialchallenge_open_uqonsubmission_id, so the listing sorts the whole table.
Scenario: with many historical replay rows, every poll by every worker scans all of replay.
Expected behaviour
A new migration adds indexes so these lookups can use an index, and its down removes exactly what up created.
Proposed approach
- Create
db/migrations/0005_hot_indexes.ts(the existing migrations are0001to0004; if another migration has landed by the time you rebase, use the next free number, since Kysely runs files in name order and an applied migration must never be edited). - In
up, create:replay_reexecutor_status_idxonreplay (reexecutor_id, status).spot_check_reexecutor_idxonspot_check (reexecutor_id).challenge_opened_at_idxonchallenge (opened_at desc, id), matching the query's order direction exactly. A descending column needs the rawsqlform, as0002does forreexecutor_active_stake_idx.
- In
down, drop the three indexes in reverse order. - Do not use
CONCURRENTLY: Kysely runs each migration inside a transaction on Postgres, where it is not allowed. The tables are small enough that a plainCREATE INDEXis fine. db/src/types.tsdoes not change because no columns change.
Files
db/migrations/0005_hot_indexes.ts(new):upcreates the three indexes,downdrops them.
Acceptance criteria
-
pnpm db:migrateon a database already at0004applies the new migration without errors. - The three indexes exist in
pg_indexeswith the definitions above. -
pnpm --filter @verity/db migrate:downremoves exactly those three indexes, andpnpm db:migrateapplies them again. - No existing migration file is modified.
-
pnpm typecheckpasses.
How to verify
pnpm --filter @verity/db local-postgres # embedded Postgres on port 5433 (or use your own)
export DATABASE_URL=postgres://verity:[email protected]:5433/verity
pnpm db:migrate
pnpm --filter @verity/db migrate:down
pnpm db:migrate
pnpm typecheck
Then inspect with any Postgres client: select indexname, indexdef from pg_indexes where indexname in ('replay_reexecutor_status_idx','spot_check_reexecutor_idx','challenge_opened_at_idx');. Optionally run EXPLAIN on the assignments query against a table with a few thousand generated rows (do not commit the data). pnpm dev also runs migrations on start (scripts/dev.sh), so a clean pnpm dev start is a good final check.
Out of scope
- Rewriting any query, adding columns, or changing
db/src/types.ts. - Indexes for tables other than
replay,spot_checkandchallenge. - Changing or dropping any index created in earlier migrations.
Notes
Trivial, single new file. The only merge hotspot is the migration number: any other issue that adds a migration also wants the next number, so whichever lands second renumbers its file.
- Lenguaje dominante
- TypeScript
- Estrellas
- 0
- Forks
- 1
- Merge medio
- 2 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de DevQwinB/Verity
-
docs documentation good first issue medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
good first issue medium re-executor-agent tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
good first issue re-executor-agent tests trivial
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
-
good first issue medium re-executor-agent tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
-
dashboard good first issue tests trivial
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Todos los issues de DevQwinB/Verity
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
umami-software/umami#4637 ·
Los mantenedores suelen responder en 3 días
-
Hotkeys fire when pressed with the Ctrl key, so browser shortcuts also trigger player actionsPosiblemente ocupada @RaphaelFakhri la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
muxinc/media-chrome#1332 ·
Los mantenedores suelen responder en 5 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
polarsource/polar#15580 ·
Los mantenedores suelen responder en 1 día
-
accepted bug via-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
pingdotgg/t3code#20931 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug/1-unconfirmed kind/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día