diff options
author | Andreas Fischer <bantu@phpbb.com> | 2011-12-12 02:41:48 +0100 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2012-03-03 21:03:55 +0100 |
commit | 97cf433dea658127ed60c70ea47d1c3830964f25 (patch) | |
tree | a999650c489bb1378efc493ced55a65e0eed4be4 /phpBB | |
parent | efe25a0b49c7445bef665ab28fc979e485e49289 (diff) | |
download | forums-97cf433dea658127ed60c70ea47d1c3830964f25.tar forums-97cf433dea658127ed60c70ea47d1c3830964f25.tar.gz forums-97cf433dea658127ed60c70ea47d1c3830964f25.tar.bz2 forums-97cf433dea658127ed60c70ea47d1c3830964f25.tar.xz forums-97cf433dea658127ed60c70ea47d1c3830964f25.zip |
[ticket/9813] Use table status row count only if greater than 100000 or exact.
PHPBB3-9813
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/search/fulltext_native.php | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index e5eee50fdb..69937ff9c9 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -1459,37 +1459,52 @@ class fulltext_native extends search_backend function get_stats() { + $this->stats['total_words'] = $this->get_table_row_count(SEARCH_WORDLIST_TABLE); + $this->stats['total_matches'] = $this->get_table_row_count(SEARCH_WORDMATCH_TABLE); + } + + /** + * Gets statistics for a specific database table. + * + * @param string $table_name Table name + * + * @return string Row count. Prefixed with ~ if estimated. + * + * @access protected + */ + function get_table_row_count($table_name) + { global $db; - switch ($db->sql_layer) + if (stripos($db->sql_layer, 'mysql') === 0) { - case 'mysql4': - case 'mysqli': - $sql = "SHOW TABLE STATUS LIKE '" . SEARCH_WORDLIST_TABLE . "'"; - $result = $db->sql_query($sql); - $this->stats['total_words'] = (int) $db->sql_fetchfield('Rows'); - $db->sql_freeresult($result); - - $sql = "SHOW TABLE STATUS LIKE '" . SEARCH_WORDMATCH_TABLE . "'"; - $result = $db->sql_query($sql); - $this->stats['total_matches'] = (int) $db->sql_fetchfield('Rows'); - $db->sql_freeresult($result); - break; + $sql = "SHOW TABLE STATUS + LIKE '" . $table_name . "'"; + $result = $db->sql_query($sql); + $table_status = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - default: - $sql = 'SELECT COUNT(*) as total_words - FROM ' . SEARCH_WORDLIST_TABLE; - $result = $db->sql_query($sql); - $this->stats['total_words'] = (int) $db->sql_fetchfield('total_words'); - $db->sql_freeresult($result); - - $sql = 'SELECT COUNT(*) as total_matches - FROM ' . SEARCH_WORDMATCH_TABLE; - $result = $db->sql_query($sql); - $this->stats['total_matches'] = (int) $db->sql_fetchfield('total_matches'); - $db->sql_freeresult($result); - break; + if (isset($table_status['Engine'])) + { + if ($table_status['Engine'] === 'MyISAM') + { + return $table_status['Rows']; + } + else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000) + { + return '~' . $table_status['Rows']; + } + } } + + // Get exact row count by actually counting rows + $sql = 'SELECT COUNT(*) AS rows_total + FROM ' . $table_name; + $result = $db->sql_query($sql); + $rows_total = $db->sql_fetchfield('rows_total'); + $db->sql_freeresult($result); + + return $rows_total; } /** |