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

Job count by state query performance #367

Closed
guenaelgonnord opened this issue May 21, 2024 · 4 comments
Closed

Job count by state query performance #367

guenaelgonnord opened this issue May 21, 2024 · 4 comments

Comments

@guenaelgonnord
Copy link
Contributor

Hi,

on a heavy loaded database instance with millions of hangfire runned jobs, I think I found a better index on job count by state query :

SELECT
  "statename" "State",
  COUNT("id") "Count"
FROM
  "hangfire"."job"
WHERE
  "statename" IS NOT NULL
GROUP BY
  "statename"

We might use this one that is using original where clause + included column :
create or replace index ix_hangfire_job_statename_is_not_null on job(statename) include (id) where statename is not null;

With that index, the query above is now performing an index only scan which performs better.

Do you think it could be a good option for your database init script ?

@azygis
Copy link
Collaborator

azygis commented May 21, 2024

Would you be able to provide the differences in terms of execution plans? One without new index, one with, on that heavily-loaded database if possible? Would be nice if it's links to dalibo visualizer.

@guenaelgonnord
Copy link
Contributor Author

guenaelgonnord commented May 21, 2024

Here are 2 screenshots from Query insights (Google CloudSQL PostgreSQL) :
Screenshot from 2024-05-21 17-12-37
Screenshot from 2024-05-21 17-12-51

More explain : https://explain.dalibo.com/plan/043bdcc9d5e5cf1a

@azygis
Copy link
Collaborator

azygis commented Jun 27, 2024

I don't see why not, honestly. If it helps, it helps, while I personally can't see how it could regress anything. Would you be willing to create a PR for this new index?

azygis added a commit that referenced this issue Jun 29, 2024
…ery-performance

#367 - Improve job count by state query performance
@azygis
Copy link
Collaborator

azygis commented Jun 29, 2024

It's been merged, but will be released later on when there are more changes. You're free to just continue using the same index as it will later be recreated with an update.

@azygis azygis closed this as completed Jun 29, 2024
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

No branches or pull requests

2 participants