'GET' => [
'masterConns' => 0,
'writes' => 0,
- 'readQueryTime' => 5
+ 'readQueryTime' => 5,
+ 'readQueryRows' => 10000
],
// HTTP POST requests.
// Master reads and writes will happen for a subset of these.
'POST' => [
'readQueryTime' => 5,
'writeQueryTime' => 1,
+ 'readQueryRows' => 100000,
'maxAffected' => 1000
],
'POST-nonwrite' => [
'masterConns' => 0,
'writes' => 0,
- 'readQueryTime' => 5
+ 'readQueryTime' => 5,
+ 'readQueryRows' => 10000
],
// Deferred updates that run after HTTP response is sent for GET requests
'PostSend-GET' => [
'readQueryTime' => 5,
'writeQueryTime' => 1,
+ 'readQueryRows' => 10000,
'maxAffected' => 1000,
// Log master queries under the post-send entry point as they are discouraged
'masterConns' => 0,
'PostSend-POST' => [
'readQueryTime' => 5,
'writeQueryTime' => 1,
+ 'readQueryRows' => 100000,
'maxAffected' => 1000
],
// Background job runner
'JobRunner' => [
'readQueryTime' => 30,
'writeQueryTime' => 5,
+ 'readQueryRows' => 100000,
'maxAffected' => 500 // ballpark of $wgUpdateRowsPerQuery
],
// Command-line scripts
'conns' => INF,
'masterConns' => INF,
'maxAffected' => INF,
+ 'readQueryRows' => INF,
'readQueryTime' => INF,
'writeQueryTime' => INF
];
* @param string $query Function name or generalized SQL
* @param float $sTime Starting UNIX wall time
* @param bool $isWrite Whether this is a write query
- * @param int $n Number of affected rows
+ * @param int $n Number of affected/read rows
*/
public function recordQueryCompletion( $query, $sTime, $isWrite = false, $n = 0 ) {
$eTime = microtime( true );
$this->logger->warning(
"Query affected $n row(s):\n" . $query . "\n" .
( new RuntimeException() )->getTraceAsString() );
+ } elseif ( !$isWrite && $n > $this->expect['readQueryRows'] ) {
+ $this->logger->warning(
+ "Query returned $n row(s):\n" . $query . "\n" .
+ ( new RuntimeException() )->getTraceAsString() );
}
// Report when too many writes/queries happen...
}
$this->trxProfiler->recordQueryCompletion(
- $queryProf, $startTime, $isWrite, $this->affectedRows()
+ $queryProf,
+ $startTime,
+ $isWrite,
+ $isWrite ? $this->affectedRows() : $this->numRows( $ret )
);
$this->queryLogger->debug( $sql, [
'method' => $fname,
}
public function numRows( $res ) {
+ if ( $res === false ) {
+ return 0;
+ }
+
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
/**
* The PDO::Statement class implements the array interface so count() will work
*
- * @param ResultWrapper|array $res
+ * @param ResultWrapper|array|false $res
* @return int
*/
function numRows( $res ) {
+ // false does not implement Countable
$r = $res instanceof ResultWrapper ? $res->result : $res;
- return count( $r );
+ return is_array( $r ) ? count( $r ) : 0;
}
/**