Skip to content

Conversation

@smudge
Copy link
Member

@smudge smudge commented Feb 10, 2026

Stacked PRs:


perf(monitor): 4 fewer queries w/ equivalent scans

This combines queries for count (live), future_count, and
erroring_count into a combined query for "live" jobs.

It also combines locked_count/working_count and workable_count
into a combined query for "pending" jobs.

The reason this is still two queries and not one is because on
PostgreSQL, locked_count, working_count, and workable_countall require heap access (i.e. cannot beIndex Onlyscans) -- becauselocked_atis not part of any index. Given this, we benefit from restricting the scan to as few rows as necessary, andjobs.pending` is
exactly the combined superset that supports all three counts.

Meanwhile, the "live" job query is an Index Only scan and can
theoretically benefit from not having to hit the heap. (Though
unfortunately it sometimes does require heap visits, depending on how
recently a given page has been VACUUMed.)

/no-platform

This combines queries for `count` (live), `future_count`, and
`erroring_count` into a combined query for "live" jobs.

It also combines `locked_count`/`working_count` and `workable_count`
into a combined query for "pending" jobs.

The reason this is still two queries and not one is because on
PostgreSQL, `locked_count, `working_count`, and `workable_count` all
require heap access (i.e. cannot be `Index Only` scans) -- because
`locked_at` is not part of any index. Given this, we benefit from
restricting the scan to as few rows as necessary, and `jobs.pending` is
exactly the combined superset that supports all three counts.

Meanwhile, the "live" job query is an `Index Only` scan and can
theoretically benefit from not having to hit the heap. (Though
unfortunately it sometimes does require heap visits, depending on how
recently a given page has been VACUUMed.)

/no-platform

stack-info: PR: #95, branch: smudge/stack/6
@smudge smudge marked this pull request as draft February 10, 2026 17:26
@smudge smudge changed the base branch from smudge/stack/5 to main February 10, 2026 17:26
@smudge smudge changed the base branch from main to smudge/stack/5 February 10, 2026 17:27
@smudge smudge marked this pull request as ready for review February 10, 2026 17:27
@smudge smudge marked this pull request as draft February 10, 2026 17:28
@smudge smudge changed the base branch from smudge/stack/5 to main February 10, 2026 17:28
@smudge smudge changed the base branch from main to smudge/stack/5 February 10, 2026 17:29
@smudge smudge mentioned this pull request Feb 10, 2026
@smudge smudge marked this pull request as ready for review February 10, 2026 17:29
@smudge smudge marked this pull request as draft February 10, 2026 17:31
@smudge smudge changed the base branch from smudge/stack/5 to main February 10, 2026 17:31
@smudge smudge changed the base branch from main to smudge/stack/5 February 10, 2026 17:32
@smudge smudge marked this pull request as ready for review February 10, 2026 17:32
@smudge smudge requested a review from effron February 10, 2026 17:37
@smudge smudge marked this pull request as draft February 10, 2026 18:10
@smudge smudge changed the base branch from smudge/stack/5 to main February 10, 2026 18:10
@smudge smudge changed the base branch from main to smudge/stack/5 February 10, 2026 18:10
@smudge smudge marked this pull request as ready for review February 10, 2026 18:11
smudge added a commit that referenced this pull request Feb 10, 2026
This combines queries for `count` (live), `future_count`, and
`erroring_count` into a combined query for "live" jobs.

It also combines `locked_count`/`working_count` and `workable_count`
into a combined query for "pending" jobs.

The reason this is still two queries and not one is because on
PostgreSQL, `locked_count, `working_count`, and `workable_count` all
require heap access (i.e. cannot be `Index Only` scans) -- because
`locked_at` is not part of any index. Given this, we benefit from
restricting the scan to as few rows as necessary, and `jobs.pending` is
exactly the combined superset that supports all three counts.

Meanwhile, the "live" job query is an `Index Only` scan and can
theoretically benefit from not having to hit the heap. (Though
unfortunately it sometimes does require heap visits, depending on how
recently a given page has been VACUUMed.)

/no-platform

stack-info: PR: #95, branch: smudge/stack/6
smudge added a commit that referenced this pull request Feb 10, 2026
This combines queries for `count` (live), `future_count`, and
`erroring_count` into a combined query for "live" jobs.

It also combines `locked_count`/`working_count` and `workable_count`
into a combined query for "pending" jobs.

The reason this is still two queries and not one is because on
PostgreSQL, `locked_count, `working_count`, and `workable_count` all
require heap access (i.e. cannot be `Index Only` scans) -- because
`locked_at` is not part of any index. Given this, we benefit from
restricting the scan to as few rows as necessary, and `jobs.pending` is
exactly the combined superset that supports all three counts.

Meanwhile, the "live" job query is an `Index Only` scan and can
theoretically benefit from not having to hit the heap. (Though
unfortunately it sometimes does require heap visits, depending on how
recently a given page has been VACUUMed.)

/no-platform

stack-info: PR: #95, branch: smudge/stack/6
smudge added a commit that referenced this pull request Feb 11, 2026
This combines queries for `count` (live), `future_count`, and
`erroring_count` into a combined query for "live" jobs.

It also combines `locked_count`/`working_count` and `workable_count`
into a combined query for "pending" jobs.

The reason this is still two queries and not one is because on
PostgreSQL, `locked_count, `working_count`, and `workable_count` all
require heap access (i.e. cannot be `Index Only` scans) -- because
`locked_at` is not part of any index. Given this, we benefit from
restricting the scan to as few rows as necessary, and `jobs.pending` is
exactly the combined superset that supports all three counts.

Meanwhile, the "live" job query is an `Index Only` scan and can
theoretically benefit from not having to hit the heap. (Though
unfortunately it sometimes does require heap visits, depending on how
recently a given page has been VACUUMed.)

/no-platform

stack-info: PR: #95, branch: smudge/stack/6
Base automatically changed from smudge/stack/5 to main February 11, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant