Quantcast
Channel: Backup and restore
Viewing all articles
Browse latest Browse all 6815

SQL Performance on lesson course restoration

$
0
0
by Luis Alberto Asturias Núñez.  

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.

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.


Viewing all articles
Browse latest Browse all 6815

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>