aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db/mysqli.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-03-08 08:44:24 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-03-08 08:44:24 -0500
commitd380a1a36ffd5b2de6e403eb63f8754d8a277386 (patch)
tree167e903aad4f7408a131426112a065c19ade0b56 /phpBB/includes/db/mysqli.php
parentd67fae0f09b339dc0f399062dd228fba94e5aaa0 (diff)
parentc11607bdd1ad4209a7697f0dc8d46ea81795b14c (diff)
downloadforums-d380a1a36ffd5b2de6e403eb63f8754d8a277386.tar
forums-d380a1a36ffd5b2de6e403eb63f8754d8a277386.tar.gz
forums-d380a1a36ffd5b2de6e403eb63f8754d8a277386.tar.bz2
forums-d380a1a36ffd5b2de6e403eb63f8754d8a277386.tar.xz
forums-d380a1a36ffd5b2de6e403eb63f8754d8a277386.zip
Merge remote-tracking branch 'bantu/ticket/9813' into develop-olympus
* bantu/ticket/9813: [ticket/10653] Call get_row_count of base class in mysql get_estimated_row_count [ticket/9813] Only get posts table row count if we detected a fulltext index. [ticket/9813] Also use estimated row count of posts table for fulltext mysql. [ticket/10653] Fix parameter to substr() in unit tests. Should be 1, not -1. [ticket/10653] Unit tests for get_row_count() and get_estimated_row_count(). [ticket/10653] Add ability to count table rows to database abstraction layer. [ticket/9813] Use table status row count only if greater than 100000 or exact. [ticket/9813] Use SHOW TABLE STATUS to get search stats for native on MySQL.
Diffstat (limited to 'phpBB/includes/db/mysqli.php')
-rw-r--r--phpBB/includes/db/mysqli.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php
index 456ce906d0..a311b8cda6 100644
--- a/phpBB/includes/db/mysqli.php
+++ b/phpBB/includes/db/mysqli.php
@@ -316,6 +316,76 @@ class dbal_mysqli extends dbal
}
/**
+ * Gets the estimated number of rows in a specified table.
+ *
+ * @param string $table_name Table name
+ *
+ * @return string Number of rows in $table_name.
+ * Prefixed with ~ if estimated (otherwise exact).
+ *
+ * @access public
+ */
+ function get_estimated_row_count($table_name)
+ {
+ $table_status = $this->get_table_status($table_name);
+
+ 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'];
+ }
+ }
+
+ return parent::get_row_count($table_name);
+ }
+
+ /**
+ * Gets the exact number of rows in a specified table.
+ *
+ * @param string $table_name Table name
+ *
+ * @return string Exact number of rows in $table_name.
+ *
+ * @access public
+ */
+ function get_row_count($table_name)
+ {
+ $table_status = $this->get_table_status($table_name);
+
+ if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM')
+ {
+ return $table_status['Rows'];
+ }
+
+ return parent::get_row_count($table_name);
+ }
+
+ /**
+ * Gets some information about the specified table.
+ *
+ * @param string $table_name Table name
+ *
+ * @return array
+ *
+ * @access protected
+ */
+ function get_table_status($table_name)
+ {
+ $sql = "SHOW TABLE STATUS
+ LIKE '" . $this->sql_escape($table_name) . "'";
+ $result = $this->sql_query($sql);
+ $table_status = $this->sql_fetchrow($result);
+ $this->sql_freeresult($result);
+
+ return $table_status;
+ }
+
+ /**
* Build LIKE expression
* @access private
*/