推荐应用
DiscuzX2.5的InnoDB解决方案
发布于 2013-07-13
InnoDB不适用以下类型的Discuz论坛网站
1、主要做展示的网站,数据库写操作较少
2、主要做Insert操作的
3、Update和Delete操作较少的
4、日PV小于10W的
执行步骤
1、转换表引擎
我们需要将除forum_post表(包括它的所有分表)、common_session、common_admincp_session、common_member_grouppm之外的其他所有表转换成InnoDB引擎,可以使用如下这样的SQL语句
source/class/discuz/discus_database.php第339行增加如下代码:
1、主要做展示的网站,数据库写操作较少
2、主要做Insert操作的
3、Update和Delete操作较少的
4、日PV小于10W的
执行步骤
1、转换表引擎
我们需要将除forum_post表(包括它的所有分表)、common_session、common_admincp_session、common_member_grouppm之外的其他所有表转换成InnoDB引擎,可以使用如下这样的SQL语句
ALTER TABLE `pre_common_addon` ENGINE=InnoDB;
2、修改如下文件source/class/discuz/discus_database.php第339行增加如下代码:
public static function count_all($table) {
$linkId = 1;
if(!empty(self::$db->config['map']) && !empty(self::$db->config['map'][$table])){
$linkId = self::$db->config['map'][$table];}
$dbname = self::$db->config[$linkId]['dbname'];
$table = self::$db->table_name($table);
self::$db->select_db('information_schema');
return self::$db->result_first("SELECT TABLE_ROWS FROM `TABLES` WHERE TABLE_SCHEMA = '$dbname' AND TABLE_NAME = '$table'");}
ource/class/table/table_common_block_permission.php第55行替换为
return $where ? DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$where) : DB::count_all($this->_table);
source/class/table/table_common_block_style.php第34行替换为
return $wheresql ? DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
source/class/table/table_common_credit_log.php第120行替换为
return $condition[0] ? DB::result_first('SELECT COUNT(*) FROM %t '.$condition[0], $condition[1]) : DB::count_all($this->_table);
source/class/table/table_common_diy_data.php第51行替换为return $wheresql ? DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
source/class/table/table_common_invite.php第63行替换为
return $condition[0] ? DB::result_first('SELECT COUNT(*) FROM %t '.$condition[0], $condition[1]) : DB::count_all($this->_table);
source/class/table/table_common_member.php第170行替换为$count = DB::count_all($this->_table);
第174行替换为$count += intval(DB::count_all('common_connect_guest'));
第350行替换为if(!DB::fetch_first('SELECT * FROM '.$temptablename.' LIMIT 1')) {
第354行替换为if(DB::fetch_first('SELECT * FROM '.$temptablename.' LIMIT 1')) {
source/class/table/table_common_member_archive.php第48行替换为return isset($this->membersplit) ? DB::count_all($this->_table) : 0;
source/class/table/table_common_member_verify_info.php第49行替换为return $condition[0] ? DB::result_first('SELECT COUNT(*) FROM %t '.$condition[0], $condition[1]) : DB::count_all($this->_table);
source/class/table/table_forum_attachtype.php第51行替换为return $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
source/class/table/table_forum_grouplevel.php第27行替换为return DB::count_all($this->_table);
source/class/table/table_forum_medallog.php第81行替换为return $where ? DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_medallog')." $where") : DB::count_all($this->_table);
source/class/table/table_forum_thread.php第982行替换为
return $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
第1023行替换为return DB::count_all($this->get_table_name($tableid));
第1028行替换为return $condition[0] ? DB::result_first('SELECT COUNT(*) FROM %t '.$condition[0], $condition[1]) : DB::count_all($this->get_table_name());
source/class/table/table_home_blacklist.php第37行替换为return $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
source/class/table/table_home_favorite.php第56行替换为
return $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql ", $parameter) : DB::count_all($this->_table);
source/class/table/table_home_follow.php第100行替换为
$count = $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
第112行替换为
$count = $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
source/class/table/table_home_follow_feed.php第76行替换为$count = $wheresql ? DB::result_first("SELECT COUNT(*) FROM %t $wheresql", $parameter) : DB::count_all($this->_table);
source/class/table/table_home_friend.php第104行替换为
return $wheresql ? DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter) : DB::count_all($this->_table);
source/class/table/table_home_share.php第137行替换为return $wheresql ? DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter) : DB::count_all($this->_table);
第158行替换为
return $wheresql ? DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter) : DB::count_all($this->_table);
第195行替换为
return $wheresql ? DB::result_first('SELECT COUNT(*) FROM %t '.$wheresql, $parameter) : DB::count_all($this->_table);
source/class/table/table_portal_topic.php第25行替换为
$wheresql = empty($wherearr) ? '' : ' WHERE '.implode(' AND ', $wherearr);
第26行替换为return $wheresql ? DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
source/class/table/table_portal_category_permission.php第54行替换为return $where ? DB::result_first('SELECT COUNT(*) FROM '.DB::table($this->_table).$where) : DB::count_all($this->_table);
进行如上这些操作之后就可以了,大功告成,哈哈!