MDL-35453 quiz reports: don't order by id.

We were using ORDER BY id even though there was a perfectly good
attempt column to order the attempts by one user at one quiz.

Also, Oracle was complaining:
Debug info: ORA-01799: a column may not be outer-joined to a subquery
This commit is contained in:
Tim Hunt 2014-02-12 17:26:30 +00:00
parent 7784c3ad18
commit 2ce9a94d96
3 changed files with 106 additions and 24 deletions

View file

@ -156,35 +156,27 @@ function quiz_report_qm_filter_select($quiz, $quizattemptsalias = 'quiza') {
function quiz_report_grade_method_sql($grademethod, $quizattemptsalias = 'quiza') {
switch ($grademethod) {
case QUIZ_GRADEHIGHEST :
return "$quizattemptsalias.id = (
SELECT MIN(qa2.id)
FROM {quiz_attempts} qa2
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid AND
COALESCE(qa2.sumgrades, 0) = (
SELECT MAX(COALESCE(qa3.sumgrades, 0))
FROM {quiz_attempts} qa3
WHERE qa3.quiz = $quizattemptsalias.quiz AND
qa3.userid = $quizattemptsalias.userid
)
)";
qa2.userid = $quizattemptsalias.userid AND (
COALESCE(qa2.sumgrades, 0) > COALESCE($quizattemptsalias.sumgrades, 0) OR
(COALESCE(qa2.sumgrades, 0) = COALESCE($quizattemptsalias.sumgrades, 0) AND qa2.attempt < $quizattemptsalias.attempt)
))";
case QUIZ_GRADEAVERAGE :
return '';
case QUIZ_ATTEMPTFIRST :
return "$quizattemptsalias.id = (
SELECT MIN(qa2.id)
FROM {quiz_attempts} qa2
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid)";
qa2.userid = $quizattemptsalias.userid AND
qa2.attempt < $quizattemptsalias.attempt)";
case QUIZ_ATTEMPTLAST :
return "$quizattemptsalias.id = (
SELECT MAX(qa2.id)
FROM {quiz_attempts} qa2
return "NOT EXISTS (SELECT 1 FROM {quiz_attempts} qa2
WHERE qa2.quiz = $quizattemptsalias.quiz AND
qa2.userid = $quizattemptsalias.userid)";
qa2.userid = $quizattemptsalias.userid AND
qa2.attempt > $quizattemptsalias.attempt)";
}
}