MDL-31495 Performance improvement in question engine upgrade SQL
[moodle.git] / question / engine / upgrade / upgradelib.php
index 8c6e175..b11ef48 100644 (file)
@@ -155,19 +155,19 @@ class question_engine_attempt_upgrader {
 
         $quizattemptsrs = $DB->get_recordset_select('quiz_attempts', $where, $params, 'uniqueid');
         $questionsessionsrs = $DB->get_recordset_sql("
-                SELECT *
-                FROM {question_sessions}
-                WHERE attemptid IN (
-                    SELECT uniqueid FROM {quiz_attempts} WHERE $where)
-                ORDER BY attemptid, questionid
+                SELECT s.*
+                  FROM {question_sessions} s
+                  JOIN {quiz_attempts} a ON (attemptid = uniqueid)
+                 WHERE $where
+              ORDER BY attemptid, questionid
         ", $params);
 
         $questionsstatesrs = $DB->get_recordset_sql("
-                SELECT *
-                FROM {question_states}
-                WHERE attempt IN (
-                    SELECT uniqueid FROM {quiz_attempts} WHERE $where)
-                ORDER BY attempt, question, seq_number, id
+                SELECT s.*
+                  FROM {question_states} s
+                  JOIN {quiz_attempts} ON (s.attempt = uniqueid)
+                 WHERE $where
+              ORDER BY s.attempt, question, seq_number, s.id
         ", $params);
 
         $datatodo = $quizattemptsrs && $questionsessionsrs && $questionsstatesrs;