Fix superfluous SELECT when scheduling a single future job - #807
Open
Mohammadalkhassawneh wants to merge 1 commit into
Open
Mohammadalkhassawneh wants to merge 1 commit into
Mohammadalkhassawneh wants to merge 1 commit into
Conversation
When a single job is enqueued, each Execution subclass fires a SELECT on solid_queue_jobs before INSERT. This happens because: 1. assumes_attributes_from_job sets a before_create callback that calls job.send(attribute) for each attribute to copy from the job record. 2. Since create_or_find_by!(job_id: id) only sets the job_id foreign key, the job association isn't loaded — so accessing it triggers a SELECT. The bulk path (enqueue_all) already avoids this by using insert_all, which bypasses callbacks entirely. Fix: pass job: self via the create_or_find_by! block so the association is already loaded in memory when both the before_create callback and the belongs_to validation run. No DB round-trip needed. Applied to all three single-job dispatch paths: schedule (ScheduledExecution), ready (ReadyExecution), and block (BlockedExecution).
Mohammadalkhassawneh
force-pushed
the
fix-superfluous-select-on-single-job-schedule
branch
from
September 24, 2026 10:15
6e2bffa to
cfad0ed
Compare
Mohammadalkhassawneh
marked this pull request as ready for review
September 24, 2026 10:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a single job is enqueued, Execution subclasses (
ScheduledExecution,ReadyExecution,BlockedExecution) each fire an extraSELECT solid_queue_jobs WHERE id = ?immediately before their INSERT.The root cause is
assume_attributes_from_job— abefore_createcallback that copiesqueue_name,priority, and any subclass-specific attributes from the job record:Because
create_or_find_by!(job_id: id)only sets thejob_idFK, thejobassociation is not loaded. Callingjob.send(attribute)lazy-loads it, triggering a SELECT. The bulk path (enqueue_all) already avoids this becauseinsert_allbypasses ActiveRecord callbacks entirely. The single-job paths do not.Fix
Pass
job: selfvia thecreate_or_find_by!block so the association is already loaded in memory whenassume_attributes_from_jobfires:Applied to all three single-job dispatch paths:
schedule,ready, andblock.