Project

General

Profile

Actions

Defect #42202

closed

SUM of time entries query load issue

Added by Yuvansri Thangavel 2 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Time tracking
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

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

explain_for_enum.png (78.5 KB) explain_for_enum.png explain query Yuvansri Thangavel, 2025-02-03 04:43

Related issues

Related to Redmine - Defect #40728: Slow loading of global spent time list in MySQLClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA 9 days ago

  • Related to Defect #40728: Slow loading of global spent time list in MySQL added
Actions #2

Updated by Go MAEDA 9 days ago

  • Status changed from New to Needs feedback

Could you please check if applying the changes in r23609 will improve performance?

Actions #3

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!

Actions #4

Updated by Go MAEDA 8 days ago

  • Status changed from Needs feedback to Closed
  • Resolution set to Fixed

Thank you for your feedback. I am glad to hear that the performance issue was resolved by the change made in #40728.

I am closing this issue.

Actions

Also available in: Atom PDF