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.

door Luis Alberto Asturias Núñez -
Aantal antwoorden: 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.

Gemiddelde van de beoordelingen: Useful (1)
Als antwoord op Luis Alberto Asturias Núñez

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

door Ken Task -
Foto van 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
Gemiddelde van de beoordelingen:  -
Als antwoord op Ken Task

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

door 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.
Gemiddelde van de beoordelingen:  -
Als antwoord op Luis Alberto Asturias Núñez

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

door 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
Gemiddelde van de beoordelingen:  -