1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-17 07:10:48 +03:00

небольшая оптимизация индексов БД

This commit is contained in:
Mzhelskiy Maxim 2010-04-04 14:58:11 +00:00
parent bbe4242654
commit a07df8dfe2
5 changed files with 64 additions and 18 deletions

View file

@ -75,12 +75,12 @@ class Mapper_Talk extends Mapper {
FROM
".Config::Get('db.table.talk_user')." as t
WHERE
t.user_id = ?d
t.talk_id IN(?a)
AND
t.talk_id IN(?a)
t.user_id = ?d
";
$aTalkUsers=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
if ($aRows=$this->oDb->select($sql,$aArrayId,$sUserId)) {
foreach ($aRows as $aRow) {
$aTalkUsers[]=Engine::GetEntity('Talk_TalkUser',$aRow);
}
@ -208,9 +208,9 @@ class Mapper_Talk extends Mapper {
FROM
".Config::Get('db.table.talk_user')." as tu
WHERE
tu.date_last IS NULL
tu.user_id = ?d
AND
tu.user_id = ?d
tu.date_last IS NULL
AND
tu.talk_user_active=?d
";

View file

@ -107,11 +107,12 @@ class Mapper_Topic extends Mapper {
public function GetTopicUnique($sUserId,$sHash) {
$sql = "SELECT topic_id FROM ".Config::Get('db.table.topic')."
WHERE
user_id = ?d
topic_text_hash =?
AND
topic_text_hash =?
user_id = ?d
LIMIT 0,1
";
if ($aRow=$this->oDb->selectRow($sql,$sUserId,$sHash)) {
if ($aRow=$this->oDb->selectRow($sql,$sHash,$sUserId)) {
return $aRow['topic_id'];
}
return null;
@ -527,12 +528,12 @@ class Mapper_Topic extends Mapper {
FROM
".Config::Get('db.table.topic_read')." as t
WHERE
t.user_id = ?d
t.topic_id IN(?a)
AND
t.topic_id IN(?a)
t.user_id = ?d
";
$aReads=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
if ($aRows=$this->oDb->select($sql,$aArrayId,$sUserId)) {
foreach ($aRows as $aRow) {
$aReads[]=Engine::GetEntity('Topic_TopicRead',$aRow);
}
@ -566,12 +567,12 @@ class Mapper_Topic extends Mapper {
FROM
".Config::Get('db.table.topic_question_vote')." as v
WHERE
v.user_voter_id = ?d
AND
v.topic_id IN(?a)
v.topic_id IN(?a)
AND
v.user_voter_id = ?d
";
$aVotes=array();
if ($aRows=$this->oDb->select($sql,$sUserId,$aArrayId)) {
if ($aRows=$this->oDb->select($sql,$aArrayId,$sUserId)) {
foreach ($aRows as $aRow) {
$aVotes[]=Engine::GetEntity('Topic_TopicQuestionVote',$aRow);
}

View file

@ -158,4 +158,19 @@ ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );
ALTER TABLE `prefix_comment_online` DROP INDEX `id_type` ,
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_title` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date_last` );
ALTER TABLE `prefix_talk_user` DROP INDEX `talk_id`;
ALTER TABLE `prefix_talk_user` ADD INDEX ( `date_last` );
ALTER TABLE `prefix_talk_user` ADD INDEX ( `talk_user_active` );
ALTER TABLE `prefix_topic_read` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic_question_vote` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic` ADD INDEX ( `topic_text_hash` );
ALTER TABLE `prefix_session` ADD INDEX ( `session_date_last` );
ALTER TABLE `prefix_user` DROP INDEX `user_date_last`;

View file

@ -984,4 +984,19 @@ ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );
ALTER TABLE `prefix_comment_online` DROP INDEX `id_type` ,
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_title` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date_last` );
ALTER TABLE `prefix_talk_user` DROP INDEX `talk_id`;
ALTER TABLE `prefix_talk_user` ADD INDEX ( `date_last` );
ALTER TABLE `prefix_talk_user` ADD INDEX ( `talk_user_active` );
ALTER TABLE `prefix_topic_read` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic_question_vote` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic` ADD INDEX ( `topic_text_hash` );
ALTER TABLE `prefix_session` ADD INDEX ( `session_date_last` );
ALTER TABLE `prefix_user` DROP INDEX `user_date_last`;

View file

@ -167,4 +167,19 @@ ALTER TABLE `prefix_friend` DROP INDEX `user_from`;
ALTER TABLE `prefix_notify_task` ADD INDEX ( `date_created` );
ALTER TABLE `prefix_comment_online` DROP INDEX `id_type` ,
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ADD UNIQUE `id_type` ( `target_id` , `target_type` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_title` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date` );
ALTER TABLE `prefix_talk` ADD INDEX ( `talk_date_last` );
ALTER TABLE `prefix_talk_user` DROP INDEX `talk_id`;
ALTER TABLE `prefix_talk_user` ADD INDEX ( `date_last` );
ALTER TABLE `prefix_talk_user` ADD INDEX ( `talk_user_active` );
ALTER TABLE `prefix_topic_read` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic_question_vote` DROP INDEX `topic_id`;
ALTER TABLE `prefix_topic` ADD INDEX ( `topic_text_hash` );
ALTER TABLE `prefix_session` ADD INDEX ( `session_date_last` );
ALTER TABLE `prefix_user` DROP INDEX `user_date_last`;