From 65b6264fd95080ac52a8136c5748597208b6ca8f Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 20 Oct 2014 21:39:01 -0500 Subject: [PATCH] InnoDB tables for search indexing where possible Especially on Galera clusters, search indexing with MyISAM tables will cause unstable clusters and loss of data. For standalone clusters using MySQL 5.6 or MariaDB 10.0, the database default table storage engine can be used, since either support fulltext indexing. --- include/class.search.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/include/class.search.php b/include/class.search.php index c3b2b2c1e..0df7e086e 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -403,14 +403,30 @@ class MysqlSearchBackend extends SearchBackend { } static function createSearchTable() { - $sql = 'CREATE TABLE IF NOT EXISTS '.TABLE_PREFIX.'_search ( + // Use InnoDB with Galera, MyISAM with v5.5, and the database + // default otherwise + $sql = "select count(*) from information_schema.tables where + table_schema='information_schema' and table_name = + 'INNODB_FT_CONFIG'"; + $mysql56 = db_result(db_query($sql)); + + $sql = "show status like 'wsrep_local_state'"; + $galera = db_result(db_query($sql)); + + if ($galera && !$mysql56) + throw new Exception('Galera cannot be used with MyISAM tables'); + $engine = $galera ? 'InnodB' : ($mysql56 ? '' : 'MyISAM'); + if ($engine) + $engine = 'ENGINE='.$engine; + + $sql = 'CREATE TABLE IF NOT EXISTS '.TABLE_PREFIX."_search ( `object_type` varchar(8) not null, `object_id` int(11) unsigned not null, `title` text collate utf8_general_ci, `content` text collate utf8_general_ci, primary key `object` (`object_type`, `object_id`), fulltext key `search` (`title`, `content`) - ) ENGINE=MyISAM CHARSET=utf8'; + ) $engine CHARSET=utf8"; return db_query($sql); } -- GitLab