X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBacklinksprop.php;h=ef7b9af9869f1fdc3331fd42bea6acb2ea8f0aad;hb=da637fd3b927e87417e31b6b7c8249613af321a6;hp=3810e90f139745d2dd3b73b80ca0d03fa0abc6f8;hpb=fc1ca75323b5f424a9f8d28d42d85a311ed2f721;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index 3810e90f13..ef7b9af986 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', @@ -235,7 +238,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { if ( isset( $show['fragment'] ) && isset( $show['!fragment'] ) || isset( $show['redirect'] ) && isset( $show['!redirect'] ) ) { - $this->dieUsageMsg( 'show' ); + $this->dieWithError( 'apierror-show' ); } $this->addWhereIf( "rd_fragment != $emptyString", isset( $show['fragment'] ) ); $this->addWhereIf( @@ -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__ );