'code' => 'lh',
'prefix' => 'pl',
'linktable' => 'pagelinks',
+ 'indexes' => [ 'pl_namespace', 'pl_backlinks_namespace' ],
'from_namespace' => true,
'showredirects' => true,
],
'code' => 'ti',
'prefix' => 'tl',
'linktable' => 'templatelinks',
+ 'indexes' => [ 'tl_namespace', 'tl_backlinks_namespace' ],
'from_namespace' => true,
'showredirects' => true,
],
'code' => 'fu',
'prefix' => 'il',
'linktable' => 'imagelinks',
+ 'indexes' => [ 'il_to', 'il_backlinks_namespace' ],
'from_namespace' => true,
'to_namespace' => NS_FILE,
'exampletitle' => 'File:Example.jpg',
$this->dieContinueUsageIf( count( $cont ) != count( $sortby ) );
$where = '';
$i = count( $sortby ) - 1;
- $cont_ns = 0;
- $cont_title = '';
foreach ( array_reverse( $sortby, true ) as $field => $type ) {
$v = $cont[$i];
switch ( $type ) {
case 'ns':
- $cont_ns = (int)$v;
- /* fall through */
case 'int':
$v = (int)$v;
$this->dieContinueUsageIf( $v != $cont[$i] );
break;
-
- case 'title':
- $cont_title = $v;
- /* fall through */
default:
$v = $db->addQuotes( $v );
break;
// 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__ );
foreach ( $sortby as $field => $v ) {
$cont[] = $row->$field;
}
- $this->setContinueEnumParameter( 'continue', join( '|', $cont ) );
+ $this->setContinueEnumParameter( 'continue', implode( '|', $cont ) );
}
public function getCacheMode( $params ) {