Rename new_name_timestamp on recentchanges to rc_new_name_timestamp

To make it have a uniform prefix for index and column names

Bug: T270033
Change-Id: I8eb600416913092bd5aeb70389bba6e8a54d1d57
This commit is contained in:
Amir Sarabadani 2021-02-27 19:37:49 +01:00 committed by Ladsgroup
parent 17fbc2856a
commit 1053405664
13 changed files with 684 additions and 11 deletions

View file

@ -257,6 +257,8 @@ class MysqlUpdater extends DatabaseUpdater {
[ 'dropDefault', 'recentchanges', 'rc_timestamp' ],
[ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ],
[ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ],
[ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
'patch-recentchanges-rc_new_name_timestamp.sql' ],
];
}

View file

@ -632,6 +632,8 @@ class PostgresUpdater extends DatabaseUpdater {
[ 'setDefault', 'recentchanges', 'rc_last_oldid', 0 ],
[ 'changeNullableField', 'recentchanges', 'rc_cur_id', 'NOT NULL', true ],
[ 'changeNullableField', 'recentchanges', 'rc_ip', 'NOT NULL', true ],
[ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
'patch-recentchanges-rc_new_name_timestamp.sql' ],
];
}

View file

@ -223,6 +223,8 @@ class SqliteUpdater extends DatabaseUpdater {
[ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
'patch-site_identifiers-rename-indexes.sql' ],
[ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
[ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
'patch-recentchanges-rc_new_name_timestamp.sql' ],
];
}

View file

