Skip to content

Comments

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

Merged
smudge merged 1 commit intomainfrom
smudge/stack/6
Feb 12, 2026
Merged

perf(monitor): 4 fewer queries w/ equivalent scans#95
smudge merged 1 commit intomainfrom
smudge/stack/6

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

@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
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
Copy link
Contributor

@effron effron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one question, otherwise looks good!

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 12, 2026 20:14
@smudge smudge marked this pull request as ready for review February 12, 2026 20:15
@smudge smudge requested a review from effron February 12, 2026 20:17
Copy link
Contributor

@effron effron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domainLGTM

@smudge smudge merged commit 1e3f706 into main Feb 12, 2026
47 checks passed
@smudge smudge deleted the smudge/stack/6 branch February 12, 2026 20:32
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.

2 participants