Skip to content

Add the missing LIMIT 1 to findLatestExecutedJob - #1840

Merged
Seldaek merged 1 commit into
mainfrom
perf/limit-latest-job-query
Sep 8, 2026
Merged

Add the missing LIMIT 1 to findLatestExecutedJob#1840
Seldaek merged 1 commit into
mainfrom
perf/limit-latest-job-query

Conversation

@Seldaek

@Seldaek Seldaek commented Sep 7, 2026

Copy link
Copy Markdown
Member

The query only ever consumes one row — it's fed to fetchOne() — but had no LIMIT, so MySQL sorted every matching job row before discarding all but the first.

Job volume per package is low enough that this was never expensive, hence no new index. The LIMIT is free though, and it matches findLatestMigrationJob() immediately above it, which already uses setMaxResults(1) for the same shape of query.

The new tests pin the ordering semantics the LIMIT relies on — newest executed job wins, queued jobs and other packages/types are not considered — since a wrong LIMIT on an unstable sort is the failure mode worth guarding.

Verification

composer phpstan clean, full suite green.

The query only ever consumes one row - it is fed to fetchOne() - but had no LIMIT, so
MySQL sorted every matching job row before discarding all but the first. Job volume per
package is low enough that this was never expensive, hence no new index, but the LIMIT
is free and matches findLatestMigrationJob() right above it, which already uses
setMaxResults(1) for the same shape of query.

The new tests pin the ordering semantics the LIMIT relies on: newest executed job wins,
queued jobs and other packages/types are not considered.
@Seldaek
Seldaek merged commit 8c2dee7 into main Sep 8, 2026
8 checks passed
@Seldaek
Seldaek deleted the perf/limit-latest-job-query branch September 8, 2026 08:59
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