Page MenuHomePhabricator

Wanted Pages uses significantly non-optimal query
Open, Needs TriagePublic

Description

In the Wanted Pages query (found in includes/specials/SpecialWantedpages.php=>getQueryInfo()), there is a check that the "from" namespace is not MediaWiki space. This check, however, is performed on the pg2 table, an alias of the page table, which is on the "wrong" side of the join. Since that information is also available in pagelinks itself, it is notably more efficient to check against that copy of it, rather than the joined copy.

TLDR: change

  • 'pg2.page_namespace != ' . $dbr->addQuotes( NS_MEDIAWIKI ) to
  • 'pl_from_namespace != ' . $dbr->addQuotes( NS_MEDIAWIKI )

On our wiki, this resulted in a reduction from 41 seconds, returning 7830 rows, to 4.7 seconds, returning those same 7830 rows. The only potential issue here is if, for some reason, pagelinks.pl_from_namespace becomes out of sync with the equivalent page.page_namespace after joining. (And if it does, you've probably got bigger issues.)