Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use none? instead of count.zero? #1030

Merged
merged 1 commit into from
Apr 9, 2021
Merged

Use none? instead of count.zero? #1030

merged 1 commit into from
Apr 9, 2021

Conversation

gr-eg
Copy link
Contributor

@gr-eg gr-eg commented Apr 9, 2021

We have run in to a performance issue when removing unused tags and not using the tags_counter

taggings.count.zero? executes the following sql

`SELECT COUNT(*) FROM taggings WHERE taggings.tag_id = ?`

This can be very slow on large tables

by using taggings.none? it instead executes:

`SELECT 1 AS one FROM taggings WHERE taggings.tag_id = 304185392 LIMIT 1`

which can always use the index and is much faster.

`taggings.count.zero?` executes the following sql
`SELECT COUNT(*) FROM taggings WHERE taggings.tag_id = ?`

This can be very slow on large tables by using
`taggings.none?` it instead executes:
`SELECT 1 AS one FROM taggings WHERE taggings.tag_id = 304185392 LIMIT 1`

which can always use the primary key index and is much faster.
@seuros seuros merged commit 4e7600c into mbleigh:master Apr 9, 2021
@seuros seuros self-assigned this Apr 9, 2021
@seuros
Copy link
Collaborator

seuros commented Jun 7, 2021

released

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