$this->mServer, $this->mDBname, $this->mTrxShortId );
}
- $queryProf = '';
- $totalProf = '';
$isMaster = !is_null( $this->getLBInfo( 'master' ) );
+ # generalizeSQL will probably cut down the query to reasonable
+ # logging size most of the time. The substr is really just a sanity check.
+ if ( $isMaster ) {
+ $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $totalProf = 'DatabaseBase::query-master';
+ } else {
+ $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $totalProf = 'DatabaseBase::query';
+ }
+ # Include query transaction state
+ $queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : "";
$profiler = Profiler::instance();
if ( !$profiler instanceof ProfilerStub ) {
- # generalizeSQL will probably cut down the query to reasonable
- # logging size most of the time. The substr is really just a sanity check.
- if ( $isMaster ) {
- $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
- $totalProf = 'DatabaseBase::query-master';
- } else {
- $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
- $totalProf = 'DatabaseBase::query';
- }
- # Include query transaction state
- $queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : "";
-
$totalProfSection = $profiler->scopedProfileIn( $totalProf );
$queryProfSection = $profiler->scopedProfileIn( $queryProf );
}
throw new DBUnexpectedError( $this, "DB connection was already closed." );
}
- # Log the query time and feed it into the DB trx profiler
- if ( $queryProf != '' ) {
- $that = $this;
- $queryStartTime = microtime( true );
- $queryProfile = new ScopedCallback(
- function () use ( $that, $queryStartTime, $queryProf, $isMaster ) {
- $n = $that->affectedRows();
- $trxProf = Profiler::instance()->getTransactionProfiler();
- $trxProf->recordQueryCompletion( $queryProf, $queryStartTime, $isMaster, $n );
- }
- );
- }
-
# Do the query and handle errors
+ $startTime = microtime( true );
$ret = $this->doQuery( $commentedSql );
+ # Log the query time and feed it into the DB trx profiler
+ $profiler->getTransactionProfiler()->recordQueryCompletion(
+ $queryProf, $startTime, $isWriteQuery, $this->affectedRows() );
MWDebug::queryTime( $queryId );
$this->reportQueryError( $lastError, $lastErrno, $sql, $fname, $tempIgnore );
} else {
# Should be safe to silently retry (no trx and thus no callbacks)
+ $startTime = microtime( true );
$ret = $this->doQuery( $commentedSql );
+ # Log the query time and feed it into the DB trx profiler
+ $profiler->getTransactionProfiler()->recordQueryCompletion(
+ $queryProf, $startTime, $isWriteQuery, $this->affectedRows() );
}
} else {
wfDebug( "Failed\n" );
}
if ( false === $ret ) {
- $this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore );
+ $this->reportQueryError(
+ $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore );
}
$res = $this->resultObject( $ret );
* - If the value of such an array element is a scalar (such as a
* string), it will be treated as data and thus quoted appropriately.
* If it is null, an IS NULL clause will be added.
- * - If the value is an array, an IN(...) clause will be constructed,
- * such that the field name may match any of the elements in the
- * array. The elements of the array will be quoted.
+ * - If the value is an array, an IN (...) clause will be constructed
+ * from its non-null elements, and an IS NULL clause will be added
+ * if null is present, such that the field may match any of the
+ * elements in the array. The non-null elements will be quoted.
*
* Note that expressions are often DBMS-dependent in their syntax.
* DBMS-independent wrappers are provided for constructing several types of