Schema: Drop unused and useless indexes of sites table

This table has eight indexes plus PK. It has around 1000 rows only. Even
if it needs these indexes (which it doesn't), they are still useless.

Looking at the code, the only potential useful index is the one on
site_global_key, they are showing up in the report of unused indexes in
the db and I checked with Fandom (which might benefit from an index on
this table) and they said they don't use sites table.

Bug: T342856
Change-Id: I06b3db0f33bd35bfa68f4b418d8c2f4b9b988409
This commit is contained in:
Amir Sarabadani 2024-02-01 14:43:22 +01:00
parent 0b52e864b0
commit 616744db1d
11 changed files with 245 additions and 43 deletions

View file

@ -171,6 +171,7 @@ class MysqlUpdater extends DatabaseUpdater {
[ 'addTable', 'block_target', 'patch-block_target.sql' ],
[ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
[ 'runMaintenance', PopulateUserIsTemp::class, 'maintenance/populateUserIsTemp.php' ],
[ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
];
}

View file

@ -471,6 +471,7 @@ class PostgresUpdater extends DatabaseUpdater {
[ 'addTable', 'block_target', 'patch-block_target.sql' ],
[ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
[ 'runMaintenance', PopulateUserIsTemp::class, 'maintenance/populateUserIsTemp.php' ],
[ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
];
}

View file

@ -153,6 +153,7 @@ class SqliteUpdater extends DatabaseUpdater {
[ 'addTable', 'block_target', 'patch-block_target.sql' ],
[ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
[ 'runMaintenance', PopulateUserIsTemp::class, 'maintenance/populateUserIsTemp.php' ],
[ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
];
}

View file

@ -0,0 +1,162 @@
{
"comment": "Drop unused indexes of sites table",
"before": {
"name": "sites",
"comment": "Holds all the sites known to the wiki.",
"columns": [
{
"name": "site_id",
"type": "integer",
"comment": "Numeric id of the site",
"options": { "unsigned": true, "notnull": true, "autoincrement": true }
},
{
"name": "site_global_key",
"type": "binary",
"comment": "Global identifier for the site, ie 'enwiktionary'",
"options": { "notnull": true, "length": 64 }
},
{
"name": "site_type",
"type": "binary",
"comment": "Type of the site, ie 'mediawiki'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_group",
"type": "binary",
"comment": "Group of the site, ie 'wikipedia'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_source",
"type": "binary",
"comment": "Source of the site data, ie 'local', 'wikidata', 'my-magical-repo'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_language",
"type": "binary",
"comment": "Language code of the sites primary language.",
"options": { "notnull": true, "length": 35 }
},
{
"name": "site_protocol",
"type": "binary",
"comment": "Protocol of the site, ie 'http://', 'irc://', '//'. This field is an index for lookups and is build from type specific data in site_data.",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_domain",
"type": "string",
"comment": "Domain of the site in reverse order, ie 'org.mediawiki.www.'. This field is an index for lookups and is build from type specific data in site_data.",
"options": { "notnull": true, "length": 255 }
},
{
"name": "site_data",
"type": "blob",
"comment": "Type dependent site data.",
"options": { "notnull": true, "length": 65530 }
},
{
"name": "site_forward",
"type": "mwtinyint",
"comment": "If site.tld/path/key:pageTitle should forward users to the page on the actual site, where \"key\" is the local identifier.",
"options": { "notnull": true, "length": 1 }
},
{
"name": "site_config",
"type": "blob",
"comment": "Type dependent site config. For instance if template transclusion should be allowed if it's a MediaWiki.",
"options": { "notnull": true, "length": 65530 }
}
],
"indexes": [
{ "name": "site_global_key", "columns": [ "site_global_key" ], "unique": true },
{ "name": "site_type", "columns": [ "site_type" ], "unique": false },
{ "name": "site_group", "columns": [ "site_group" ], "unique": false },
{ "name": "site_source", "columns": [ "site_source" ], "unique": false },
{ "name": "site_language", "columns": [ "site_language" ], "unique": false },
{ "name": "site_protocol", "columns": [ "site_protocol" ], "unique": false },
{ "name": "site_domain", "columns": [ "site_domain" ], "unique": false },
{ "name": "site_forward", "columns": [ "site_forward" ], "unique": false }
],
"pk": [ "site_id" ]
},
"after": {
"name": "sites",
"comment": "Holds all the sites known to the wiki.",
"columns": [
{
"name": "site_id",
"type": "integer",
"comment": "Numeric id of the site",
"options": { "unsigned": true, "notnull": true, "autoincrement": true }
},
{
"name": "site_global_key",
"type": "binary",
"comment": "Global identifier for the site, ie 'enwiktionary'",
"options": { "notnull": true, "length": 64 }
},
{
"name": "site_type",
"type": "binary",
"comment": "Type of the site, ie 'mediawiki'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_group",
"type": "binary",
"comment": "Group of the site, ie 'wikipedia'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_source",
"type": "binary",
"comment": "Source of the site data, ie 'local', 'wikidata', 'my-magical-repo'",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_language",
"type": "binary",
"comment": "Language code of the sites primary language.",
"options": { "notnull": true, "length": 35 }
},
{
"name": "site_protocol",
"type": "binary",
"comment": "Protocol of the site, ie 'http://', 'irc://', '//'. This field is an index for lookups and is build from type specific data in site_data.",
"options": { "notnull": true, "length": 32 }
},
{
"name": "site_domain",
"type": "string",
"comment": "Domain of the site in reverse order, ie 'org.mediawiki.www.'. This field is an index for lookups and is build from type specific data in site_data.",
"options": { "notnull": true, "length": 255 }
},
{
"name": "site_data",
"type": "blob",
"comment": "Type dependent site data.",
"options": { "notnull": true, "length": 65530 }
},
{
"name": "site_forward",
"type": "mwtinyint",
"comment": "If site.tld/path/key:pageTitle should forward users to the page on the actual site, where \"key\" is the local identifier.",
"options": { "notnull": true, "length": 1 }
},
{
"name": "site_config",
"type": "blob",
"comment": "Type dependent site config. For instance if template transclusion should be allowed if it's a MediaWiki.",
"options": { "notnull": true, "length": 65530 }
}
],
"indexes": [
{ "name": "site_global_key", "columns": [ "site_global_key" ], "unique": true }
],
"pk": [ "site_id" ]
}
}

View file

@ -0,0 +1,11 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-sites-drop_indexes.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
DROP INDEX site_type ON /*_*/sites;
DROP INDEX site_group ON /*_*/sites;
DROP INDEX site_source ON /*_*/sites;
DROP INDEX site_language ON /*_*/sites;
DROP INDEX site_protocol ON /*_*/sites;
DROP INDEX site_domain ON /*_*/sites;
DROP INDEX site_forward ON /*_*/sites;

View file

@ -0,0 +1,11 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-sites-drop_indexes.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
DROP INDEX site_type;
DROP INDEX site_group;
DROP INDEX site_source;
DROP INDEX site_language;
DROP INDEX site_protocol;
DROP INDEX site_domain;
DROP INDEX site_forward;

View file

@ -390,20 +390,6 @@ CREATE TABLE sites (
CREATE UNIQUE INDEX site_global_key ON sites (site_global_key);
CREATE INDEX site_type ON sites (site_type);
CREATE INDEX site_group ON sites (site_group);
CREATE INDEX site_source ON sites (site_source);
CREATE INDEX site_language ON sites (site_language);
CREATE INDEX site_protocol ON sites (site_protocol);
CREATE INDEX site_domain ON sites (site_domain);
CREATE INDEX site_forward ON sites (site_forward);
CREATE TABLE user_newtalk (
user_id INT DEFAULT 0 NOT NULL, user_ip TEXT DEFAULT '' NOT NULL,

View file

@ -0,0 +1,57 @@
-- This file is automatically generated using maintenance/generateSchemaChangeSql.php.
-- Source: maintenance/abstractSchemaChanges/patch-sites-drop_indexes.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TEMPORARY TABLE /*_*/__temp__sites AS
SELECT
site_id,
site_global_key,
site_type,
site_group,
site_source,
site_language,
site_protocol,
site_domain,
site_data,
site_forward,
site_config
FROM /*_*/sites;
DROP TABLE /*_*/sites;
CREATE TABLE /*_*/sites (
site_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
site_global_key BLOB NOT NULL,
site_type BLOB NOT NULL,
site_group BLOB NOT NULL,
site_source BLOB NOT NULL,
site_language BLOB NOT NULL,
site_protocol BLOB NOT NULL,
site_domain VARCHAR(255) NOT NULL,
site_data BLOB NOT NULL,
site_forward SMALLINT NOT NULL,
site_config BLOB NOT NULL
);
INSERT INTO /*_*/sites (
site_id, site_global_key, site_type,
site_group, site_source, site_language,
site_protocol, site_domain, site_data,
site_forward, site_config
)
SELECT
site_id,
site_global_key,
site_type,
site_group,
site_source,
site_language,
site_protocol,
site_domain,
site_data,
site_forward,
site_config
FROM
/*_*/__temp__sites;
DROP TABLE /*_*/__temp__sites;
CREATE UNIQUE INDEX site_global_key ON /*_*/sites (site_global_key);

View file

@ -373,20 +373,6 @@ CREATE TABLE /*_*/sites (
CREATE UNIQUE INDEX site_global_key ON /*_*/sites (site_global_key);
CREATE INDEX site_type ON /*_*/sites (site_type);
CREATE INDEX site_group ON /*_*/sites (site_group);
CREATE INDEX site_source ON /*_*/sites (site_source);
CREATE INDEX site_language ON /*_*/sites (site_language);
CREATE INDEX site_protocol ON /*_*/sites (site_protocol);
CREATE INDEX site_domain ON /*_*/sites (site_domain);
CREATE INDEX site_forward ON /*_*/sites (site_forward);
CREATE TABLE /*_*/user_newtalk (
user_id INTEGER UNSIGNED DEFAULT 0 NOT NULL,

View file

@ -344,13 +344,6 @@ CREATE TABLE /*_*/sites (
site_forward TINYINT(1) NOT NULL,
site_config BLOB NOT NULL,
UNIQUE INDEX site_global_key (site_global_key),
INDEX site_type (site_type),
INDEX site_group (site_group),
INDEX site_source (site_source),
INDEX site_language (site_language),
INDEX site_protocol (site_protocol),
INDEX site_domain (site_domain),
INDEX site_forward (site_forward),
PRIMARY KEY(site_id)
) /*$wgDBTableOptions*/;

View file

@ -1158,14 +1158,7 @@
}
],
"indexes": [
{ "name": "site_global_key", "columns": [ "site_global_key" ], "unique": true },
{ "name": "site_type", "columns": [ "site_type" ], "unique": false },
{ "name": "site_group", "columns": [ "site_group" ], "unique": false },
{ "name": "site_source", "columns": [ "site_source" ], "unique": false },
{ "name": "site_language", "columns": [ "site_language" ], "unique": false },
{ "name": "site_protocol", "columns": [ "site_protocol" ], "unique": false },
{ "name": "site_domain", "columns": [ "site_domain" ], "unique": false },
{ "name": "site_forward", "columns": [ "site_forward" ], "unique": false }
{ "name": "site_global_key", "columns": [ "site_global_key" ], "unique": true }
],
"pk": [ "site_id" ]
},