Moodle

Scheduled course backup runs full table scan on mdl_backup_log

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.8.4, 1.9
  • Fix Version/s: 1.9
  • Component/s: Backup, Performance
  • Labels:
    None
  • Environment:
    MySQL 5.0.22
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

If scheduled course backups are enabled, cron.php calls schedule_backup_cron() whenever it runs. Line 36 of backup/backup_scheduled.php is

$numofrec = count_records_select ("backup_log","time > $timeafter");

This runs a full scan on mdl_backup_log, which can be a very large table depending on your site's log-retention policy. For example, we have cron.php scheduled to run every 5 minutes, and ~65,000 rows are read, simply to find out whether a backup task is currently running. The query takes around 4 seconds to complete. A workaround is to add an index to the table.

ALTER TABLE mdl_backup_log ADD INDEX (time);

This avoids the full table scan, and the query now completes in less than one hundredth of a second at our site. The drawback is that mdl_backup_log.MYI is now almost as big as mdl_backup_log.MYD I can't see any way of working around this issue in the PHP code.

Issue Links

Activity

Hide
Chris Fryer added a comment -

Speed of query updated

Show
Chris Fryer added a comment - Speed of query updated
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Chris,

that exact index was added to Moodle 1.9 some time ago (it will be created as part of the 1.8 => 1.9 upgrade). Anyway, it's safe if you've created it manually in you 1.8 site: upgrade will simply skip its creation.

Closing, thanks for report, ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Chris, that exact index was added to Moodle 1.9 some time ago (it will be created as part of the 1.8 => 1.9 upgrade). Anyway, it's safe if you've created it manually in you 1.8 site: upgrade will simply skip its creation. Closing, thanks for report, ciao
Hide
Lee Bowyer added a comment -

Eloy,

Having just upgraded a moodle instance to 1.9.5+ from 1.8.4 (Upgrading Moodle database from version 1.8.4 (2007021540) to 1.9.5+ (Build: 20090805) (2007101550)...) - I notice that no index was created for mdl_backup_log.time.

~L

Show
Lee Bowyer added a comment - Eloy, Having just upgraded a moodle instance to 1.9.5+ from 1.8.4 (Upgrading Moodle database from version 1.8.4 (2007021540) to 1.9.5+ (Build: 20090805) (2007101550)...) - I notice that no index was created for mdl_backup_log.time. ~L
Hide
Lee Bowyer added a comment -

Also running check indexes produces the following for mdl_backup_log:

backup_log
Key: primary (id) OK
Key: foreign (courseid) references backup_courses (courseid) OK

no reference to the time column is made.

I can also confirm that this produces a considerable performance boost one the index is created.

~L

Show
Lee Bowyer added a comment - Also running check indexes produces the following for mdl_backup_log: backup_log Key: primary (id) OK Key: foreign (courseid) references backup_courses (courseid) OK no reference to the time column is made. I can also confirm that this produces a considerable performance boost one the index is created. ~L

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: