wiki.techinc.nl/maintenance/sqlite/archives/patch-iwlinks-fix-pk.sql
Reedy 0f13fff160 Convert UNIQUE keys into PRIMARY KEY
WMF DBAs have been doing a massive effort to convert UNIQUE KEYS into
PRIMARY KEY.

Having a PK is essential to do maintenance, specially on large tasks.
By not having a PK it is impossible to add it in a safe way if not done
directly on the master.

Having a PK means that we can easily change the PK into another one if
needed in the future. The ones we chose might not be the best ones, but
will allow us to get them changed.

Bug: T172514
Change-Id: Id635297838938c7c5dfe65d45285a4d16d65152d
2017-08-29 18:25:37 +01:00

24 lines
No EOL
756 B
SQL

CREATE TABLE /*_*/iwlinks_tmp (
-- page_id of the referring page
iwl_from int unsigned NOT NULL default 0,
-- Interwiki prefix code of the target
iwl_prefix varbinary(20) NOT NULL default '',
-- Title of the target, including namespace
iwl_title varchar(255) binary NOT NULL default '',
PRIMARY KEY (iwl_from,iwl_prefix,iwl_title)
) /*$wgDBTableOptions*/;
INSERT INTO /*_*/iwlinks_tmp
SELECT * FROM /*_*/iwlinks;
DROP TABLE /*_*/iwlinks;
ALTER TABLE /*_*/iwlinks_tmp RENAME TO /*_*/iwlinks;
-- Index for ApiQueryIWBacklinks
CREATE INDEX /*i*/iwl_prefix_title_from ON /*_*/iwlinks (iwl_prefix, iwl_title, iwl_from);
-- Index for ApiQueryIWLinks
CREATE INDEX /*i*/iwl_prefix_from_title ON /*_*/iwlinks (iwl_prefix, iwl_from, iwl_title);