DISCUZ!论坛的INNODB使用方案
代码修改
代码中主要是针对SELECT COUNT(*)全表搜索的时候的优化。所涉及的文件均在source/class/table文件夹内
首先需要在class/discuz/discus_database.php中增加一个count_all的方法,修改如下:
在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’);
$count = self::$db->result_first(“SELECT TABLE_ROWS FROM `TABLES` WHERE TABLE_SCHEMA = ‘$dbname’ AND TABLE_NAME = ‘$table'”);
X2.5文件修改列表
文件名
|
|
|
|
|
替换为:
return $where ? DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table($this->_table).$where) : DB::count_all($this->_table);
|
|
|
替换为:
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
|
|
|
替换为:
return $condition[0] ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) : DB::count_all($this->_table);
|
|
|
替换为:
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
|
|
|
替换为:
return $condition[0] ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) : DB::count_all($this->_table);
|
|
|
分别替换为:
$count = DB::count_all($this->_table);
$count += intval(DB::count_all(‘common_connect_guest’));
if(!DB::fetch_first(‘SELECT * FROM ‘.$temptablename.’ LIMIT 1′)) {
if(DB::fetch_first(‘SELECT * FROM ‘.$temptablename.’ LIMIT 1′)) {
|
|
|
替换为:
return isset($this->membersplit) ? DB::count_all($this->_table) : 0;
|
Common_member_verify_info
|
|
替换为:
return $condition[0] ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) : DB::count_all($this->_table);
|
|
|
替换为:
return $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
|
|
|
替换为:
return DB::count_all($this->_table);
|
|
|
替换为:
return $where ? DB::result_first(“SELECT COUNT(*) FROM “.DB::table(‘forum_medallog’).” $where”) : DB::count_all($this->_table);
|
|
|
分别替换为:
return $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
return DB::count_all($this->get_table_name($tableid));
return $condition[0] ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$condition[0], $condition[1]) : DB::count_all($this->get_table_name());
|
|
|
替换为:
return $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
|
|
|
替换为:
return $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql “, $parameter) : DB::count_all($this->_table);
|
|
|
分别替换为:
$count = $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
$count = $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
|
|
|
替换为:
$count = $wheresql ? DB::result_first(“SELECT COUNT(*) FROM %t $wheresql”, $parameter) : DB::count_all($this->_table);
|
|
|
替换为:
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) : DB::count_all($this->_table);
|
|
|
分别替换为:
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) : DB::count_all($this->_table);
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) : DB::count_all($this->_table);
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM %t ‘.$wheresql, $parameter) : DB::count_all($this->_table);
|
|
|
替换为:
$wheresql = empty($wherearr) ? ” : ‘ WHERE ‘.implode(‘ AND ‘, $wherearr);
return $wheresql ? DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table($this->_table).$wheresql) : DB::count_all($this->_table);
|
Portal_category_permission
|
|
替换为:
return $where ? DB::result_first(‘SELECT COUNT(*) FROM ‘.DB::table($this->_table).$where) : DB::count_all($this->_table);
|
注:此表依据17173的INNODB转换方案修改。table目录修改的文件列表如附件table
|
|
数据库修改:修改除post,session表之外的所有表引擎为INNODB。
感谢作者:Luca. 原帖地址:http://www.discuz.net/thread-3251930-1-1.html
无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明discuz论坛的INNODB方案!