Merged from MOODLE_14_STABLE: Indexes on forum and version bump

This commit is contained in:
mjollnir_ 2004-11-18 04:10:47 +00:00
parent 1734f08ea4
commit d21e88a938
5 changed files with 102 additions and 7 deletions

View File

@ -130,9 +130,37 @@ function forum_upgrade($oldversion) {
if ($oldversion < 2004070700) { // This may be redoing it from STABLE but that's OK
table_column("forum_discussions", "groupid", "groupid", "integer", "10", "", "0", "");
}
if ($oldversion < 2004111700) {
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_parent_idx;",false);
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_discussion_idx;",false);
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` DROP INDEX {$CFG->prefix}forum_posts_userid_idx;",false);
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_forum_idx;",false);
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` DROP INDEX {$CFG->prefix}forum_discussions_userid_idx;",false);
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_parent_idx (parent) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_discussion_idx (discussion) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_posts` ADD INDEX {$CFG->prefix}forum_posts_userid_idx (userid) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_forum_idx (forum) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}forum_discussions` ADD INDEX {$CFG->prefix}forum_discussions_userid_idx (userid) ");
}
if ($oldversion < 2004111700) {
execute_sql("ALTER TABLE {$CFG->prefix}forum DROP INDEX course;",false);
execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX userid;",false);
execute_sql("ALTER TABLE {$CFG->prefix}forum_ratings DROP INDEX post;",false);
execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX userid;",false);
execute_sql("ALTER TABLE {$CFG->prefix}forum_subscriptions DROP INDEX forum;",false);
modify_database('','ALTER TABLE prefix_forum ADD INDEX course (course);');
modify_database('','ALTER TABLE prefix_forum_ratings ADD INDEX userid (userid);');
modify_database('','ALTER TABLE prefix_forum_ratings ADD INDEX post (post);');
modify_database('','ALTER TABLE prefix_forum_subscriptions ADD INDEX userid (userid);');
modify_database('','ALTER TABLE prefix_forum_subscriptions ADD INDEX forum (forum);');
}
return true;
}

View File

@ -20,7 +20,8 @@ CREATE TABLE prefix_forum (
rssarticles tinyint(2) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
UNIQUE KEY id (id),
KEY course (course)
) COMMENT='Forums contain and structure discussion';
# --------------------------------------------------------
@ -39,7 +40,9 @@ CREATE TABLE prefix_forum_discussions (
assessed tinyint(1) NOT NULL default '1',
timemodified int(10) unsigned NOT NULL default '0',
usermodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id)
PRIMARY KEY (id),
KEY prefix_forum_discussions_forum_idx (forum),
KEY prefix_forum_discussions_userid_idx (userid)
) COMMENT='Forums are composed of discussions';
# --------------------------------------------------------
@ -60,7 +63,10 @@ CREATE TABLE prefix_forum_posts (
format tinyint(2) NOT NULL default '0',
attachment VARCHAR(100) NOT NULL default '',
totalscore tinyint(4) NOT NULL default '0',
PRIMARY KEY (id)
PRIMARY KEY (id),
KEY prefix_forum_posts_parent_idx (parent),
KEY prefix_forum_posts_discussion_idx (discussion),
KEY prefix_forum_posts_userid_idx (userid)
) COMMENT='All posts are stored in this table';
# --------------------------------------------------------
@ -89,7 +95,9 @@ CREATE TABLE prefix_forum_ratings (
post int(10) unsigned NOT NULL default '0',
time int(10) unsigned NOT NULL default '0',
rating tinyint(4) NOT NULL default '0',
PRIMARY KEY (id)
PRIMARY KEY (id),
KEY userid (userid),
KEY post (post)
) COMMENT='Contains user ratings for individual posts';
# --------------------------------------------------------
@ -102,7 +110,9 @@ CREATE TABLE prefix_forum_subscriptions (
userid int(10) unsigned NOT NULL default '0',
forum int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
UNIQUE KEY id (id)
UNIQUE KEY id (id),
KEY userid (userid),
KEY forum (forum)
) COMMENT='Keeps track of who is subscribed to what forum';
# --------------------------------------------------------

View File

