Skip to content

Commit

Permalink
MDL-66253 calendar: New indexes to reduce full table scans
Browse files Browse the repository at this point in the history
The eventtype index will stop full table scans when the Event API
retrieves events for a group or category and there are a large number
of groups or categories so it cannot use the groupid or categoryid
indexes efficiently.

The modulename-instance index will improve the performance of queries
used by activity backup, deletion and visibility changes where all
the events for an individual activity need to be found.
  • Loading branch information
NeillM committed Jan 14, 2020
1 parent 28c30ff commit 2fc2dfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@
<INDEX NAME="uuid" UNIQUE="false" FIELDS="uuid"/>
<INDEX NAME="type-timesort" UNIQUE="false" FIELDS="type, timesort"/>
<INDEX NAME="groupid-courseid-categoryid-visible-userid" UNIQUE="false" FIELDS="groupid, courseid, categoryid, visible, userid" COMMENT="used for calendar view"/>
<INDEX NAME="eventtype" UNIQUE="false" FIELDS="eventtype"/>
<INDEX NAME="modulename-instance" UNIQUE="false" FIELDS="modulename, instance"/>
</INDEXES>
</TABLE>
<TABLE NAME="cache_filters" COMMENT="For keeping information about cached data">
Expand Down
17 changes: 17 additions & 0 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2145,5 +2145,22 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2019122000.01);
}

if ($oldversion < 2020010900.02) {
$table = new xmldb_table('event');

// This index will improve the performance when the Events API retrieves category and group events.
$index = new xmldb_index('eventtype', XMLDB_INDEX_NOTUNIQUE, ['eventtype']);
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// This index improves the performance of backups, deletion and visibilty changes on activities.
$index = new xmldb_index('modulename-instance', XMLDB_INDEX_NOTUNIQUE, ['modulename', 'instance']);
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

upgrade_main_savepoint(true, 2020010900.02);
}
return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2020010900.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2020010900.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.9dev (Build: 20200109)'; // Human-friendly version name
Expand Down

0 comments on commit 2fc2dfb

Please sign in to comment.