/** Maximum time to wait before retry */
const DEADLOCK_DELAY_MAX = 1500000;
- /** How many row changes in a write query trigger a log entry */
- const LOG_WRITE_THRESHOLD = 300;
-
protected $mLastQuery = '';
protected $mDoneWrites = false;
protected $mPHPError = false;
# Log the query time and feed it into the DB trx profiler
if ( $queryProf != '' ) {
+ $that = $this;
$queryStartTime = microtime( true );
$queryProfile = new ScopedCallback(
- function () use ( $queryStartTime, $queryProf, $isMaster ) {
- $trxProfiler = Profiler::instance()->getTransactionProfiler();
- $trxProfiler->recordQueryCompletion( $queryProf, $queryStartTime, $isMaster );
+ function () use ( $that, $queryStartTime, $queryProf, $isMaster ) {
+ $n = $that->affectedRows();
+ $trxProf = Profiler::instance()->getTransactionProfiler();
+ $trxProf->recordQueryCompletion( $queryProf, $queryStartTime, $isMaster, $n );
}
);
}
if ( false === $ret ) {
$this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore );
- } else {
- $n = $this->affectedRows();
- if ( $isWriteQuery && $n > self::LOG_WRITE_THRESHOLD && PHP_SAPI !== 'cli' ) {
- wfDebugLog( 'DBPerformance',
- "Query affected $n rows:\n" .
- DatabaseBase::generalizeSQL( $sql ) . "\n" . wfBacktrace( true ) );
- }
}
$res = $this->resultObject( $ret );
protected $dbLockThreshold = 3.0;
/** @var float Seconds */
protected $eventThreshold = .25;
+ /** @var integer */
+ protected $affectedThreshold = 500;
/** @var array transaction ID => (write start time, list of DBs involved) */
protected $dbTrxHoldingLocks = array();
*
* This assumes that all queries are synchronous (non-overlapping)
*
- * @param string $query Function name
+ * @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 integer $n Number of affected rows
*/
- public function recordQueryCompletion( $query, $sTime, $isWrite = false ) {
+ public function recordQueryCompletion( $query, $sTime, $isWrite = false, $n = 0 ) {
$eTime = microtime( true );
$elapsed = ( $eTime - $sTime );
+ if ( $isWrite && $n > $this->affectedThreshold && PHP_SAPI !== 'cli' ) {
+ wfDebugLog( 'DBPerformance',
+ "Query affected $n rows:\n" . $query . "\n" . wfBacktrace( true ) );
+ }
+
if ( !$this->dbTrxHoldingLocks ) {
// Short-circuit
return;