From: Brad Jorsch Date: Tue, 2 Apr 2019 14:07:56 +0000 (-0400) Subject: MigrateActors: Improve query for log_search rows X-Git-Tag: 1.34.0-rc.0~2187^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=commitdiff_plain;h=42b14d98b5dca07c8180468bbc02fccea2721e62;p=lhc%2Fweb%2Fwiklou.git MigrateActors: Improve query for log_search rows The query in question is, generically, SELECT ls_value, ls_log_id, actor_id FROM log_search LEFT JOIN actor ON (ls_value = actor_user) WHERE ls_field = 'target_author_id' ORDER BY ls_value, ls_log_id LIMIT 100; The intention is that it'll pull out 100 rows from log_search using its primary key, and for each of those 100 rows find the actor_id for the referenced user_id (using the actor_user index) if an actor ID exists. The twist comes in the fact that ls_value is a string-type column while actor_user is an integer-type. MySQL doesn't usually care, but other DBs do so we have to cast one into the other. Currently the code is casting actor_user to a string. But that means the DB can't use the index on actor_user to find the one matching row, instead it needs to scan the whole table. The fix is simple enough: instead of casting actor_user to a string, cast ls_value to an integer. That allows the actor_user index to be used as expected. Bug: T215525 Change-Id: I2f7a6ba9fd537336594088a0281a62ea5601cd59 --- diff --git a/maintenance/includes/MigrateActors.php b/maintenance/includes/MigrateActors.php index f5b366690c..aff67587b4 100644 --- a/maintenance/includes/MigrateActors.php +++ b/maintenance/includes/MigrateActors.php @@ -504,7 +504,7 @@ class MigrateActors extends LoggedUpdateMaintenance { 'ORDER BY' => $primaryKey, 'LIMIT' => $this->mBatchSize, ], - [ 'actor' => [ 'LEFT JOIN', 'ls_value = ' . $dbw->buildStringCast( 'actor_user' ) ] ] + [ 'actor' => [ 'LEFT JOIN', 'actor_user = ' . $dbw->buildIntegerCast( 'ls_value' ) ] ] ); if ( !$res->numRows() ) { break;