Dear all:
It looks like by default, Moodle 1.9.x would set up a cron job that would run a query every 15 minutes to clean out the "grades history" table. According to our system administrators, this doesn't appear to cause any site slow down or a serious bump in CPU or overall activity. But it seems that it is not a really efficient query (especially when the grade history table gets bigger). Here is a brief sample report:
===========================
User@Host: xxxxx @ localhost [127.0.0.1]
Query_time: 2.411335 Lock_time: 0.000107 Rows_sent: 0 Rows_examined: 0
SET timestamp=1257566407;
DELETE FROM mdl_grade_grades_history WHERE time modified < 1226030404;
User@Host: xxxxx @ localhost [127.0.0.1]
Query_time: 2.314545 Lock_time: 0.000041 Rows_sent: 0 Rows_examined: 0
SET timestamp=1257567359;
DELETE FROM mdl_grade_grades_history WHERE timemodified < 1226031356;
mysql> explain select * FROM mdl_grade_grades_history WHERE timemodified < 1226031356;
--- [snip]
===============================
A possible solution would be to add an index on time modified:
ALTER TABLE `mdl_grade_grades_history` ADD INDEX `timemodified` (`timemodified`) ;
My questions are:
1. Is it really necessary to run this query every 15 minutes?
2. If that's the case, would it be a good idea to maybe modify the installation script so that it would create a index on timemodified with mdl_grade_grades_history by default?
3. Any other thoughts or comments about this?
Thanks!
Possible inefficient cron job query with mdl_grade_grades_history table
by Wen Hao Chuang -
Number of replies: 2
In reply to Wen Hao Chuang
Re: Possible inefficient cron job query with mdl_grade_grades_history table
by Tim Hunt -
This is related to the gradehistorylifetime setting on the cleanup page.
It is crazy to do this every 15 minutes. Once per day would be more than enough. Please put a bug/patch in the tracker.
It is crazy to do this every 15 minutes. Once per day would be more than enough. Please put a bug/patch in the tracker.
In reply to Tim Hunt
Re: Possible inefficient cron job query with mdl_grade_grades_history table
by Wen Hao Chuang -
OK I have put a bug report in the tracker. MDL-20912. I should be able to come up with a patch shortly and it will be posted in the tracker. Thanks Tim!