-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an index to better support
smaller_number_is_higher_priority
(#…
…1213) The preexisting index (introduced in #726) gave a direct answer to the materialized subquery used to find candidate jobs, subject to the ordering rules that were in place at that time. In #883, `GoodJob` deprecated that ordering in favour of a lower-is-more-important scheme, aligning with Active Job. When there are a substantial number of completed jobs, the `priority desc` index does not allow for a straight index scan, and may not actually be used by the planner. Aligning the sort orders here allows for the subquery to be satisfied directly. Although `ASC NULLS LAST` is the default (as observable in the generated schema) it seems appropriate to be explicit in the actual index declaration, although mostly for consistency with the previous version.
- Loading branch information
Showing
6 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
demo/db/migrate/20240114223450_create_index_good_job_jobs_for_candidate_lookup.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateIndexGoodJobJobsForCandidateLookup < ActiveRecord::Migration[7.1] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.index_name_exists?(:good_jobs, :index_good_job_jobs_for_candidate_lookup) | ||
end | ||
end | ||
|
||
add_index :good_jobs, [:priority, :created_at], order: { priority: "ASC NULLS LAST", created_at: :asc }, | ||
where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup, | ||
algorithm: :concurrently | ||
end | ||
end |
This file contains 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
This file contains 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
19 changes: 19 additions & 0 deletions
19
...job/templates/update/migrations/11_create_index_good_job_jobs_for_candidate_lookup.rb.erb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateIndexGoodJobJobsForCandidateLookup < ActiveRecord::Migration<%= migration_version %> | ||
disable_ddl_transaction! | ||
|
||
def change | ||
reversible do |dir| | ||
dir.up do | ||
# Ensure this incremental update migration is idempotent | ||
# with monolithic install migration. | ||
return if connection.index_name_exists?(:good_jobs, :index_good_job_jobs_for_candidate_lookup) | ||
end | ||
end | ||
|
||
add_index :good_jobs, [:priority, :created_at], order: { priority: "ASC NULLS LAST", created_at: :asc }, | ||
where: "finished_at IS NULL", name: :index_good_job_jobs_for_candidate_lookup, | ||
algorithm: :concurrently | ||
end | ||
end |
This file contains 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