Skip to content
Browse files

Indexes on faux foreign keys and often used fields, one more set and …

…version bump to come.
  • Loading branch information...
1 parent 0ee95ca commit bd2c2596c2c205a915510cbbfec2a9d977dde158 mjollnir_ committed
Showing with 142 additions and 14 deletions.
  1. +41 −0 lib/db/mysql.php
  2. +30 −11 lib/db/mysql.sql
  3. +42 −1 lib/db/postgres7.php
  4. +29 −2 lib/db/postgres7.sql
View
41 lib/db/mysql.php
@@ -843,6 +843,47 @@ function main_upgrade($oldversion=0) {
execute_sql("UPDATE {$CFG->prefix}course SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
}
+ if ($oldversion < 2004083128) { // add indexes.
+ execute_sql(" ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_idnumber (idnumber) ");
+ execute_sql(" ALTER TABLE `{$CFG->prefix}user` ADD INDEX user_auth (auth) ");
+ }
+
+ if ($oldversion < 2004083128) { // add indexes.
+ execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX idnumber (idnumber) ");
+ execute_sql(" ALTER TABLE `{$CFG->prefix}course` ADD INDEX shortname (shortname) ");
+ execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX userid (userid) ");
+ execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX userid (userid) ");
+ }
+
+ if ($oldversion < 2004083128) {// add an index to event for timestart and timeduration
+ modify_database('','ALTER TABLE prefix_event ADD INDEX timestart (timestart);');
+ modify_database('','ALTER TABLE prefix_event ADD INDEX timeduration (timeduration);');
+ }
+
+ if ($oldversion < 2004083128) { //add indexes on modules and course_modules
+ modify_database('','ALTER TABLE prefix_course_modules add key visible(visible);');
+ modify_database('','ALTER TABLE prefix_course_modules add key course(course);');
+ modify_database('','ALTER TABLE prefix_course_modules add key module(module);');
+ modify_database('','ALTER TABLE prefix_course_modules add key instance (instance);');
+ modify_database('','ALTER TABLE prefix_course_modules add key deleted (deleted);');
+ modify_database('','ALTER TABLE prefix_modules add key name(name);');
+ }
+
+
+ if ($oldversion < 2004083128) { // add an index on the groups_members table
+ modify_database('','ALTER TABLE prefix_groups_members ADD INDEX userid (userid);');
+ }
+
+ if ($oldversion < 2004083128) { // add an index on user students timeaccess (used for sorting)
+ modify_database('','ALTER TABLE prefix_user_students ADD INDEX timeaccess (timeaccess);');
+ }
+
+ if ($oldversion < 2004083128) {
+ modify_database('','ALTER TABLE prefix_scale ADD INDEX courseid (courseid);');
+ modify_database('','ALTER TABLE prefix_user_admins ADD INDEX userid (userid);');
+ modify_database('','ALTER TABLE prefix_user_coursecreators ADD INDEX userid (userid);');
+ }
+
return $result;
}
View
41 lib/db/mysql.sql
@@ -61,7 +61,9 @@ 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`)
+ KEY `category` (`category`),
+ KEY `idnumber` (`idnumber`),
+ KEY `shortname` (`shortname`)
) TYPE=MyISAM;
# --------------------------------------------------------
@@ -117,7 +119,12 @@ CREATE TABLE `prefix_course_modules` (
`visible` tinyint(1) NOT NULL default '1',
`groupmode` tinyint(4) NOT NULL default '0',
PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`)
+ UNIQUE KEY `id` (`id`),
+ KEY `visible` (`visible`),
+ KEY `course` (`course`),
+ KEY `module` (`module`),
+ KEY `instance` (`instance`),
+ KEY `deleted` (`deleted`)
) TYPE=MyISAM;
# --------------------------------------------------------
@@ -159,7 +166,9 @@ CREATE TABLE `prefix_event` (
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `courseid` (`courseid`),
- KEY `userid` (`userid`)
+ KEY `userid` (`userid`),
+ KEY `timestart` (`timestart`),
+ KEY `timeduration` (`timeduration`)
) TYPE=MyISAM COMMENT='For everything with a time associated to it';
# --------------------------------------------------------
@@ -227,7 +236,8 @@ CREATE TABLE `prefix_groups_members` (
`timeadded` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
- KEY `groupid` (`groupid`)
+ KEY `groupid` (`groupid`),
+ KEY `userid` (`userid`)
) TYPE=MyISAM COMMENT='Lists memberships of users to groups';
# --------------------------------------------------------
@@ -279,7 +289,8 @@ CREATE TABLE `prefix_modules` (
`search` varchar(255) NOT NULL default '',
`visible` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`)
+ UNIQUE KEY `id` (`id`),
+ KEY `name` (`name`)
) TYPE=MyISAM;
# --------------------------------------------------------
@@ -296,7 +307,8 @@ CREATE TABLE `prefix_scale` (
`scale` text NOT NULL,
`description` text NOT NULL,
`timemodified` int(10) unsigned NOT NULL default '0',
- PRIMARY KEY (id)
+ PRIMARY KEY (id),
+ KEY `courseid` (`courseid`)
) TYPE=MyISAM COMMENT='Defines grading scales';
# --------------------------------------------------------
@@ -344,7 +356,9 @@ CREATE TABLE `prefix_user` (
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
- UNIQUE KEY `username` (`username`)
+ UNIQUE KEY `username` (`username`),
+ KEY `user_idnumber` (`idnumber`),
+ KEY `user_auth` (`auth`)
) TYPE=MyISAM COMMENT='One record for each person';
# --------------------------------------------------------
@@ -356,7 +370,8 @@ CREATE TABLE `prefix_user_admins` (
`id` int(10) unsigned NOT NULL auto_increment,
`userid` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`)
+ UNIQUE KEY `id` (`id`),
+ KEY `userid` (`userid`)
) TYPE=MyISAM COMMENT='One record per administrator user';
# --------------------------------------------------------
@@ -393,7 +408,9 @@ CREATE TABLE `prefix_user_students` (
`timeaccess` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
- KEY `courseuserid` (course,userid)
+ KEY `courseuserid` (course,userid),
+ KEY `userid` (userid),
+ KEY `timeaccess` (timeaccess)
) TYPE=MyISAM;
# --------------------------------------------------------
@@ -414,7 +431,8 @@ CREATE TABLE `prefix_user_teachers` (
`timeaccess` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
- KEY `courseuserid` (course,userid)
+ KEY `courseuserid` (course,userid),
+ KEY `userid` (userid)
) TYPE=MyISAM COMMENT='One record per teacher per course';
#
@@ -425,7 +443,8 @@ CREATE TABLE `prefix_user_coursecreators` (
`id` int(10) unsigned NOT NULL auto_increment,
`userid` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`)
+ UNIQUE KEY `id` (`id`),
+ KEY `userid` (`userid`)
) TYPE=MyISAM COMMENT='One record per course creator';
INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname," ",lastname)');
View
43 lib/db/postgres7.php
@@ -577,8 +577,49 @@ function main_upgrade($oldversion=0) {
execute_sql("UPDATE {$CFG->prefix}course SET lang = 'mi_nt' WHERE lang = 'ma_nt'");
}
- return $result;
+ if ($oldversion < 2004083128) { // add indexes.
+ modify_database("", "CREATE INDEX prefix_user_idnumber_idx ON prefix_user (idnumber);");
+ modify_database("", "CREATE INDEX prefix_user_auth_idx ON prefix_user (auth);");
+ }
+
+ if ($oldversion < 2004083128) { // add indexes
+ modify_database("","CREATE INDEX {$CFG->prefix}course_idnumber_idx ON {$CFG->prefix}course (idnumber);" );
+ modify_database("","CREATE INDEX {$CFG->prefix}course_shortname_idx ON {$CFG->prefix}course (shortname);" );
+ modify_database("","CREATE INDEX {$CFG->prefix}user_students_userid_idx ON {$CFG->prefix}user_students (userid);");
+ modify_database("","CREATE INDEX {$CFG->prefix}user_teachers_userid_idx ON {$CFG->prefix}user_teachers (userid);");
+ }
+
+ if ($oldversion < 2004083128) { // add an index to event for timestart and timeduration
+ modify_database('','CREATE INDEX prefix_event_timestart_idx ON prefix_event (timestart);');
+ modify_database('','CREATE INDEX prefix_event_timeduration_idx ON prefix_event (timeduration);');
+ }
+
+ if ($oldversion < 2004083128) { //add indexes on modules and course_modules
+ modify_database('','CREATE INDEX prefix_course_modules_visible_idx ON prefix_course_modules (visible);');
+ modify_database('','CREATE INDEX prefix_course_modules_course_idx ON prefix_course_modules (course);');
+ modify_database('','CREATE INDEX prefix_course_modules_module_idx ON prefix_course_modules (module);');
+ modify_database('','CREATE INDEX prefix_course_modules_instance_idx ON prefix_course_modules (instance);');
+ modify_database('','CREATE INDEX prefix_course_modules_deleted_idx ON prefix_course_modules (deleted);');
+ modify_database('','CREATE INDEX prefix_modules_name_idx ON prefix_modules (name);');
+ }
+ if ($oldversion < 2004083128) { // add an index on the groups_members table
+ modify_database('','CREATE INDEX prefix_groups_members_userid_idx ON prefix_groups_members (userid);');
+ }
+
+
+ if ($oldversion < 2004083128) { // add an index on user students timeaccess (used for sorting)
+ modify_database('','CREATE INDEX prefix_user_students_timeaccess_idx ON prefix_user_students (timeaccess);');
+ }
+
+ if ($oldversion < 2004083128) {
+ modify_database('','CREATE INDEX prefix_course_sections_coursesection_idx ON prefix_course_sections (course,section);');
+ modify_database('','CREATE INDEX prefix_scale_courseid_idx ON prefix_scale (courseid);');
+ modify_database('','CREATE INDEX prefix_user_admins_userid_idx ON prefix_user_admins (userid);');
+ modify_database('','CREATE INDEX prefix_user_coursecreators_userid_idx ON prefix_user_coursecreators (userid);');
+ }
+
+ return $result;
}
?>
View
31 lib/db/postgres7.sql
@@ -41,6 +41,8 @@ CREATE TABLE prefix_course (
);
CREATE INDEX prefix_course_category_idx ON prefix_course (category);
+CREATE INDEX prefix_course_idnumber_idx ON prefix_course (idnumber);
+CREATE INDEX prefix_course_shortname_idx ON prefix_course (shortname);
CREATE TABLE prefix_course_categories (
id SERIAL PRIMARY KEY,
@@ -76,6 +78,12 @@ CREATE TABLE prefix_course_modules (
groupmode integer NOT NULL default '0'
);
+CREATE INDEX prefix_course_modules_visible_idx ON prefix_course_modules (visible);
+CREATE INDEX prefix_course_modules_course_idx ON prefix_course_modules (course);
+CREATE INDEX prefix_course_modules_module_idx ON prefix_course_modules (module);
+CREATE INDEX prefix_course_modules_instance_idx ON prefix_course_modules (instance);
+CREATE INDEX prefix_course_modules_deleted_idx ON prefix_course_modules (deleted);
+
CREATE TABLE prefix_course_sections (
id SERIAL PRIMARY KEY,
course integer NOT NULL default '0',
@@ -85,6 +93,8 @@ CREATE TABLE prefix_course_sections (
visible integer NOT NULL default '1'
);
+CREATE INDEX prefix_course_sections_coursesection_idx ON prefix_course_sections (course,section);
+
CREATE TABLE prefix_event (
id SERIAL PRIMARY KEY,
name varchar(255) NOT NULL default '',
@@ -104,6 +114,8 @@ CREATE TABLE prefix_event (
CREATE INDEX prefix_event_courseid_idx ON prefix_event (courseid);
CREATE INDEX prefix_event_userid_idx ON prefix_event (userid);
+CREATE INDEX prefix_event_timestart_idx ON prefix_event (timestart);
+CREATE INDEX prefix_event_timeduration_idx ON prefix_event (timeduration);
CREATE TABLE prefix_groups (
id SERIAL PRIMARY KEY,
@@ -127,6 +139,7 @@ CREATE TABLE prefix_groups_members (
);
CREATE INDEX prefix_groups_members_idx ON prefix_groups_members (groupid);
+CREATE INDEX prefix_groups_members_userid_idx ON prefix_groups_members (userid);
CREATE TABLE prefix_log (
id SERIAL PRIMARY KEY,
@@ -162,6 +175,8 @@ CREATE TABLE prefix_modules (
visible integer NOT NULL default '1'
);
+CREATE INDEX prefix_modules_name_idx ON prefix_modules (name);
+
CREATE TABLE prefix_scale (
id SERIAL PRIMARY KEY,
courseid integer NOT NULL default '0',
@@ -172,6 +187,8 @@ CREATE TABLE prefix_scale (
timemodified integer NOT NULL default '0'
);
+CREATE INDEX prefix_scale_courseid_idx ON prefix_scale (courseid);
+
CREATE TABLE prefix_cache_filters (
id SERIAL PRIMARY KEY,
@@ -235,11 +252,16 @@ CREATE TABLE prefix_user (
CONSTRAINT prefix_user_username_uk UNIQUE (username)
);
+CREATE INDEX prefix_user_idnumber_idx ON prefix_user (idnumber);
+CREATE INDEX prefix_user_auth_idx ON prefix_user (auth);
+
CREATE TABLE prefix_user_admins (
id SERIAL PRIMARY KEY,
userid integer NOT NULL default '0'
);
+CREATE INDEX prefix_user_admins_userid_idx ON prefix_user_admins (userid);
+
CREATE TABLE prefix_user_preferences (
id SERIAL PRIMARY KEY,
userid integer NOT NULL default '0',
@@ -260,6 +282,8 @@ CREATE TABLE prefix_user_students (
);
CREATE INDEX prefix_user_students_courseuserid_idx ON prefix_user_students (course,userid);
+CREATE INDEX prefix_user_students_userid_idx ON prefix_user_students (userid);
+CREATE INDEX prefix_user_students_timeaccess_idx ON prefix_user_students (timeaccess);
CREATE TABLE prefix_user_teachers (
id SERIAL PRIMARY KEY,
@@ -275,14 +299,17 @@ CREATE TABLE prefix_user_teachers (
);
CREATE INDEX prefix_user_teachers_courseuserid_idx ON prefix_user_teachers (course,userid);
+CREATE INDEX prefix_user_teachers_userid_idx ON prefix_user_teachers (userid);
CREATE TABLE prefix_user_coursecreators (
id SERIAL8 PRIMARY KEY,
userid int8 NOT NULL default '0'
);
-INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname," ",lastname)');
-INSERT INTO prefix_log_display VALUES ('course', 'user report', 'user', 'CONCAT(firstname," ",lastname)');
+CREATE INDEX prefix_user_coursecreators_userid_idx ON prefix_user_coursecreators (userid);
+
+INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'firstname||\' \'||lastname');
+INSERT INTO prefix_log_display VALUES ('course', 'user report', 'user', 'firstname||\' \'||lastname');
INSERT INTO prefix_log_display VALUES ('course', 'view', 'course', 'fullname');
INSERT INTO prefix_log_display VALUES ('course', 'update', 'course', 'fullname');
INSERT INTO prefix_log_display VALUES ('course', 'enrol', 'course', 'fullname');

0 comments on commit bd2c259

Please sign in to comment.
Something went wrong with that request. Please try again.