Permalink
Browse files

Add a unique key to guarantee that course,sortorder is unique. Allows…

… fix_course_sortorder and ordering operations to be much faster. (martinlanghoff)

arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-231
arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-236
  • Loading branch information...
1 parent bd2c259 commit 3ebf865805d7c69b95df470599acbf2b7b4be435 mjollnir_ committed Nov 17, 2004
Showing with 54 additions and 4 deletions.
  1. +18 −1 lib/db/mysql.php
  2. +10 −2 lib/db/mysql.sql
  3. +17 −0 lib/db/postgres7.php
  4. +9 −1 lib/db/postgres7.sql
View
@@ -883,9 +883,26 @@ function main_upgrade($oldversion=0) {
modify_database('','ALTER TABLE prefix_user_admins ADD INDEX userid (userid);');
modify_database('','ALTER TABLE prefix_user_coursecreators ADD INDEX userid (userid);');
}
+
+ if ($oldversion < 2004083128) { // replace index on course
+ fix_course_sortorder(0,0,1);
+ modify_database('', "ALTER TABLE `prefix_course` DROP KEY category");
+ modify_database('', "ALTER TABLE `prefix_course` ADD UNIQUE KEY category_sortorder(category,sortorder)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_deleted_idx (deleted)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_confirmed_idx (confirmed)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_firstname_idx (firstname)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_lastname_idx (lastname)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_city_idx (city)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_country_idx (country)");
+ modify_database("", "ALTER TABLE `prefix_user` ADD INDEX prefix_user_lastaccess_idx (lastaccess)");
+ }
+
+ if ($oldversion < 2004083128) { // one more index for email (for sorting)
+ modify_database('','ALTER TABLE `prefix_user` ADD INDEX prefix_user_email_idx (email);');
+ }
return $result;
-
+
}
?>
View
@@ -61,7 +61,7 @@ CREATE TABLE `prefix_course` (
`timecreated` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
- KEY `category` (`category`),
+ UNIQUE KEY `category_sortorder` (`category`, `sortorder`),
KEY `idnumber` (`idnumber`),
KEY `shortname` (`shortname`)
) TYPE=MyISAM;
@@ -358,7 +358,15 @@ CREATE TABLE `prefix_user` (
UNIQUE KEY `id` (`id`),
UNIQUE KEY `username` (`username`),
KEY `user_idnumber` (`idnumber`),
- KEY `user_auth` (`auth`)
+ KEY `user_auth` (`auth`),
+ KEY `user_deleted` (`deleted`),
+ KEY `user_confirmed` (`confirmed`),
+ KEY `user_firstname` (`firstname`),
+ KEY `user_lastname` (`lastname`),
+ KEY `user_city` (`city`),
+ KEY `user_country` (`country`),
+ KEY `user_lastaccess` (`lastaccess`),
+ KEY `user_email` (`email`)
) TYPE=MyISAM COMMENT='One record for each person';
# --------------------------------------------------------
View
@@ -619,6 +619,23 @@ function main_upgrade($oldversion=0) {
modify_database('','CREATE INDEX prefix_user_coursecreators_userid_idx ON prefix_user_coursecreators (userid);');
}
+ if ($oldversion < 2004083128) { // make new indexes on user table.
+ fix_course_sortorder(0,0,1);
+ modify_database('', "DROP INDEX prefix_course_category_idx;");
+ modify_database('', "CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course(category,sortorder)");
+ modify_database("","CREATE INDEX prefix_user_deleted_idx ON prefix_user (deleted)");
+ modify_database("","CREATE INDEX prefix_user_confirmed_idx ON prefix_user (confirmed)");
+ modify_database("","CREATE INDEX prefix_user_firstname_idx ON prefix_user (firstname)");
+ modify_database("","CREATE INDEX prefix_user_lastname_idx ON prefix_user (lastname)");
+ modify_database("","CREATE INDEX prefix_user_city_idx ON prefix_user (city)");
+ modify_database("","CREATE INDEX prefix_user_country_idx ON prefix_user (country)");
+ modify_database("","CREATE INDEX prefix_user_lastaccess_idx ON prefix_user (lastaccess)");
+ }
+
+ if ($oldversion < 2004083128) { // one more index for email (for sorting)
+ modify_database('','CREATE INDEX prefix_user_email_idx ON prefix_user (email);');
+ }
+
return $result;
}
View
@@ -40,7 +40,7 @@ CREATE TABLE prefix_course (
timemodified integer NOT NULL default '0'
);
-CREATE INDEX prefix_course_category_idx ON prefix_course (category);
+CREATE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);
CREATE INDEX prefix_course_idnumber_idx ON prefix_course (idnumber);
CREATE INDEX prefix_course_shortname_idx ON prefix_course (shortname);
@@ -254,6 +254,14 @@ CREATE TABLE prefix_user (
CREATE INDEX prefix_user_idnumber_idx ON prefix_user (idnumber);
CREATE INDEX prefix_user_auth_idx ON prefix_user (auth);
+CREATE INDEX prefix_user_deleted_idx ON prefix_user (deleted);
+CREATE INDEX prefix_user_confirmed_idx ON prefix_user (confirmed);
+CREATE INDEX prefix_user_firstname_idx ON prefix_user (firstname);
+CREATE INDEX prefix_user_lastname_idx ON prefix_user (lastname);
+CREATE INDEX prefix_user_city_idx ON prefix_user (city);
+CREATE INDEX prefix_user_country_idx ON prefix_user (country);
+CREATE INDEX prefix_user_lastaccess_idx ON prefix_user (lastaccess);
+CREATE INDEX prefix_user_email_idx ON prefix_user (email);
CREATE TABLE prefix_user_admins (
id SERIAL PRIMARY KEY,

0 comments on commit 3ebf865

Please sign in to comment.