If InnoDB is used the query like in course/lib.php is a really slow query:
SELECT * FROM mdl_log WHERE time > 1244979700 AND course = 1015 AND module = 'course' AND (action = 'add mod' OR action = 'update mod' OR action = 'delete mod') ORDER BY id ASC;
This might be referred to
http://bugs.mysql.com/bug.php?id=28404 and
http://bugs.mysql.com/bug.php?id=36259. The work around is simply FORCE INDEX (Thanks to Valeriy Kravchuk, MySQL Principal Support Engineer). The workaround I have done with course/lib.php is
// ----------------ORIGINAL CODE----------------
// $logs = get_records_select('log', "time > $timestart AND course = $course->id AND
// module = 'course' AND
// (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
// "id ASC");
$sqllogs = "SELECT * FROM " . $CFG->prefix . "log FORCE INDEX (coursemoduleaction) WHERE
time > $timestart AND course = $course->id AND module = 'course' AND
(action = 'add mod' OR action = 'update mod' OR action = 'delete mod') ORDER BY id ASC";
$logs = get_recordset_sql($sqllogs);
Sorry! I am not good in programming.