-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.1.4
-
MOODLE_401_STABLE
There is a slow query issue in the core Moodle code, specifically in the completion_criteria_course.php file. The problem occurs in the cron() function on line 155. This query takes an excessive amount of time, approximately 4 minutes, to complete even when it returns an empty set.
$sql = "
SELECT DISTINCT
c.id AS course,
cr.id AS criteriaid,
ra.userid AS userid,
cc.timecompleted AS timecompleted
FROM
cr
INNER JOIN
c
ON cr.course = c.id
INNER JOIN
con
ON con.instanceid = c.id
INNER JOIN
ra
ON ra.contextid = con.id
INNER JOIN
cc
ON cc.course = cr.courseinstance
AND cc.userid = ra.userid
LEFT JOIN
ccc
ON ccc.criteriaid = cr.id
AND ccc.userid = ra.userid
WHERE
cr.criteriatype = ".COMPLETION_CRITERIA_TYPE_COURSE."
AND con.contextlevel = ".CONTEXT_COURSE."
AND c.enablecompletion = 1
AND ccc.id IS NULL
AND cc.timecompleted IS NOT NULL
";