From: Brad Jorsch Date: Thu, 30 Jun 2016 17:48:38 +0000 (-0400) Subject: API: Force indexes for prop=linkshere|transcludedin|fileusage X-Git-Tag: 1.31.0-rc.0~6010^2 X-Git-Url: http://git.cyclocoop.org/%7B%7B%20url_for%28%27admin_vote_add%27%29%20%7D%7D?a=commitdiff_plain;h=17b837d725b8b7388fcf1d61286841f7469beee3;p=lhc%2Fweb%2Fwiklou.git API: Force indexes for prop=linkshere|transcludedin|fileusage 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. Bug: T139056 Change-Id: I989dfbe898b75d649c22e198a6fbdd3a2de196e5 --- diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index 3810e90f13..236fb9e06c 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,18 @@ 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 ] ); + } + } + $this->addOption( 'LIMIT', $params['limit'] + 1 ); $res = $this->select( __METHOD__ );