Skip to content

Commit

Permalink
Added some new indexes on quiz tables in MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Mar 26, 2003
1 parent 264d4e0 commit 6eff984
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
12 changes: 12 additions & 0 deletions mod/quiz/db/mysql.php
Expand Up @@ -53,6 +53,18 @@ function quiz_upgrade($oldversion) {
if ($oldversion < 2003030303) {
table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image");
}
if ($oldversion < 2003032600) {
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_answers` ADD INDEX(question) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_attempts` ADD INDEX(quiz) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_attempts` ADD INDEX(userid) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(quiz) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(userid) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grade` ADD INDEX(quiz) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grade` ADD INDEX(question) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_randommatch` ADD INDEX(question) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(attempt) ");
execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(question) ");
}

return true;
}
Expand Down
23 changes: 16 additions & 7 deletions mod/quiz/db/mysql.sql
Expand Up @@ -44,8 +44,8 @@ CREATE TABLE `prefix_quiz_answers` (
`answer` varchar(255) NOT NULL default '',
`fraction` varchar(10) NOT NULL default '0.0',
`feedback` text NOT NULL,

PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Answers, with a fractional grade (0-1) and feedback';
# --------------------------------------------------------

Expand All @@ -62,7 +62,9 @@ CREATE TABLE `prefix_quiz_attempts` (
`timestart` int(10) unsigned NOT NULL default '0',
`timefinish` int(10) unsigned NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `quiz` (`quiz`),
KEY `userid` (`userid`)
) TYPE=MyISAM COMMENT='Stores various attempts on a quiz';
# --------------------------------------------------------

Expand Down Expand Up @@ -90,7 +92,9 @@ CREATE TABLE `prefix_quiz_grades` (
`userid` int(10) unsigned NOT NULL default '0',
`grade` varchar(10) NOT NULL default '0.0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `quiz` (`quiz`),
KEY `userid` (`userid`)
) TYPE=MyISAM COMMENT='Final quiz grade (may be best of several attempts)';
# --------------------------------------------------------

Expand Down Expand Up @@ -118,7 +122,9 @@ CREATE TABLE `prefix_quiz_question_grades` (
`quiz` int(10) unsigned NOT NULL default '0',
`question` int(10) unsigned NOT NULL default '0',
`grade` smallint(6) NOT NULL default '0',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `quiz` (`quiz`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='The grade for a question in a quiz';
# --------------------------------------------------------

Expand All @@ -130,7 +136,8 @@ CREATE TABLE `prefix_quiz_randommatch` (
`id` int(10) unsigned NOT NULL auto_increment,
`question` int(10) unsigned NOT NULL default '0',
`choose` INT UNSIGNED DEFAULT '4' NOT NULL,
PRIMARY KEY ( `id` )
PRIMARY KEY ( `id` ),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Info about a random matching question';

#
Expand Down Expand Up @@ -159,7 +166,9 @@ CREATE TABLE `prefix_quiz_responses` (
`question` int(10) unsigned NOT NULL default '0',
`answer` varchar(255) NOT NULL default '',
`grade` varchar(10) NOT NULL default '0.0',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `attempt` (`attempt`),
KEY `question` (`question`)
) TYPE=MyISAM COMMENT='Stores user responses to a quiz, and percentage grades';
# --------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/version.php
Expand Up @@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////

$module->version = 2003030303; // The (date) version of this module
$module->version = 2003032600; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
?>

0 comments on commit 6eff984

Please sign in to comment.