X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBacklinksprop.php;h=8e89c32e50d0c2798819ed0a2342906f9d54c57e;hb=76d62d7b204b48a0794032d2266ed64455058d13;hp=5b55332e1193bd1b3081fd4bb7288c05ae227fea;hpb=2e5a0882aaeec0376155d72a4bd7b3ff9c4b4eec;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index 5b55332e11..8e89c32e50 100644 --- a/includes/api/ApiQueryBacklinksprop.php +++ b/includes/api/ApiQueryBacklinksprop.php @@ -53,6 +53,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { 'code' => 'lh', 'prefix' => 'pl', 'linktable' => 'pagelinks', + 'indexes' => [ 'pl_namespace', 'pl_backlinks_namespace' ], 'from_namespace' => true, 'showredirects' => true, ], @@ -60,6 +61,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { 'code' => 'ti', 'prefix' => 'tl', 'linktable' => 'templatelinks', + 'indexes' => [ 'tl_namespace', 'tl_backlinks_namespace' ], 'from_namespace' => true, 'showredirects' => true, ], @@ -67,6 +69,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { 'code' => 'fu', 'prefix' => 'il', 'linktable' => 'imagelinks', + 'indexes' => [ 'il_to', 'il_backlinks_namespace' ], 'from_namespace' => true, 'to_namespace' => NS_FILE, 'exampletitle' => 'File:Example.jpg', @@ -249,6 +252,24 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { // Override any ORDER BY from above with what we calculated earlier. $this->addOption( 'ORDER BY', array_keys( $sortby ) ); + // MySQL's optimizer chokes if we have too many values in "$bl_title IN + // (...)" and chooses the wrong index, so specify the correct index to + // use for the query. See T139056 for details. + if ( !empty( $settings['indexes'] ) ) { + list( $idxNoFromNS, $idxWithFromNS ) = $settings['indexes']; + if ( $params['namespace'] !== null && !empty( $settings['from_namespace'] ) ) { + $this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxWithFromNS ] ); + } else { + $this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxNoFromNS ] ); + } + } + + // MySQL (or at least 5.5.5-10.0.23-MariaDB) chooses a really bad query + // plan if it thinks there will be more matching rows in the linktable + // than are in page. Use STRAIGHT_JOIN here to force it to use the + // intended, fast plan. See T145079 for details. + $this->addOption( 'STRAIGHT_JOIN' ); + $this->addOption( 'LIMIT', $params['limit'] + 1 ); $res = $this->select( __METHOD__ ); @@ -313,7 +334,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { foreach ( $sortby as $field => $v ) { $cont[] = $row->$field; } - $this->setContinueEnumParameter( 'continue', join( '|', $cont ) ); + $this->setContinueEnumParameter( 'continue', implode( '|', $cont ) ); } public function getCacheMode( $params ) {