Remove MySQL index aliasing for user_newtalk indexes
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 18 Sep 2019 16:44:15 +0000 (12:44 -0400)
committerMobrovac <mobrovac@wikimedia.org>
Fri, 27 Sep 2019 09:30:31 +0000 (09:30 +0000)
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
includes/db/MWLBFactory.php
includes/installer/MysqlUpdater.php
maintenance/archives/patch-rename-mysql-user_newtalk-indexes.sql [new file with mode: 0644]

index ab51eab..83847d8 100644 (file)
@@ -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 {
index ad5708a..63b320e 100644 (file)
@@ -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
index 7d41d04..a53a72b 100644 (file)
@@ -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 (file)
index 0000000..3177b4d
--- /dev/null
@@ -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);