Use STRAIGHT_JOIN in SpecialWhatlinkshere query
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 29 Jul 2015 20:51:42 +0000 (13:51 -0700)
committerOri.livneh <ori@wikimedia.org>
Thu, 30 Jul 2015 17:57:11 +0000 (17:57 +0000)
* Also added a type hint to avoid IDE errors in this area

Bug: T106682
Change-Id: I825eedaceb0c0323de85466e48582d72c57b201a

includes/specials/SpecialWhatlinkshere.php

index 5db81d4..a6f92d6 100644 (file)
@@ -155,7 +155,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                        $conds['pagelinks'][] = 'rd_from is NOT NULL';
                }
 
-               $queryFunc = function ( $dbr, $table, $fromCol ) use (
+               $queryFunc = function ( IDatabase $dbr, $table, $fromCol ) use (
                        $conds, $target, $limit, $useLinkNamespaceDBFields
                ) {
                        // Read an extra row as an at-end check
@@ -170,11 +170,12 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                        }
                        // Inner LIMIT is 2X in case of stale backlinks with wrong namespaces
                        $subQuery = $dbr->selectSqlText(
-                               array( $table, 'page', 'redirect' ),
+                               array( $table, 'redirect', 'page' ),
                                array( $fromCol, 'rd_from' ),
                                $conds[$table],
                                __CLASS__ . '::showIndirectLinks',
-                               array( 'ORDER BY' => $fromCol, 'LIMIT' => 2 * $queryLimit ),
+                               // Force JOIN order per T106682 to avoid large filesorts
+                               array( 'ORDER BY' => $fromCol, 'LIMIT' => 2 * $queryLimit, 'STRAIGHT_JOIN' ),
                                array(
                                        'page' => array( 'INNER JOIN', "$fromCol = page_id" ),
                                        'redirect' => array( 'LEFT JOIN', $on )