-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Optimize counts in search queries #20587
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good since no tests are broken but just looking at the code it is hard to understand what exact performances change happened.
Maybe a real example of some before/after timings of the SQL request would help us see the improvement?
A question for maintainers: I don't know if it is worth spending time on this but maybe we could setup something to keep track of the performances of a few important process?
This would make sure we don't have regression on this kind of search engine stuff that can easily break the next time it is modified (as some performances gain on a feature of the search engine can easily lead to losses for others features, we've seen it before).
A quick search show me there is this tool https://github.com/phpbench/phpbench, but I don't know if the results would be exploitable as we don't control the CI runners and they are not always equal in performances.
Edit: the runner would not be a problem as I guess we would generate the baseline on the same runner anyway and would only mesure the difference between the baseline on main and the changes from the PR, I think it can actually be setup quite easily.
Yes, this is the same issue: the slowdown occurs when both the "Number of writer tickets" and "Number of tickets as requester" columns are used simultaneously. Note that no slowdown is observed when either column is used individually.
This patch is not compatible with GLPI 10.0. It targets the next major release because it alters the behavior of the search engine (a core and impactful feature in GLPI). However, this use case is specific and easily avoidable, which is why the fix is planned for the next major version (>11.1). |
Checklist before requesting a review
Please delete options that are not relevant.
Description
Attempts to optimize the SQL search query when performing a
COUNT
, especially in user-related searches. Currently, up to threesearchoptions
can be used to count tickets linked to a user. When the database contains a large number of tickets and multiple such columns are selected, the query consumes significant resources and can crash GLPI if it takes too long.The issue stems from
LEFT JOIN
s being executed before the count, forcing the database to process a large number of rows. This PR refactors the query to move the calculation into a subquery, on which theLEFT JOIN
is then performed. This avoids multiplying intermediate rows and significantly reduces query overhead.Screenshots (if appropriate):