SQL performance after upgrading from 3.9.x to 3.11.x is blocking us course restorations.

SQL performance after upgrading from 3.9.x to 3.11.x is blocking us course restorations.

by Luis Alberto Asturias Núñez -
Number of replies: 3
Hello all.

We are managing a moodle with mdl_lesson_branch table composed by 12685665 rows.

In the process of importing a course or copying courses with lesson pages, the performance is poor and takes more than 30 minutes, it blocks the normal performance of the tool. Performance is worst after the upgrade from 3.9 to 3.11.

We reviewed the code and the cause is the execution of below code from mod/lesson/backup/moodle2/restore_lesson_stepslib.php:
// Replay the upgrade step 2015032700.
// Delete any orphaned lesson_branch record.
if ($DB->get_dbfamily() === 'mysql') {
$sql = "DELETE {lesson_branch}
FROM {lesson_branch}
LEFT JOIN {lesson_pages}
ON {lesson_branch}.pageid = {lesson_pages}.id
WHERE {lesson_pages}.id IS NULL";
} else {
$sql = "DELETE FROM {lesson_branch}
WHERE NOT EXISTS (
SELECT 'x' FROM {lesson_pages}
WHERE {lesson_branch}.pageid = {lesson_pages}.id)";
}

$DB->execute($sql);

The sentence takes about 60 seconds in our database.

Does anyone know if this SQL request can be safely improved or cleaned from the code.
We are considering deleting this query and planning a nightly execution to avoid any problems with orphaned lesson branch records.

Many thanks in advance.

Average of ratings: Useful (1)
In reply to Luis Alberto Asturias Núñez

Re: SQL performance after upgrading from 3.9.x to 3.11.x is blocking us course restorations.

by Ken Task -
Picture of Particularly helpful Moodlers
Suggest installing and running as superuser of DB server, MySQLTuner - a perl script.  It will ID tables in need of optimization and have some recommendations for settings tweaks.


'SoS', Ken
In reply to Ken Task

Re: SQL performance after upgrading from 3.9.x to 3.11.x is blocking us course restorations.

by Luis Alberto Asturias Núñez -
No issues were detected.
It seems more related with the size of the tables used by the SQL sentence: "DELETE {lesson_branch} FROM {lesson_branch} LEFT JOIN {lesson_pages} ON {lesson_branch}.pageid = lesson_pages}.id WHERE {lesson_pages}.id IS NULL"

We have recreated indexes and rebuild statistics without any improvement.
In reply to Luis Alberto Asturias Núñez

Re: SQL performance after upgrading from 3.9.x to 3.11.x is blocking us course restorations.

by Maria del Carmen Loriente Yañez -
Good morning,

Have you found a solution for this? We are trying to update to version 3.11 and this process is blocking us.

Thanks in advance