MDL-46161 switch the field order of the index on mdl_files_reference to improve performance of file_storage::search_references

This commit is contained in:
Davo Smith 2014-06-27 09:38:38 +01:00
parent 7a4832ecb9
commit 463882d085
3 changed files with 22 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20140324" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20140627" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -2358,7 +2358,7 @@
<KEY NAME="repositoryid" TYPE="foreign" FIELDS="repositoryid" REFTABLE="repository_instances" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="uq_external_file" UNIQUE="true" FIELDS="repositoryid, referencehash" COMMENT="The combination of repositoryid and reference field is supposed to be a unique identification of an external file. Because the reference is a TEXT field, we can't use to compose the index. So we use the referencehash instead and the file API is responsible to keep it up-to-date"/>
<INDEX NAME="uq_external_file" UNIQUE="true" FIELDS="referencehash, repositoryid" COMMENT="The combination of repositoryid and reference field is supposed to be a unique identification of an external file. Because the reference is a TEXT field, we can't use to compose the index. So we use the referencehash instead and the file API is responsible to keep it up-to-date"/>
</INDEXES>
</TABLE>
<TABLE NAME="repository" COMMENT="This table contains one entry for every configured external repository instance.">

View File

@ -3676,5 +3676,23 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2014061000.00);
}
// Switch the order of the fields in the files_reference index, to improve the performance of search_references.
if ($oldversion < 2014062700.00) {
$table = new xmldb_table('files_reference');
$index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('repositoryid', 'referencehash'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
upgrade_main_savepoint(true, 2014062700.00);
}
if ($oldversion < 2014062700.01) {
$table = new xmldb_table('files_reference');
$index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('referencehash', 'repositoryid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
upgrade_main_savepoint(true, 2014062700.01);
}
return true;
}

View File

@ -29,11 +29,11 @@
defined('MOODLE_INTERNAL') || die();
$version = 2014062600.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2014062700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '2.8dev (Build: 20140626)'; // Human-friendly version name
$release = '2.8dev (Build: 20140627)'; // Human-friendly version name
$branch = '28'; // This version's branch.
$maturity = MATURITY_ALPHA; // This version's maturity level.