From 971982db122d4aa3e75ada8f2b8fabed3c6095ad Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Sat, 7 Apr 2007 17:46:17 +0000 Subject: [PATCH] Add estimateRowCount(), to support changes made in r21071 --- includes/DatabasePostgres.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index c280f487c8..6af0c023e1 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -558,6 +558,30 @@ class DatabasePostgres extends Database { return pg_affected_rows( $this->mLastResult ); } + /** + * Estimate rows in dataset + * Returns estimated count, based on EXPLAIN output + * This is not necessarily an accurate estimate, so use sparingly + * Returns -1 if count cannot be found + * Takes same arguments as Database::select() + */ + + function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) { + $options['EXPLAIN'] = true; + $res = $this->select( $table, $vars, $conds, $fname, $options ); + $rows = -1; + if ( $res ) { + $row = $this->fetchRow( $res ); + $count = array(); + if( preg_match( '/rows=(\d+)/', $row[0], $count ) ) { + $rows = $count[1]; + } + $this->freeResult($res); + } + return $rows; + } + + /** * Returns information about an index * If errors are explicitly ignored, returns NULL on failure -- 2.20.1