Defect #42202
closedSUM of time entries query load issue
0%
Description
SUM of time entries query loading issue
when, i remove where clause query gets executed quickly.(I know the where clause is important to validate the module is enabled for the project).
In JOIN clauses, The query validates issue_tracking module is enabled or not.
again in WHERE Clause, The validation happens for time_tracking module.
In this case, when join exec happens 4496 columns filtered
when exec move to LEFT OUTER JOIN, issue_tracking module validation. 1181 rows get filtered.
Now in where clause another 1181 again.
(4496 * 1181 * 1181) now of rows examined in query is increased.
SELECT
SUM(`time_entries`.`hours`)
FROM
`time_entries`
INNER JOIN `projects` ON `projects`.`id` = `time_entries`.`project_id`
INNER JOIN `enumerations` ON `enumerations`.`id` = `time_entries`.`activity_id`
AND `enumerations`.`type` = 'TimeEntryActivity'
INNER JOIN `users` ON `users`.`id` = `time_entries`.`user_id`
AND `users`.`type` IN ('User', 'AnonymousUser')
LEFT OUTER JOIN issues ON issues.id = time_entries.issue_id
AND (
projects.status IN (1, 5)
AND EXISTS (
SELECT
1 AS one
FROM
enabled_modules em
WHERE
em.project_id = projects.id
AND em.name = 'issue_tracking'
)
)
WHERE
(
projects.status IN (1, 5)
AND EXISTS (
SELECT
1 AS one
FROM
enabled_modules em
WHERE
em.project_id = projects.id
AND em.name = 'time_tracking'
)
)
Files
Related issues
Updated by Go MAEDA 9 days ago
- Related to Defect #40728: Slow loading of global spent time list in MySQL added
Updated by Yuvansri Thangavel 8 days ago
Hi Go MAEDA,
Now i got response with in 5 to 6 seconds avg.
Previously i do some modifications in the code for the quick response. I know it's not a good one
Because, i skip module exist condition validation in time_entry.rb model. Using the below line.
options[:skip_pre_condition] = true; in visible_condition function.
in my case, all my projects must have time entry module. That's why i made this change.
But now i applied your code change. Yep i got quick response now.
Thankyou, so much!