From 32fc405ea78fa342138bde2786e3b8d01d338f92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 2 Oct 2005 16:10:39 +0000 Subject: [PATCH] * Support for specifying USE INDEX for any of >1 tables --- includes/Database.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 446bca5e95..72f1e06a03 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -718,7 +718,7 @@ class Database { $tailOpts .= ' LOCK IN SHARE MODE'; } - if ( isset( $options['USE INDEX'] ) ) { + if ( isset( $options['USE INDEX'] ) && ! is_array( $options['USE INDEX'] ) ) { $useIndex = $this->useIndexClause( $options['USE INDEX'] ); } else { $useIndex = ''; @@ -738,7 +738,10 @@ class Database { $options = array( $options ); } if( is_array( $table ) ) { - $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) ); + if ( @is_array( $options['USE INDEX'] ) ) + $from = ' FROM ' . $this->tableNamesWithUseIndex( $table, $options['USE INDEX'] ); + else + $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) ); } elseif ($table!='') { $from = ' FROM ' . $this->tableName( $table ); } else { @@ -1130,6 +1133,21 @@ class Database { return $retVal; } + /** + * @access private + */ + function tableNamesWithUseIndex( $tables, $use_index ) { + $ret = array(); + + foreach ( $tables as $table ) + if ( @$use_index[$table] !== null ) + $ret[] = $this->tableName( $table ) . ' ' . $this->useIndexClause( implode( ',', (array)$use_index[$table] ) ); + else + $ret[] = $this->tableName( $table ); + + return implode( ',', $ret ); + } + /** * Wrapper for addslashes() * @param string $s String to be slashed. -- 2.20.1