Optimize(Search): Handle LEFT JOIN which concern counting operatio lastly #16997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On one customer's instance, we were confronted with major problems of slowness on the software list.
The first 50 softwares took almost 13 seconds to load.
Here is the list of columns displayed on the customer's site
By digging around, I've come to understand that if the column that counts the number of installations (
glpi_items_softwareversions_37010ce8f4633da91ded3e0a4c256dc9
) is followed by any otherLEFT JOIN
glpi_states_0a35c270152be19b5c8a485502badcd7
, the SQL query takes an enormous amount of time (13.877 sec).Conversely, if the column counting the number of installations is the last, the loading time is very reasonable (0.008 sec).
I have therefore deduced that there is a performance problem with the order of the
LEFT JOIN
when GLPI creates the SQL query.An
EXPLAIN
of the SQL query seems to confirm thisSQL query with "bad"
LEFT JOIN
order (lastLEFT JOIN
onglpi_states
useUsing join buffer
instead ofwhere
(seeExtra
column) maybe becausekey
,key_len
andref
arenull
)SQL query with "good" LEFT JOIN order (only
where
is used seeExtra
column)The idea of this PR is therefore to reorganise the searchoption order according to
datatype
If equal to
count
put at the end, otherwise at the beginning