* (bug 20847) Deprecated deprecated akeytt() removed in wikibits.js leaving
dummy
* (bug 21161) Changing $wgCaCacheEpoch now always invalidates file cache
+* (bug 20268) Fixed row count estimation on SQLite backend
== API changes in 1.16 ==
/**
* Estimate rows in dataset
- * Returns estimated count, based on EXPLAIN output
+ * Returns estimated count - not necessarily an accurate estimate across different databases,
+ * so use sparingly
* Takes same arguments as Database::select()
+ *
+ * @param string $table table name
+ * @param array $vars unused
+ * @param array $conds filters on the table
+ * @param string $fname function name for profiling
+ * @param array $options options for select
+ * @return int row count
*/
public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
- $options['EXPLAIN'] = true;
- $res = $this->select( $table, $vars, $conds, $fname, $options );
- if ( $res === false )
- return false;
- if ( !$this->numRows( $res ) ) {
- $this->freeResult($res);
- return 0;
+ $rows = 0;
+ $res = $this->select ( $table, 'COUNT(*) AS rowcount', $conds, $fname, $options );
+ if ( $res ) {
+ $row = $this->fetchRow( $res );
+ $rows = ( isset( $row['rowcount'] ) ) ? $row['rowcount'] : 0;
}
-
- $rows = 1;
- while( $plan = $this->fetchObject( $res ) ) {
- $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero
- }
-
- $this->freeResult($res);
- return $rows;
+ $this->freeResult( $res );
+ return $rows;
}
/**
$this->query( $sql, $fname );
}
-
- /**
- * Estimate rows in dataset
- * Returns estimated count, based on COUNT(*) output
- * Takes same arguments as Database::select()
- * @param string $table table name
- * @param array $vars unused
- * @param array $conds filters on the table
- * @param string $fname function name for profiling
- * @param array $options options for select
- * @return int row count
- */
- public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
- $rows = 0;
- $res = $this->select ($table, 'COUNT(*) as mwrowcount', $conds, $fname, $options );
- if ($res) {
- $row = $this->fetchRow($res);
- $rows = (isset($row['mwrowcount'])) ? $row['mwrowcount'] : 0;
- }
- $this->freeResult($res);
- return $rows;
- }
-
+
/**
* Description is left as an exercise for the reader
* @param mixed $b data to be encoded
return $this->query( $sql, $fname );
}
- /**
- * Estimate rows in dataset
- * Returns estimated count, based on EXPLAIN output
- * Takes same arguments as Database::select()
- */
- function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
- $rows = 0;
- $res = $this->select ($table, 'COUNT(*)', $conds, $fname, $options );
- if ($res) {
- $row = $this->fetchObject($res);
- $rows = $row[0];
- }
- $this->freeResult($res);
- return $rows;
- }
-
/**
* Determines whether a field exists in a table
* Usually aborts on failure
}
function affectedRows() { return mysql_affected_rows( $this->mConn ); }
+
+ /**
+ * Estimate rows in dataset
+ * Returns estimated count, based on EXPLAIN output
+ * Takes same arguments as Database::select()
+ */
+ public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
+ $options['EXPLAIN'] = true;
+ $res = $this->select( $table, $vars, $conds, $fname, $options );
+ if ( $res === false )
+ return false;
+ if ( !$this->numRows( $res ) ) {
+ $this->freeResult($res);
+ return 0;
+ }
+
+ $rows = 1;
+ while( $plan = $this->fetchObject( $res ) ) {
+ $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero
+ }
+
+ $this->freeResult($res);
+ return $rows;
+ }
function fieldInfo( $table, $field ) {
$table = $this->tableName( $table );