ApiQueryExtLinksUsage: Avoid bad query plan

Apparently MariaDB will sometimes decide it makes more sense to scan and
filesort 80 million rows instead of using an index that allows it to
check only the LIMIT.

A STRAIGHT_JOIN (along with fixed table order) seems to avoid this.

Bug: T244254
Change-Id: I1bf1203459922e2a16fa7339ff424a67005e4a2a
This commit is contained in:
Brad Jorsch 2020-02-04 16:05:11 -05:00
parent 724e1782db
commit c42ee486f4

View file

@ -52,8 +52,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
$query = $params['query'];
$protocol = self::getProtocolPrefix( $params['protocol'] );
$this->addTables( [ 'page', 'externallinks' ] );
$this->addWhere( 'page_id=el_from' );
$this->addTables( [ 'externallinks', 'page' ] );
$this->addJoinConds( [ 'page' => [ 'JOIN', 'page_id=el_from' ] ] );
$miser_ns = [];
if ( $this->getConfig()->get( 'MiserMode' ) ) {
@ -121,6 +121,9 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
$limit = $params['limit'];
$this->addOption( 'LIMIT', $limit + 1 );
// T244254: Avoid MariaDB deciding to scan all of `page`.
$this->addOption( 'STRAIGHT_JOIN' );
if ( $params['continue'] !== null ) {
$cont = explode( '|', $params['continue'] );
$this->dieContinueUsageIf( count( $cont ) !== count( $orderBy ) );