@ -67,6 +67,40 @@ function forum_upgrade($oldversion) {
}
if ($oldversion < 2004111700) {
execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_parent_idx;",false);
execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_discussion_idx;",false);
execute_sql(" DROP INDEX {$CFG->prefix}forum_posts_userid_idx;",false);
execute_sql(" DROP INDEX {$CFG->prefix}forum_discussions_forum_idx;",false);
execute_sql(" DROP INDEX {$CFG->prefix}forum_discussions_userid_idx;",false);
execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_parent_idx ON {$CFG->prefix}forum_posts (parent) ");
execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_discussion_idx ON {$CFG->prefix}forum_posts (discussion) ");
execute_sql(" CREATE INDEX {$CFG->prefix}forum_posts_userid_idx ON {$CFG->prefix}forum_posts (userid) ");
execute_sql(" CREATE INDEX {$CFG->prefix}forum_discussions_forum_idx ON {$CFG->prefix}forum_discussions (forum) ");
execute_sql(" CREATE INDEX {$CFG->prefix}forum_discussions_userid_idx ON {$CFG->prefix}forum_discussions (userid) ");
}
if ($oldversion < 2004111200) {
execute_sql("DROP INDEX {$CFG->prefix}forum_course_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_queue_userid_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_queue_discussion_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_queue_postid_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_ratings_userid_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_ratings_post_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_subscriptions_userid_idx;",false);
execute_sql("DROP INDEX {$CFG->prefix}forum_subscriptions_forum_idx;",false);
modify_database('','CREATE INDEX prefix_forum_course_idx ON prefix_forum (course);');
modify_database('','CREATE INDEX prefix_forum_queue_userid_idx ON prefix_forum_queue (userid);');
modify_database('','CREATE INDEX prefix_forum_queue_discussion_idx ON prefix_forum_queue (discussionid);');
modify_database('','CREATE INDEX prefix_forum_queue_postid_idx ON prefix_forum_queue (postid);');
modify_database('','CREATE INDEX prefix_forum_ratings_userid_idx ON prefix_forum_ratings (userid);');
modify_database('','CREATE INDEX prefix_forum_ratings_post_idx ON prefix_forum_ratings (post);');
modify_database('','CREATE INDEX prefix_forum_subscriptions_userid_idx ON prefix_forum_subscriptions (userid);');
modify_database('','CREATE INDEX prefix_forum_subscriptions_forum_idx ON prefix_forum_subscriptions (forum);');
}
return true;
}

View File

@ -20,6 +20,8 @@ CREATE TABLE prefix_forum (
rssarticles integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
);
CREATE INDEX prefix_forum_course_idx ON prefix_forum (course);
# --------------------------------------------------------
#
@ -38,6 +40,10 @@ CREATE TABLE prefix_forum_discussions (
timemodified integer NOT NULL default '0',
usermodified integer NOT NULL default '0'
);
CREATE INDEX prefix_forum_discussions_forum_idx ON prefix_forum_discussions (forum);
CREATE INDEX prefix_forum_discussions_userid_idx ON prefix_forum_discussions (userid);
# --------------------------------------------------------
#
@ -58,6 +64,12 @@ CREATE TABLE prefix_forum_posts (
attachment VARCHAR(100) NOT NULL default '',
totalscore integer NOT NULL default '0'
);
CREATE INDEX prefix_forum_posts_discussion_idx ON prefix_forum_posts (discussion);
CREATE INDEX prefix_forum_posts_parent_idx ON prefix_forum_posts (parent);
CREATE INDEX prefix_forum_posts_userid_idx ON prefix_forum_posts (userid);
# --------------------------------------------------------
#
@ -71,6 +83,9 @@ CREATE TABLE prefix_forum_queue (
postid integer default 0 NOT NULL
);
CREATE INDEX prefix_forum_queue_userid_idx ON prefix_forum_queue (userid);
CREATE INDEX prefix_forum_queue_discussion_idx ON prefix_forum_queue (discussionid);
CREATE INDEX prefix_forum_queue_postid_idx ON prefix_forum_queue (postid);
# --------------------------------------------------------
@ -85,6 +100,10 @@ CREATE TABLE prefix_forum_ratings (
time integer NOT NULL default '0',
rating integer NOT NULL default '0'
);
CREATE INDEX prefix_forum_ratings_userid_idx ON prefix_forum_ratings (userid);
CREATE INDEX prefix_forum_ratings_post_idx ON prefix_forum_ratings (post);
# --------------------------------------------------------
#
@ -96,6 +115,10 @@ CREATE TABLE prefix_forum_subscriptions (
userid integer NOT NULL default '0',
forum integer NOT NULL default '0'
);
CREATE INDEX prefix_forum_subscriptions_userid_idx ON prefix_forum_subscriptions (userid);
CREATE INDEX prefix_forum_subscriptions_forum_idx ON prefix_forum_subscriptions (forum);
# --------------------------------------------------------
#

View File

@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2004091700;
$module->version = 2004111700;
$module->requires = 2004091700; // Requires this Moodle version
$module->cron = 60;