@ -0,0 +1,621 @@
{
"comment": "Renaming new_name_timestamp index on recentchanges to rc_new_name_timestamp (T270033)",
"before": {
"name": "recentchanges",
"comment": "Primarily a summary table for Special:Recentchanges, this table contains some additional info on edits from the last few days, see Article::editUpdates()",
"columns": [
{
"name": "rc_id",
"type": "integer",
"options": {
"autoincrement": true,
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_timestamp",
"type": "mwtimestamp",
"options": {
"notnull": true,
"length": 14
}
},
{
"name": "rc_actor",
"comment": "As in revision",
"type": "bigint",
"options": {
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_namespace",
"comment": "When pages are renamed, their RC entries do _not_ change.",
"type": "integer",
"options": {
"notnull": true,
"default": 0
}
},
{
"name": "rc_title",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 255
}
},
{
"name": "rc_comment_id",
"comment": "as in revision...",
"type": "bigint",
"options": {
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_minor",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_bot",
"comment": "Edits by user accounts with the 'bot' rights key are marked with a 1 here, and will be hidden from the default view.",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_new",
"comment": "Set if this change corresponds to a page creation",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_cur_id",
"comment": "Key to page_id (was cur_id prior to 1.5). This will keep links working after moves while retaining the at-the-time name in the changes list.",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_this_oldid",
"comment": "rev_id of the given revision",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_last_oldid",
"comment": "rev_id of the prior revision, for generating diff links.",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_type",
"comment": "The type of change entry (RC_EDIT,RC_NEW,RC_LOG,RC_EXTERNAL)",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_source",
"comment": "The source of the change entry (replaces rc_type) default of '' is temporary, needed for initial migration",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 16
}
},
{
"name": "rc_patrolled",
"comment": "If the Recent Changes Patrol option is enabled, users may mark edits as having been reviewed to remove a warning flag on the RC list. A value of 1 indicates the page has been reviewed.",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_ip",
"comment": "Recorded IP address the edit was made from, if the $wgPutIPinRC option is enabled.",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 40
}
},
{
"name": "rc_old_len",
"comment": "Text length in characters before the edit",
"type": "integer",
"options": {
"notnull": false
}
},
{
"name": "rc_new_len",
"comment": "Text length in characters after the edit",
"type": "integer",
"options": {
"notnull": false
}
},
{
"name": "rc_deleted",
"comment": "Visibility of recent changes items, bitfield",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_logid",
"comment": "Value corresponding to log_id, specific log entries",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_log_type",
"comment": "Store log type info here, or null",
"type": "binary",
"options": {
"notnull": false,
"default": null,
"length": 255
}
},
{
"name": "rc_log_action",
"comment": "Store log action or null",
"type": "binary",
"options": {
"notnull": false,
"default": null,
"length": 255
}
},
{
"name": "rc_params",
"comment": "Log params",
"type": "blob",
"options": {
"notnull": false,
"length": 65535
}
}
],
"indexes": [
{
"name": "rc_timestamp",
"comment": "Special:Recentchanges",
"columns": [
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_namespace_title_timestamp",
"comment": "Special:Watchlist",
"columns": [
"rc_namespace",
"rc_title",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_cur_id",
"comment": "Special:Recentchangeslinked when finding changes in pages linked from a page",
"columns": [
"rc_cur_id"
],
"unique": false
},
{
"name": "new_name_timestamp",
"comment": "Special:Newpages",
"columns": [
"rc_new",
"rc_namespace",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_ip",
"comment": "Blank unless $wgPutIPinRC=true (false at WMF), possibly used by extensions, but mostly replaced by CheckUser.",
"columns": [
"rc_ip"
],
"unique": false
},
{
"name": "rc_ns_actor",
"comment": "Probably intended for Special:NewPages namespace filter",
"columns": [
"rc_namespace",
"rc_actor"
],
"unique": false
},
{
"name": "rc_actor",
"comment": "SiteStats active user count, Special:ActiveUsers, Special:NewPages user filter",
"columns": [
"rc_actor",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_name_type_patrolled_timestamp",
"comment": "ApiQueryRecentChanges (T140108)",
"columns": [
"rc_namespace",
"rc_type",
"rc_patrolled",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_this_oldid",
"comment": "Article.php and friends (T139012)",
"columns": [
"rc_this_oldid"
],
"unique": false
}
],
"pk": [
"rc_id"
]
},
"after": {
"name": "recentchanges",
"comment": "Primarily a summary table for Special:Recentchanges, this table contains some additional info on edits from the last few days, see Article::editUpdates()",
"columns": [
{
"name": "rc_id",
"type": "integer",
"options": {
"autoincrement": true,
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_timestamp",
"type": "mwtimestamp",
"options": {
"notnull": true,
"length": 14
}
},
{
"name": "rc_actor",
"comment": "As in revision",
"type": "bigint",
"options": {
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_namespace",
"comment": "When pages are renamed, their RC entries do _not_ change.",
"type": "integer",
"options": {
"notnull": true,
"default": 0
}
},
{
"name": "rc_title",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 255
}
},
{
"name": "rc_comment_id",
"comment": "as in revision...",
"type": "bigint",
"options": {
"unsigned": true,
"notnull": true
}
},
{
"name": "rc_minor",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_bot",
"comment": "Edits by user accounts with the 'bot' rights key are marked with a 1 here, and will be hidden from the default view.",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_new",
"comment": "Set if this change corresponds to a page creation",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_cur_id",
"comment": "Key to page_id (was cur_id prior to 1.5). This will keep links working after moves while retaining the at-the-time name in the changes list.",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_this_oldid",
"comment": "rev_id of the given revision",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_last_oldid",
"comment": "rev_id of the prior revision, for generating diff links.",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_type",
"comment": "The type of change entry (RC_EDIT,RC_NEW,RC_LOG,RC_EXTERNAL)",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_source",
"comment": "The source of the change entry (replaces rc_type) default of '' is temporary, needed for initial migration",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 16
}
},
{
"name": "rc_patrolled",
"comment": "If the Recent Changes Patrol option is enabled, users may mark edits as having been reviewed to remove a warning flag on the RC list. A value of 1 indicates the page has been reviewed.",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_ip",
"comment": "Recorded IP address the edit was made from, if the $wgPutIPinRC option is enabled.",
"type": "binary",
"options": {
"notnull": true,
"default": "",
"length": 40
}
},
{
"name": "rc_old_len",
"comment": "Text length in characters before the edit",
"type": "integer",
"options": {
"notnull": false
}
},
{
"name": "rc_new_len",
"comment": "Text length in characters after the edit",
"type": "integer",
"options": {
"notnull": false
}
},
{
"name": "rc_deleted",
"comment": "Visibility of recent changes items, bitfield",
"type": "mwtinyint",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_logid",
"comment": "Value corresponding to log_id, specific log entries",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true,
"default": 0
}
},
{
"name": "rc_log_type",
"comment": "Store log type info here, or null",
"type": "binary",
"options": {
"notnull": false,
"default": null,
"length": 255
}
},
{
"name": "rc_log_action",
"comment": "Store log action or null",
"type": "binary",
"options": {
"notnull": false,
"default": null,
"length": 255
}
},
{
"name": "rc_params",
"comment": "Log params",
"type": "blob",
"options": {
"notnull": false,
"length": 65535
}
}
],
"indexes": [
{
"name": "rc_timestamp",
"comment": "Special:Recentchanges",
"columns": [
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_namespace_title_timestamp",
"comment": "Special:Watchlist",
"columns": [
"rc_namespace",
"rc_title",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_cur_id",
"comment": "Special:Recentchangeslinked when finding changes in pages linked from a page",
"columns": [
"rc_cur_id"
],
"unique": false
},
{
"name": "rc_new_name_timestamp",
"comment": "Special:Newpages",
"columns": [
"rc_new",
"rc_namespace",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_ip",
"comment": "Blank unless $wgPutIPinRC=true (false at WMF), possibly used by extensions, but mostly replaced by CheckUser.",
"columns": [
"rc_ip"
],
"unique": false
},
{
"name": "rc_ns_actor",
"comment": "Probably intended for Special:NewPages namespace filter",
"columns": [
"rc_namespace",
"rc_actor"
],
"unique": false
},
{
"name": "rc_actor",
"comment": "SiteStats active user count, Special:ActiveUsers, Special:NewPages user filter",
"columns": [
"rc_actor",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_name_type_patrolled_timestamp",
"comment": "ApiQueryRecentChanges (T140108)",
"columns": [
"rc_namespace",
"rc_type",
"rc_patrolled",
"rc_timestamp"
],
"unique": false
},
{
"name": "rc_this_oldid",
"comment": "Article.php and friends (T139012)",
"columns": [
"rc_this_oldid"
],
"unique": false
}
],
"pk": [
"rc_id"
]
}
}

View file

@ -0,0 +1,6 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-recentchanges-rc_new_name_timestamp.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
DROP INDEX new_name_timestamp ON /*_*/recentchanges;
CREATE INDEX rc_new_name_timestamp ON /*_*/recentchanges ( rc_new, rc_namespace, rc_timestamp );

View file

@ -303,7 +303,7 @@ SPARQL;
$it->addJoinConditions( [
'page' => [ 'JOIN', 'rc_cur_id = page_id' ],
] );
$this->addIndex( $it );
$this->addIndex( $it, $dbr );
return $it;
}
@ -330,7 +330,7 @@ SPARQL;
// this means they were restored, thus restoring handler will pick it up.
'NOT EXISTS (SELECT * FROM page WHERE page_id = rc_cur_id)',
] );
$this->addIndex( $it );
$this->addIndex( $it, $dbr );
$it->setFetchColumns( [ 'rc_cur_id', 'rc_title' ] );
$it->setCaller( $fname );
return $it;
@ -353,7 +353,7 @@ SPARQL;
// We will only fetch ones that have page record
'EXISTS (SELECT page_id FROM page WHERE page_id = rc_cur_id)',
] );
$this->addIndex( $it );
$this->addIndex( $it, $dbr );
return $it;
}
@ -371,7 +371,7 @@ SPARQL;
'rc_new' => 0,
'rc_type' => $type,
] );
$this->addIndex( $it );
$this->addIndex( $it, $dbr );
return $it;
}
@ -390,10 +390,15 @@ SPARQL;
/**
* Need to force index, somehow on terbium the optimizer chooses wrong one
* @param BatchRowIterator $it
* @param IDatabase $dbr
*/
private function addIndex( BatchRowIterator $it ) {
private function addIndex( BatchRowIterator $it, IDatabase $dbr ) {
// T270033 'new_name_timestamp' index is being renamed
$indexName = $dbr->indexExists( 'recentchanges', 'rc_new_name_timestamp', __METHOD__ )
? 'rc_new_name_timestamp'
: 'new_name_timestamp';
$it->addOptions( [
'USE INDEX' => [ 'recentchanges' => 'new_name_timestamp' ]
'USE INDEX' => [ 'recentchanges' => $indexName ]
] );
}

View file

@ -0,0 +1,5 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-recentchanges-rc_new_name_timestamp.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
ALTER INDEX new_name_timestamp RENAME TO rc_new_name_timestamp;

View file

@ -828,7 +828,7 @@ CREATE INDEX rc_namespace_title_timestamp ON recentchanges (
CREATE INDEX rc_cur_id ON recentchanges (rc_cur_id);
CREATE INDEX new_name_timestamp ON recentchanges (
CREATE INDEX rc_new_name_timestamp ON recentchanges (
rc_new, rc_namespace, rc_timestamp
);

View file

@ -0,0 +1,31 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-recentchanges-rc_new_name_timestamp.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
DROP INDEX rc_timestamp;
DROP INDEX rc_namespace_title_timestamp;
DROP INDEX rc_cur_id;
DROP INDEX new_name_timestamp;
DROP INDEX rc_ip;
DROP INDEX rc_ns_actor;
DROP INDEX rc_actor;
DROP INDEX rc_name_type_patrolled_timestamp;
DROP INDEX rc_this_oldid;
CREATE TEMPORARY TABLE /*_*/__temp__recentchanges AS
SELECT rc_id, rc_timestamp, rc_actor, rc_namespace, rc_title, rc_comment_id, rc_minor, rc_bot, rc_new, rc_cur_id, rc_this_oldid, rc_last_oldid, rc_type, rc_source, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type, rc_log_action, rc_params
FROM /*_*/recentchanges;
DROP TABLE /*_*/recentchanges;
CREATE TABLE /*_*/recentchanges ( rc_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, rc_timestamp BLOB NOT NULL, rc_actor BIGINT UNSIGNED NOT NULL, rc_namespace INTEGER DEFAULT 0 NOT NULL, rc_title BLOB DEFAULT '' NOT NULL, rc_comment_id BIGINT UNSIGNED NOT NULL, rc_minor SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_bot SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_new SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_cur_id INTEGER UNSIGNED DEFAULT 0 NOT NULL, rc_this_oldid INTEGER UNSIGNED DEFAULT 0 NOT NULL, rc_last_oldid INTEGER UNSIGNED DEFAULT 0 NOT NULL, rc_type SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_source BLOB DEFAULT '' NOT NULL, rc_patrolled SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_ip BLOB DEFAULT '' NOT NULL, rc_old_len INTEGER DEFAULT NULL, rc_new_len INTEGER DEFAULT NULL, rc_deleted SMALLINT UNSIGNED DEFAULT 0 NOT NULL, rc_logid INTEGER UNSIGNED DEFAULT 0 NOT NULL, rc_log_type BLOB DEFAULT NULL, rc_log_action BLOB DEFAULT NULL, rc_params BLOB DEFAULT NULL );
INSERT INTO /*_*/recentchanges ( rc_id, rc_timestamp, rc_actor, rc_namespace, rc_title, rc_comment_id, rc_minor, rc_bot, rc_new, rc_cur_id, rc_this_oldid, rc_last_oldid, rc_type, rc_source, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type, rc_log_action, rc_params )
SELECT rc_id, rc_timestamp, rc_actor, rc_namespace, rc_title, rc_comment_id, rc_minor, rc_bot, rc_new, rc_cur_id, rc_this_oldid, rc_last_oldid, rc_type, rc_source, rc_patrolled, rc_ip, rc_old_len, rc_new_len, rc_deleted, rc_logid, rc_log_type, rc_log_action, rc_params
FROM /*_*/__temp__recentchanges;
DROP TABLE /*_*/__temp__recentchanges;
CREATE INDEX rc_timestamp ON /*_*/recentchanges (rc_timestamp);
CREATE INDEX rc_namespace_title_timestamp ON /*_*/recentchanges ( rc_namespace, rc_title, rc_timestamp );
CREATE INDEX rc_cur_id ON /*_*/recentchanges (rc_cur_id);
CREATE INDEX rc_ip ON /*_*/recentchanges (rc_ip);
CREATE INDEX rc_ns_actor ON /*_*/recentchanges (rc_namespace, rc_actor);
CREATE INDEX rc_actor ON /*_*/recentchanges (rc_actor, rc_timestamp);
CREATE INDEX rc_name_type_patrolled_timestamp ON /*_*/recentchanges ( rc_namespace, rc_type, rc_patrolled, rc_timestamp );
CREATE INDEX rc_this_oldid ON /*_*/recentchanges (rc_this_oldid);
CREATE INDEX rc_new_name_timestamp ON /*_*/recentchanges ( rc_new, rc_namespace, rc_timestamp );

View file

@ -773,7 +773,7 @@ CREATE INDEX rc_namespace_title_timestamp ON /*_*/recentchanges (
CREATE INDEX rc_cur_id ON /*_*/recentchanges (rc_cur_id);
CREATE INDEX new_name_timestamp ON /*_*/recentchanges (
CREATE INDEX rc_new_name_timestamp ON /*_*/recentchanges (
rc_new, rc_namespace, rc_timestamp
);

View file

@ -773,7 +773,7 @@ CREATE TABLE /*_*/recentchanges (
rc_namespace, rc_title, rc_timestamp
),
INDEX rc_cur_id (rc_cur_id),
INDEX new_name_timestamp (
INDEX rc_new_name_timestamp (
rc_new, rc_namespace, rc_timestamp
),
INDEX rc_ip (rc_ip),

View file

@ -3094,7 +3094,7 @@
"unique": false
},
{
"name": "new_name_timestamp",
"name": "rc_new_name_timestamp",
"comment": "Special:Newpages",
"columns": [
"rc_new",

View file

@ -33,7 +33,6 @@ class DatabaseIntegrationTest extends MediaWikiIntegrationTestCase {
'revision_actor_temp',
'change_tag',
'objectcache',
'recentchanges'
];
$prefixes = [];