Permalink
Browse files

MDL-31072: Added indexes to table role_assignments to speed up work i…

…n many-users-many-contexts environments
  • Loading branch information...
1 parent 037ef68 commit a519d915bf809df86bcd57041ce35ff2327ed73d @marinaglancy marinaglancy committed with kordan Jan 10, 2012
Showing with 27 additions and 2 deletions.
  1. +4 −2 lib/db/install.xml
  2. +23 −0 lib/db/upgrade.php
View
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20111214" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20120110" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -1131,7 +1131,9 @@
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="contextid"/>
</KEYS>
<INDEXES>
- <INDEX NAME="sortorder" UNIQUE="false" FIELDS="sortorder"/>
+ <INDEX NAME="sortorder" UNIQUE="false" FIELDS="sortorder" NEXT="rolecontext"/>
+ <INDEX NAME="rolecontext" UNIQUE="false" FIELDS="roleid, contextid" COMMENT="Index on roleid and contextid" PREVIOUS="sortorder" NEXT="usercontextrole"/>
+ <INDEX NAME="usercontextrole" UNIQUE="false" FIELDS="userid, contextid, roleid" COMMENT="Index on userid, contextid and roleid" PREVIOUS="rolecontext"/>
</INDEXES>
</TABLE>
<TABLE NAME="role_capabilities" COMMENT="permission has to be signed, overriding a capability for a particular role in a particular context" PREVIOUS="role_assignments" NEXT="role_names">
View
@@ -112,6 +112,29 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011120500.03);
}
+ if ($oldversion < 2012020200.03) {
+
+ // Define index rolecontext (not unique) to be added to role_assignments
+ $table = new xmldb_table('role_assignments');
+ $index = new xmldb_index('rolecontext', XMLDB_INDEX_NOTUNIQUE, array('roleid', 'contextid'));
+
+ // Conditionally launch add index rolecontext
+ if (!$dbman->index_exists($table, $index)) {
+ $dbman->add_index($table, $index);
+ }
+
+ // Define index usercontextrole (not unique) to be added to role_assignments
+ $index = new xmldb_index('usercontextrole', XMLDB_INDEX_NOTUNIQUE, array('userid', 'contextid', 'roleid'));
+
+ // Conditionally launch add index usercontextrole
+ if (!$dbman->index_exists($table, $index)) {
+ $dbman->add_index($table, $index);
+ }
+
+ // Main savepoint reached
+ upgrade_main_savepoint(true, 2012020200.03);
+ }
+
return true;
}

0 comments on commit a519d91

Please sign in to comment.