Skip to content

Commit

Permalink
MDL-45642 questions: add required index to question_attempts.
Browse files Browse the repository at this point in the history
It is important to be able to tell which behaviours are in use, and
without this index, it requires a complete scan of this table, which can
be very big, to verify that a behaviour is unused.
  • Loading branch information
timhunt authored and danpoltawski committed Aug 12, 2014
1 parent 82b7d12 commit b483b31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/db/install.xml
Expand Up @@ -1405,6 +1405,7 @@
</KEYS>
<INDEXES>
<INDEX NAME="questionusageid-slot" UNIQUE="true" FIELDS="questionusageid, slot"/>
<INDEX NAME="behaviour" UNIQUE="false" FIELDS="behaviour" COMMENT="Required because we need to be able to determine efficiently which behaviours are in use."/>
</INDEXES>
</TABLE>
<TABLE NAME="question_attempt_steps" COMMENT="Stores one step in in a question attempt. As well as the data here, the step will have some data in the question_attempt_step_data table.">
Expand Down
15 changes: 15 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -3003,5 +3003,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013111804.03);
}

if ($oldversion < 2013111804.06) {

// Define index behaviour (not unique) to be added to question_attempts.
$table = new xmldb_table('question_attempts');
$index = new xmldb_index('behaviour', XMLDB_INDEX_NOTUNIQUE, array('behaviour'));

// Conditionally launch add index behaviour.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2013111804.06);
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

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

$version = 2013111804.05; // 20131118 = branching date YYYYMMDD - do not modify!
$version = 2013111804.06; // 20131118 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.

Expand Down

0 comments on commit b483b31

Please sign in to comment.