From 4a039315d787de63a4450af7fc6ea64b7d4bada2 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 6 Sep 2007 18:31:13 +0000 Subject: [PATCH] Dropping one UNIQUE index over NULLable columns. It isn't cross-db at all. So we make the composite index not unique to get speed benefits but the unique constraint is controlled programatically. --- lib/db/install.xml | 9 +++++---- lib/db/upgrade.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/db/install.xml b/lib/db/install.xml index 341b3e41f14..8d86b55b6a2 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -156,8 +156,8 @@ - - + + @@ -1344,7 +1344,8 @@ - + +
diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 20a7b0e9cf9..d550837eb59 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2034,6 +2034,35 @@ function xmldb_main_upgrade($oldversion=0) { } } +/// To have UNIQUE indexes over NULLable columns isn't cross-db at all +/// so we create a non unique index and programatically enforce uniqueness + if ($result && $oldversion < 2007090600) { + + /// Define index idnumber (unique) to be dropped form course_modules + $table = new XMLDBTable('course_modules'); + $index = new XMLDBIndex('idnumber'); + $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber')); + + /// Launch drop index idnumber + $result = $result && drop_index($table, $index); + + /// Define index idnumber-course (not unique) to be added to course_modules + $table = new XMLDBTable('course_modules'); + $index = new XMLDBIndex('idnumber-course'); + $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course')); + + /// Launch add index idnumber-course + $result = $result && add_index($table, $index); + + /// Define index idnumber-courseid (not unique) to be added to grade_items + $table = new XMLDBTable('grade_items'); + $index = new XMLDBIndex('idnumber-courseid'); + $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'courseid')); + + /// Launch add index idnumber-courseid + $result = $result && add_index($table, $index); + + } /*