Implemented save/restore logic for sql_big_selects, per CR comments on r50168.
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 27 May 2009 06:10:48 +0000 (06:10 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 27 May 2009 06:10:48 +0000 (06:10 +0000)
includes/LogEventsList.php
includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseMssql.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 60a1721..e645750 100644 (file)
@@ -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' );
        }
 }
 
index f5c482e..40dc2e8 100644 (file)
@@ -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__ );
+       }
 }
 
 /**
index fcd0bc2..6f7b675 100644 (file)
@@ -1792,5 +1792,8 @@ SQL;
                // TODO
                // see SpecialAncientpages
        }
+
+       /** No-op */
+       public function setBigSelects( $value = true ) {}
 }
-?>
\ No newline at end of file
+?>
index 28ccab2..524fa07 100644 (file)
@@ -1015,6 +1015,8 @@ class DatabaseMssql extends Database {
                return "SearchEngineDummy";
        }
 
+       /** No-op */
+       public function setBigSelects( $value = true ) {}
 }
 
 /**
index 4c37a50..3014d8c 100644 (file)
@@ -721,4 +721,7 @@ echo "error!\n";
                return "SearchOracle";
        }
 
+       /** No-op */
+       public function setBigSelects( $value = true ) {}
+
 } // end DatabaseOracle class
index c940ad0..3a2212a 100644 (file)
@@ -1438,4 +1438,7 @@ END;
                return "SearchPostgres";
        }
 
+       /** No-op */
+       public function setBigSelects( $value = true ) {}
+
 } // end DatabasePostgres class
index a4efca7..525e54b 100644 (file)
@@ -497,6 +497,9 @@ class DatabaseSqlite extends Database {
                return $s;
        }
 
+       /** No-op */
+       public function setBigSelects( $value = true ) {}
+
 } // end DatabaseSqlite class
 
 /**