From: Tim Starling Date: Wed, 27 May 2009 06:10:48 +0000 (+0000) Subject: Implemented save/restore logic for sql_big_selects, per CR comments on r50168. X-Git-Tag: 1.31.0-rc.0~41636 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=cb3bbe1809eaecc7f9c05eb192349a264cf98e98;p=lhc%2Fweb%2Fwiklou.git Implemented save/restore logic for sql_big_selects, per CR comments on r50168. --- diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 60a1721fde..e645750b24 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -745,14 +745,10 @@ class LogPager extends ReverseChronologicalPager { } public function doQuery() { - // Work around MySQL optimizer bug - if ( in_array( get_class( $this->mDb ), array( 'Database', 'DatabaseMysql' ) ) ) { - $this->mDb->query( 'SET SQL_BIG_SELECTS=1' ); - parent::doQuery(); - $this->mDb->query( 'SET SQL_BIG_SELECTS=0' ); - } else { - parent::doQuery(); - } + // Workaround MySQL optimizer bug + $this->mDb->setBigSelects(); + parent::doQuery(); + $this->mDb->setBigSelects( 'default' ); } } diff --git a/includes/db/Database.php b/includes/db/Database.php index f5c482e384..40dc2e816c 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -39,6 +39,7 @@ class Database { protected $mErrorCount = 0; protected $mLBInfo = array(); protected $mFakeSlaveLag = null, $mFakeMaster = false; + protected $mDefaultBigSelects = null; #------------------------------------------------------------------------------ # Accessors @@ -2393,6 +2394,29 @@ class Database { public function getSearchEngine() { return "SearchMySQL"; } + + /** + * Allow or deny "big selects" for this session only. This is done by setting + * the sql_big_selects session variable. + * + * This is a MySQL-specific feature. + * + * @param mixed $value true for allow, false for deny, or "default" to restore the initial value + */ + public function setBigSelects( $value = true ) { + if ( $value === 'default' ) { + if ( $this->mDefaultBigSelects === null ) { + # Function hasn't been called before so it must already be set to the default + return; + } else { + $value = $this->mDefaultBigSelects; + } + } elseif ( $this->mDefaultBigSelects === null ) { + $this->mDefaultBigSelects = (bool)$this->selectField( false, '@@sql_big_selects' ); + } + $encValue = $value ? '1' : '0'; + $this->query( "SET sql_big_selects=$encValue", __METHOD__ ); + } } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index fcd0bc2d82..6f7b675c84 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -1792,5 +1792,8 @@ SQL; // TODO // see SpecialAncientpages } + + /** No-op */ + public function setBigSelects( $value = true ) {} } -?> \ No newline at end of file +?> diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 28ccab2d24..524fa07144 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -1015,6 +1015,8 @@ class DatabaseMssql extends Database { return "SearchEngineDummy"; } + /** No-op */ + public function setBigSelects( $value = true ) {} } /** diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 4c37a5077e..3014d8cca1 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -721,4 +721,7 @@ echo "error!\n"; return "SearchOracle"; } + /** No-op */ + public function setBigSelects( $value = true ) {} + } // end DatabaseOracle class diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index c940ad095f..3a2212af81 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1438,4 +1438,7 @@ END; return "SearchPostgres"; } + /** No-op */ + public function setBigSelects( $value = true ) {} + } // end DatabasePostgres class diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index a4efca73d4..525e54b9c1 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -497,6 +497,9 @@ class DatabaseSqlite extends Database { return $s; } + /** No-op */ + public function setBigSelects( $value = true ) {} + } // end DatabaseSqlite class /**