]> git.mjollnir.org Git - moodle.git/commitdiff
Improved indexing for improved performance on the course page, when viewing
authormoodler <moodler>
Mon, 28 Jul 2003 02:51:56 +0000 (02:51 +0000)
committermoodler <moodler>
Mon, 28 Jul 2003 02:51:56 +0000 (02:51 +0000)
logs and when viewing lists of users ... thanks to Eloy for the one on the log file.

lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
version.php

index 8375a66b9d9422d6034b3758d43646f912083470..7ad20d9af29fba550dceddb517a4a162d6489239 100644 (file)
@@ -405,6 +405,13 @@ function main_upgrade($oldversion=0) {
         table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
     }
 
+    if ($oldversion < 2003072800) {
+        print_simple_box("The following database index improves performance, but can be quite large - if you are upgrading and you have problems with a limited quota you may want to delete this index later from the '{$CFG->prefix}log' table in your database", "center", "50%", "$THEME->cellheading", "20", "noticebox");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX timecoursemoduleaction (time,course,module,action) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}user_students` ADD INDEX courseuserid (course,userid) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
+    }
+
     return $result;
 
 }
index f3b0c9b91bd818759b7758a7406c214dbb00352d..ece942f6f2b0e81289b0c545fb3673c47f6872f2 100644 (file)
@@ -131,6 +131,7 @@ CREATE TABLE `prefix_log` (
   `url` varchar(100) NOT NULL default '',
   `info` varchar(255) NOT NULL default '',
   PRIMARY KEY  (`id`),
+  KEY `timecoursemoduleaction` (time,course,module,action),
   KEY `coursemoduleaction` (course,module,action),
   KEY `courseuserid` (course,userid)
 ) TYPE=MyISAM COMMENT='Every action is logged as far as possible.';
@@ -233,7 +234,8 @@ CREATE TABLE `prefix_user_students` (
   `timeend` int(10) unsigned NOT NULL default '0',
   `time` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
-  UNIQUE KEY `id` (`id`)
+  UNIQUE KEY `id` (`id`),
+  KEY `courseuserid` (course,userid)
 ) TYPE=MyISAM;
 # --------------------------------------------------------
 
@@ -248,7 +250,8 @@ CREATE TABLE `prefix_user_teachers` (
   `authority` int(10) NOT NULL default '3',
   `role` varchar(40) NOT NULL default '',
   PRIMARY KEY  (`id`),
-  UNIQUE KEY `id` (`id`)
+  UNIQUE KEY `id` (`id`),
+  KEY `courseuserid` (course,userid)
 ) TYPE=MyISAM COMMENT='One record per teacher per course';
 
 #
index 573f26a6c1e14e5bf8faf1da649e8ff5184dc4c3..9d7afae0164a4494ee89e80eac109507f25e1174 100644 (file)
@@ -176,6 +176,13 @@ function main_upgrade($oldversion=0) {
         table_column("course_sections", "sequence", "sequence", "text", "", "", "", "", "");
     }
 
+    if ($oldversion < 2003072800) {
+        print_simple_box("The following database index improves performance, but can be quite large - if you are upgrading and you have problems with a limited quota you may want to delete this index later from the '{$CFG->prefix}log' table in your database", "center", "50%", "$THEME->cellheading", "20", "noticebox");
+        execute_sql(" CREATE INDEX {$CFG->prefix}log_timecoursemoduleaction_idx ON {$CFG->prefix}log (time,course,module,action) ");
+        execute_sql(" CREATE INDEX {$CFG->prefix}user_students_courseuserid_idx ON {$CFG->prefix}user_students (course,userid) ");
+        execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
+    }
+
     return $result;
 }
 ?>    
index 2cdc2c914b9ef3dd0ac13238c58a726aa3f4f78c..4f689cd567b98585f3d0f3f4e6ca7d7c55193d95 100644 (file)
@@ -76,7 +76,7 @@ CREATE TABLE prefix_log (
 );
 
 CREATE INDEX prefix_log_coursemoduleaction_idx ON prefix_log (course,module,action);
-
+CREATE INDEX prefix_log_timecoursemoduleaction_idx ON prefix_log (time,course,module,action);
 CREATE INDEX prefix_log_courseuserid_idx ON prefix_log (course,userid);
 
 CREATE TABLE prefix_log_display (
@@ -147,6 +147,8 @@ CREATE TABLE prefix_user_students (
    time integer NOT NULL default '0'
 );
 
+CREATE INDEX prefix_user_students_courseuserid_idx ON prefix_user_students (course,userid);
+
 CREATE TABLE prefix_user_teachers (
    id SERIAL PRIMARY KEY,
    userid integer NOT NULL default '0',
@@ -155,7 +157,9 @@ CREATE TABLE prefix_user_teachers (
    role varchar(40) NOT NULL default ''
 );
 
-CREATE TABLE mdl_user_coursecreators (
+CREATE INDEX prefix_user_teachers_courseuserid_idx ON prefix_user_teachers (course,userid);
+
+CREATE TABLE prefix_user_coursecreators (
    id SERIAL8 PRIMARY KEY,
    userid int8  NOT NULL default '0'
 );
index 30a3099e8e098b8e4c7cecf7f010642263403ba6..abe5209d524444f96c5d14fe864a54fedf6bdddd 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2003072101;   // The current version is a date (YYYYMMDDXX)
+$version = 2003072800;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.1 development";  // User-friendly version number