-
Bug
-
Resolution: Fixed
-
Minor
-
3.4.6, 3.5.3
-
MySQL
-
MOODLE_34_STABLE, MOODLE_35_STABLE
-
MOODLE_35_STABLE, MOODLE_36_STABLE
-
The privacy provider for core_grade calls the following SQL in \core_grades\privacy\provider::get_contexts_for_userid(). On MySQL at least, this is incredibly inefficient as it causes full table scans on grade_grades and grade_grades_history. (We have seen it take over 24 hours to run, with 800,000+ and 15.5 million records in those tables respectively.)
SELECT DISTINCT ctx.id |
FROM {grade_items} gi |
JOIN {context} ctx |
ON ctx.instanceid = gi.courseid |
AND ctx.contextlevel = :courselevel |
LEFT JOIN {grade_grades} gg |
ON gg.itemid = gi.id |
AND (gg.userid = :userid1 OR gg.usermodified = :userid2) |
LEFT JOIN {grade_grades_history} ggh |
ON ggh.itemid = gi.id |
AND ( |
ggh.userid = :userid3
|
OR ggh.loggeduser = :userid4 |
OR ggh.usermodified = :userid5 |
)
|
WHERE gg.id IS NOT NULL |
OR ggh.id IS NOT NULL |
|
This seems to be down to MySQL being unable to optimise the query to use indexes for all the joins and the filters.