From 5424238aa9e21233d73bc27c95db19c49c6df26d Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 18 Sep 2019 12:44:15 -0400 Subject: [PATCH] Remove MySQL index aliasing for user_newtalk indexes While these have not yet caused problems, we should probably deprecate the whole confusing "index aliasing" feature. Cleaning this up needs to be done first. Method MWLBFactory::setSchemaAliases() is being considered private due to the @internal notation, and so is being removed without deprecation. Bug: T233240 Change-Id: Ib04b7bc4af53382fde01bd8550cc7e361124255f --- includes/ServiceWiring.php | 5 +--- includes/db/MWLBFactory.php | 29 ------------------- includes/installer/MysqlUpdater.php | 1 + ...atch-rename-mysql-user_newtalk-indexes.sql | 10 +++++++ 4 files changed, 12 insertions(+), 33 deletions(-) create mode 100644 maintenance/archives/patch-rename-mysql-user_newtalk-indexes.sql diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index ab51eabd47..83847d80ae 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -207,10 +207,7 @@ return [ ); $class = MWLBFactory::getLBFactoryClass( $lbConf ); - $instance = new $class( $lbConf ); - MWLBFactory::setSchemaAliases( $instance, $mainConfig->get( 'DBtype' ) ); - - return $instance; + return new $class( $lbConf ); }, 'EventRelayerGroup' => function ( MediaWikiServices $services ) : EventRelayerGroup { diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index ad5708a2f2..63b320e343 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -23,7 +23,6 @@ use MediaWiki\Config\ServiceOptions; use MediaWiki\Logger\LoggerFactory; -use Wikimedia\Rdbms\LBFactory; use Wikimedia\Rdbms\DatabaseDomain; /** @@ -359,34 +358,6 @@ abstract class MWLBFactory { return $class; } - /** - * @param LBFactory $lbFactory - * @param string $dbType 'mysql', 'sqlite', etc. - * @internal For use with service wiring - */ - public static function setSchemaAliases( LBFactory $lbFactory, $dbType ) { - if ( $dbType === 'mysql' ) { - /** - * When SQLite indexes were introduced in r45764, it was noted that - * SQLite requires index names to be unique within the whole database, - * not just within a schema. As discussed in CR r45819, to avoid the - * need for a schema change on existing installations, the indexes - * were implicitly mapped from the new names to the old names. - * - * This mapping can be removed if DB patches are introduced to alter - * the relevant tables in existing installations. Note that because - * this index mapping applies to table creation, even new installations - * of MySQL have the old names (except for installations created during - * a period where this mapping was inappropriately removed, see - * T154872). - */ - $lbFactory->setIndexAliases( [ - 'un_user_id' => 'user_id', - 'un_user_ip' => 'user_ip', - ] ); - } - } - /** * Log a database deprecation warning * @param string $msg Deprecation message diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 7d41d04616..a53a72b9d5 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -390,6 +390,7 @@ class MysqlUpdater extends DatabaseUpdater { 'patch-drop-archive-ar_usertext_timestamp.sql' ], [ 'dropIndex', 'archive', 'usertext_timestamp', 'patch-drop-archive-usertext_timestamp.sql' ], [ 'dropField', 'logging', 'log_user', 'patch-drop-user-fields.sql' ], + [ 'addIndex', 'user_newtalk', 'un_user_ip', 'patch-rename-mysql-user_newtalk-indexes.sql' ], ]; } diff --git a/maintenance/archives/patch-rename-mysql-user_newtalk-indexes.sql b/maintenance/archives/patch-rename-mysql-user_newtalk-indexes.sql new file mode 100644 index 0000000000..3177b4d7d3 --- /dev/null +++ b/maintenance/archives/patch-rename-mysql-user_newtalk-indexes.sql @@ -0,0 +1,10 @@ +-- T233240: The indexes on `user_newtalk` may be named `un_user_id`/`un_user_ip` +-- or `user_id`/`user_ip`. At least it won't be both or mixed. Rename them to +-- the former. + +-- Do not use the /*i*/ hack here! +ALTER TABLE /*_*/user_newtalk + DROP INDEX user_id, + DROP INDEX user_ip, + ADD INDEX un_user_id (user_id), + ADD INDEX un_user_ip (user_ip); -- 2.20.1