From b483b31dab915d19dc8956e1909d2caebc31cf52 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 8 Aug 2014 13:56:23 +0100 Subject: [PATCH] MDL-45642 questions: add required index to question_attempts. 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. --- lib/db/install.xml | 1 + lib/db/upgrade.php | 15 +++++++++++++++ version.php | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 5ead98106bd..7ff1936c781 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1405,6 +1405,7 @@ + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index dbc25dcc614..34b99de8cea 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/version.php b/version.php index b4713f323ca..188226333ce 100644 --- a/version.php +++ b/version.php @@ -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.