Skip to content

Commit

Permalink
Dev Add index to question_attributes table to improve EM query perfor…
Browse files Browse the repository at this point in the history
…mance

Dev Refactor another EM query to improve performance

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11213 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Oct 19, 2011
1 parent 2ef715e commit d42de5c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$config['versionnumber'] = "2.0alpha";
$config['dbversionnumber'] = 151;
$config['dbversionnumber'] = 152;
$config['buildnumber'] = '';

?>
5 changes: 5 additions & 0 deletions application/helpers/update/upgrade-all_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ function db_upgrade_all($oldversion) {
);
$CI->dbforge->add_column('groups',$fields);
}
if ($oldversion < 152)
{
$sql = "CREATE INDEX question_attributes_idx3 ON ".$CI->db->dbprefix('question_attributes')."(attribute)";
$CI->db->query($sql);
}
}

function upgrade_question_attributes148()
Expand Down
8 changes: 4 additions & 4 deletions application/models/answers_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ function insertRecords($data)
function getAllAnswersForEM($surveyid=NULL,$qid=NULL,$lang=NULL)
{
if (!is_null($qid)) {
$where = "qid = ".$qid;
$where = "a.qid = ".$qid;
}
else if (!is_null($surveyid)) {
$where = "qid in (select qid from ".$this->db->dbprefix('questions')." where sid = ".$surveyid.")";
$where = "a.qid = q.qid and q.sid = ".$surveyid;
}
else {
$where = "1";
Expand All @@ -116,8 +116,8 @@ function getAllAnswersForEM($surveyid=NULL,$qid=NULL,$lang=NULL)
$lang = " and language='".$lang."'";
}

$query = "SELECT qid, code, answer, scale_id"
." FROM ".$this->db->dbprefix('answers')
$query = "SELECT a.qid, a.code, a.answer, a.scale_id"
." FROM ".$this->db->dbprefix('answers')." AS a, ".$this->db->dbprefix('questions')." as q"
." WHERE ".$where
.$lang
." ORDER BY qid, scale_id, sortorder";
Expand Down
2 changes: 1 addition & 1 deletion application/models/question_attributes_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function getEMRelatedRecordsForSurvey($surveyid=NULL,$qid=NULL)
$query = "select distinct qid, attribute, value"
." from ".$this->db->dbprefix('question_attributes')
." where " . $where
." attribute in ('hidden')"
." attribute in ('hidden', 'array_filter', 'array_filter_exclude', 'code_filter', 'equals_num_value', 'exclude_all_others', 'exclude_all_others_auto', 'max_answers', 'max_num_value', 'max_num_value_n', 'max_num_value_sgqa', 'min_answers', 'min_num_value', 'min_num_value_n', 'min_num_value_sgqa', 'multiflexible_max', 'multiflexible_min', 'num_value_equals_sgqa', 'show_totals')"
." order by qid, attribute";

$data = $this->db->query($query);
Expand Down
3 changes: 2 additions & 1 deletion installer/sql/create-mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ create index [conditions_idx2] on [prefix_conditions] ([qid]);
create index [conditions_idx3] on [prefix_conditions] ([cqid]);
create index [groups_idx2] on [prefix_groups] ([sid]);
create index [question_attributes_idx2] on [prefix_question_attributes] ([qid]);
create index [question_attributes_idx3] on [prefix_question_attributes] ([attribute]);
create index [questions_idx2] on [prefix_questions] ([sid]);
create index [questions_idx3] on [prefix_questions] ([gid]);
create index [questions_idx4] on [prefix_questions] ([type]);
Expand All @@ -530,6 +531,6 @@ create index [parent_qid_idx] on [prefix_questions] ([parent_qid]);
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '151');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '152');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');

3 changes: 2 additions & 1 deletion installer/sql/create-mssqlnative.sql
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ create index [conditions_idx2] on [prefix_conditions] ([qid]);
create index [conditions_idx3] on [prefix_conditions] ([cqid]);
create index [groups_idx2] on [prefix_groups] ([sid]);
create index [question_attributes_idx2] on [prefix_question_attributes] ([qid]);
create index [question_attributes_idx3] on [prefix_question_attributes] ([attribute]);
create index [questions_idx2] on [prefix_questions] ([sid]);
create index [questions_idx3] on [prefix_questions] ([gid]);
create index [questions_idx4] on [prefix_questions] ([type]);
Expand All @@ -546,6 +547,6 @@ create index [parent_qid_idx] on [prefix_questions] ([parent_qid]);
--
-- Version Info
--
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '151');
INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '152');
INSERT INTO [prefix_settings_global] VALUES ('SessionName', '$sessionname');

3 changes: 2 additions & 1 deletion installer/sql/create-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ create index `conditions_idx2` on `prefix_conditions` (`qid`);
create index `conditions_idx3` on `prefix_conditions` (`cqid`);
create index `groups_idx2` on `prefix_groups` (`sid`);
create index `question_attributes_idx2` on `prefix_question_attributes` (`qid`);
create index `question_attributes_idx3` on `prefix_question_attributes` (`attribute`);
create index `questions_idx2` on `prefix_questions` (`sid`);
create index `questions_idx3` on `prefix_questions` (`gid`);
create index `questions_idx4` on `prefix_questions` (`type`);
Expand All @@ -517,6 +518,6 @@ create index `parent_qid_idx` on `prefix_questions` (`parent_qid`);
--
-- Version Info
--
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '151');
INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '152');
INSERT INTO `prefix_settings_global` VALUES ('SessionName', '$sessionname');

3 changes: 2 additions & 1 deletion installer/sql/create-postgre.sql
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ create index assessments_idx3 on prefix_assessments (gid);
create index conditions_idx2 on prefix_conditions (qid);
create index groups_idx2 on prefix_groups (sid);
create index question_attributes_idx2 on prefix_question_attributes (qid);
create index question_attributes_idx3 on prefix_question_attributes (attribute);
create index questions_idx2 on prefix_questions (sid);
create index questions_idx3 on prefix_questions (gid);
create index quota_idx2 on prefix_quota (sid);
Expand All @@ -528,6 +529,6 @@ create index parent_qid_idx on prefix_questions (parent_qid);
--
-- Version Info
--
INSERT INTO prefix_settings_global VALUES ('DBVersion', '151');
INSERT INTO prefix_settings_global VALUES ('DBVersion', '152');
INSERT INTO prefix_settings_global VALUES ('SessionName', '$sessionname');

0 comments on commit d42de5c

Please sign in to comment.