Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75900

add an index on reaggregate field

XMLWordPrintable

    • MOODLE_400_STABLE

      Almost every minute this query is logged on our MariaDB as a slow query :

      # Query_time: 4.014217  Lock_time: 0.000066  Rows_sent: 0  Rows_examined: 2947622
      # Rows_affected: 0  Bytes_sent: 404
      SELECT DISTINCT c.id AS courseid, cr.id AS criteriaid, cco.userid, cr.criteriatype, ccocr.timecompleted
                             FROM mdl_course_completion_criteria cr
                       INNER JOIN mdl_course c ON cr.course = c.id
                       INNER JOIN mdl_course_completions cco ON cco.course = c.id
                        LEFT JOIN mdl_course_completion_crit_compl ccocr
                               ON ccocr.criteriaid = cr.id AND cco.userid = ccocr.userid
                            WHERE c.enablecompletion = 1
                              AND cco.timecompleted IS NULL
                              AND cco.reaggregate > 0 AND cco.reaggregate < '1664963355' ORDER BY courseid, cco.userid;

      I did some tests and it seems that creating an index on cco.reaggregate reduces the execution by 10.

            Unassigned Unassigned
            jboulen Julien Boulen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.