-
Improvement
-
Resolution: Fixed
-
Major
-
2.5.2, 2.5.3, 2.6, 2.7.20, 3.2.4, 3.3.1, 3.4
-
MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
-
MOODLE_34_STABLE
-
Hi,
We encounter slow-queries generated by "enrol/meta/locallib.php". Executed query looks like this:
SELECT ue.userid, ue.enrolid, pue.pstatus |
FROM mdl_user_enrolments ue |
JOIN mdl_enrol e ON (e.id = ue.enrolid AND e.enrol = 'meta' ) |
JOIN (SELECT xpue.userid, xpe.courseid, MIN(xpue.status + xpe.status) AS pstatus |
FROM mdl_user_enrolments xpue |
JOIN mdl_enrol xpe ON (xpe.id = xpue.enrolid AND xpe.enrol <> 'meta' AND xpe.enrol IN ('self','manual','guest','flatfile','database','meta','ldap','cohort')) |
GROUP BY xpue.userid, xpe.courseid |
) pue ON (pue.courseid = e.customint1 AND pue.userid = ue.userid) |
WHERE (pue.pstatus = 0 AND ue.status > 0) OR (pue.pstatus > 0 and ue.status = 0) |
It runs in about 15 seconds here.
I think we could speed it with this query or something like that (which allows the use of indexes):
SELECT ue.userid, ue.enrolid, pstatus |
FROM mdl_user_enrolments ue |
JOIN mdl_enrol e ON (e.id = ue.enrolid AND e.enrol = 'meta' AND ue.status=0) |
JOIN (SELECT xpue.userid, xpe.courseid, xpue.status+xpe.status pstatus |
FROM mdl_user_enrolments xpue JOIN mdl_enrol xpe ON (xpe.id = xpue.enrolid AND xpe.enrol <> 'meta') |
) pue ON (pue.courseid = e.customint1 AND pue.userid = ue.userid) |
WHERE |
pstatus > 0
|
UNION
|
SELECT ue.userid, ue.enrolid, pstatus |
FROM mdl_user_enrolments ue |
JOIN mdl_enrol e ON (e.id = ue.enrolid AND e.enrol = 'meta' AND ue.status>0) |
JOIN (SELECT xpue.userid, xpe.courseid, xpue.status+xpe.status pstatus |
FROM mdl_user_enrolments xpue JOIN mdl_enrol xpe ON (xpe.id = xpue.enrolid AND xpe.enrol <> 'meta') |
) pue ON (pue.courseid = e.customint1 AND pue.userid = ue.userid) |
WHERE |
pstatus = 0
|
And then create indexes on mdl_user_enrolments.status and mdl_enrol.status, so it can run under one second.
Sorry if I'm wrong since I don't catch the meaning of this query...