Project: moodle
Issue MDL-38228: Major Performance Problem with "Moving Modules" upgrade step
The upgrade script portion of the fix for MDL-37939 is inefficient and causes a considerable performance problem for upgrading large sites. The process queries course modules for each course section individually. That's a pretty big deal for Moodlerooms, where our largest site has nearly 445,000 course sections, and an average of over 6,000 course sections across 1,200 sites. The root of the problem is finding the course modules which don't exist in the sequence field of the related course section. The following query will get those course section records for you. {code:sql} SELECT cs.* FROM mdl_course_sections cs INNER JOIN mdl_course_modules cm ON (cm.course = cs.course AND cm.section = cs.id) WHERE CONCAT(',', cs.sequence, ',') NOT LIKE CONCAT('%,', cm.id, ',%') {code} The following returns an average of 33 course sections for affected sites (~80%), with a maximum of 772 course sections. Note: FIND_IN_SET is an operator that only works for MySQL and PG, but the query can be tweaked to support any RDBMS. *Additonally:* for 2.5 and 2.6 branches the new upgrade script has to be run again because of another bug. In version 2.4 we can just replace the old script with a faster one.
Story points: 20