Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove redundant good_jobs.active_job_id index #1181

Merged
merged 5 commits into from
Dec 19, 2023

Conversation

andyatkinson
Copy link
Contributor

Try running active_record_doctor on a project with GoodJob migrations:

bundle exec rake active_record_doctor

You'll see this output:

remove the index index_good_jobs_on_active_job_id from the table good_jobs - queries should be able to use the following index instead: index_good_jobs_on_active_job_id_and_created_at

This change removes the single column index on 'active_job_id'

A query that used that index before could instead use the existing multicolumn index on
['active_job_id', 'created_at'], where ‘active_job_id’ is also the “leading” column.

The single column index is not a unique index that enforces a unique constraint.

So the single column appears redundant given the multicolumn index with the same leading column, which means it could be removed.

Try running active_record_doctor on a project with GoodJob migrations:

```sh
bundle exec rake active_record_doctor
```

You'll see this output:

remove the index index_good_jobs_on_active_job_id from the table
good_jobs - queries should be able to use the following index instead:
index_good_jobs_on_active_job_id_and_created_at

This change removes the single column index on 'active_job_id'

A query that used that index before could instead use the existing
multicolumn index on
['active_job_id', 'created_at'], where ‘active_job_id’ is also the
“leading” column.

The single column index is not a unique index that enforces a unique
constraint.

So the single column appears redundant given the multicolumn index with
the same leading column, which means it could be removed.
@bensheldon bensheldon changed the title Remove redundant index Remove redundant good_jobs.active_job_id index Dec 18, 2023
@bensheldon bensheldon merged commit 2dc07b7 into bensheldon:main Dec 19, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants