wiki.techinc.nl/maintenance/sqlite/archives/patch-text-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

37 lines
No EOL
1.7 KiB
SQL

CREATE TABLE /*_*/text_tmp (
-- Unique text storage key number.
-- Note that the 'oldid' parameter used in URLs does *not*
-- refer to this number anymore, but to rev_id.
--
-- revision.rev_text_id is a key to this column
old_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
-- Depending on the contents of the old_flags field, the text
-- may be convenient plain text, or it may be funkily encoded.
old_text mediumblob NOT NULL,
-- Comma-separated list of flags:
-- gzip: text is compressed with PHP's gzdeflate() function.
-- utf-8: text was stored as UTF-8.
-- If $wgLegacyEncoding option is on, rows *without* this flag
-- will be converted to UTF-8 transparently at load time. Note
-- that due to a bug in a maintenance script, this flag may
-- have been stored as 'utf8' in some cases (T18841).
-- object: text field contained a serialized PHP object.
-- The object either contains multiple versions compressed
-- together to achieve a better compression ratio, or it refers
-- to another row where the text can be found.
-- external: text was stored in an external location specified by old_text.
-- Any additional flags apply to the data stored at that URL, not
-- the URL itself. The 'object' flag is *not* set for URLs of the
-- form 'DB://cluster/id/itemid', because the external storage
-- system itself decompresses these.
old_flags tinyblob NOT NULL
) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=10240;
INSERT INTO /*_*/text_tmp
SELECT * FROM /*_*/text;
DROP TABLE /*_*/text;
ALTER TABLE /*_*/text_tmp RENAME TO /*_*/text;