Course restore includes a bad performance SQL Update query

Course restore includes a bad performance SQL Update query

khaled flihan發表於
Number of replies: 2
Hi,  
I am trying to restore a course, it contains a lot of questions, and it takes a long time to restore, and it turns out that there is a bad performance query problem,
the Course retrieval includes SQL Update with bad performance, does not use an index, scans thousands of records, and causes a delay of 40 percent of the course retrieval time 

​my moodle ver:  Moodle 4.2 (Build: 20230424)
​the query from : 
   "moodle/backup/moodle2/restore_stepslib.php "
    class  restore_move_module_questions_categories 
    function define_execution()
   //Update the context id of any tags applied to any questions in these categories.

bad query perfomramnce

The update Query is executed many times, each time ; reads (full table scan ) 231282 records, and it consumes 100% of the CPU, and takes about 7 milliseconds each time.
the query from mariadb  log" 
execution MySQL log

I have rewritten  the Update Query as following; so that, following the index, the execution time is greatly reduced, the process becomes fast, and it does not waste time:

updated query
 
Hope; developers check the query and find a proper solution!! 
評比平均分數:Useful (1)
In reply to khaled flihan

Re: Course restore includes a bad performance SQL Update query

Séverin TERRIER發表於
Documentation writers的相片 Particularly helpful Moodlers的相片 Testers的相片 Translators的相片
Hi,

You probably need to create a tracker item, linking to this discussion, and providing as much details as possible.

And ideally code changes.

HTH,
Séverin
評比平均分數:Useful (1)