Slow query is killing my moodle

Slow query is killing my moodle

by Wilson Camilo Uribe Neira -
Number of replies: 2
I have a moodle 1.9.3 with a mysql grade_grades table of 1.188.739 rows and grade_items of 2.307 and I see a lot of queries like this:

SELECT DISTINCT go.userid FROM mdl_grade_grades go
JOIN mdl_grade_items gi ON gi.id = go.itemid
LEFT OUTER JOIN mdl_grade_grades g ON (g.userid = go.userid AND g.itemid = 1769)
WHERE gi.id <> 1769 AND g.id IS NULL;

that take around 30 seconds or more to execute.

This is blocking the tables
grade_grades and grade_items and slowing a lot my moodle.

There is a way to getting it runnning more faster?

By the way the query is in the function compute of lib/grade/grade_item.php

// precreate grades - we need them to exist
$sql = "SELECT DISTINCT go.userid
FROM {$CFG->prefix}grade_grades go
JOIN {$CFG->prefix}grade_items gi
ON gi.id = go.itemid
LEFT OUTER JOIN {$CFG->prefix}grade_grades g
ON (g.userid = go.userid AND g.itemid = $this->id)
WHERE gi.id <> $this->id AND g.id IS NULL";
In reply to Wilson Camilo Uribe Neira

Re: Slow query is killing my moodle

by Daniel Neis Araujo -
Picture of Core developers Picture of Plugin developers Picture of Translators