Skip to content

fix(runs): fix B-tree index contention on actions table#7122

Merged
AdilFayyaz merged 2 commits intov2from
adil/run-phase-status-db
Mar 31, 2026
Merged

fix(runs): fix B-tree index contention on actions table#7122
AdilFayyaz merged 2 commits intov2from
adil/run-phase-status-db

Conversation

@AdilFayyaz
Copy link
Copy Markdown

@AdilFayyaz AdilFayyaz commented Mar 31, 2026

Why are the changes needed?

UpdateActionPhase writes updated_at/ended_at as NOW() on every call, causing B-tree right-hand page contention on those indexes under concurrent load (200ms+ lock-wait). The SQLite polling path in WatchActionUpdates also lacked a run_name filter, returning updates across all runs in a project instead of just the target run.

What changes were proposed in this pull request?

  • Remove idx_actions_updated and idx_actions_ended to eliminate right-side B-tree hotspot contention on monotonically-increasing timestamp columns
  • Replace four separate single-column indexes (idx_actions_org/project/domain/run_name) with one composite idx_actions_run_lookup(org, project, domain, run_name) to serve run-scoped queries with a single selective index scan
  • Fix WatchActionUpdates SQLite polling query to include run_name in the WHERE clause, scoping results to the specific run
  • Add migration 20260330_fix_action_indexes to drop the 6 stale indexes and trigger AutoMigrate to create the composite replacement

How was this patch tested?

  • ran two psql queries to verify that the migration and the indexes were created correctly
  1. Select id from migrations
    • Found the id: 20260330_fix_action_indexes
  2. SELECT indexname FROM pg_indexes WHERE tablename = 'actions' ORDER BY indexname;
    • idx_actions_run_lookup is present (new composite index)
    • idx_actions_updated, idx_actions_ended, idx_actions_org, idx_actions_project, idx_actions_domain, idx_actions_run_name are all gone
  3. ran hello.py from the sdk on the sandbox as a smoke test

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
@AdilFayyaz AdilFayyaz self-assigned this Mar 31, 2026
@github-actions github-actions bot mentioned this pull request Mar 31, 2026
3 tasks
@AdilFayyaz AdilFayyaz changed the title perf: fix action index contention and scoped watch query fix(runs): fix B-tree index contention on actions table Mar 31, 2026
@AdilFayyaz AdilFayyaz requested a review from pingsutw March 31, 2026 04:05
Signed-off-by: M. Adil Fayyaz <62440954+AdilFayyaz@users.noreply.github.com>
@AdilFayyaz AdilFayyaz merged commit 36fa268 into v2 Mar 31, 2026
16 checks passed
@AdilFayyaz AdilFayyaz deleted the adil/run-phase-status-db branch March 31, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants