Page MenuHomePhabricator

[GlobalUsage] patches/GlobalUsage.sql : Error: 1071 Specified key was too long; max key length is 767 bytes
Closed, DeclinedPublic

Description

When running MySQL/MariaDB with charset utf8mb4, a character is 4 bytes. Hence a key created on a VARCHAR(255) takes 255 characters * 4 bytes/characters = 1020 bytes. However Innodb defaults to a maximum of 767 bytes for an index.

The extension fails to install on Debian Stretch which uses utf8mb4 as the default charset:

Query: CREATE UNIQUE INDEX globalimagelinks_to_wiki_page
 ON `globalimagelinks` (gil_to, gil_wiki, gil_page)
 
Function: Wikimedia\Rdbms\Database::sourceFile( /workspace/src/extensions/GlobalUsage/patches/GlobalUsage.sql )
Error: 1071 Specified key was too long; max key length is 767 bytes (localhost:/tmp/quibble-mysql-deferw2q/socket)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Vvjjkkii renamed this task from [GlobalUsage] patches/GlobalUsage.sql : Error: 1071 Specified key was too long; max key length is 767 bytes to 0udaaaaaaa.Jul 1 2018, 1:12 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
Mainframe98 renamed this task from 0udaaaaaaa to [GlobalUsage] patches/GlobalUsage.sql : Error: 1071 Specified key was too long; max key length is 767 bytes.Jul 1 2018, 11:42 AM
Mainframe98 updated the task description. (Show Details)
Mainframe98 added a subscriber: Aklapper.
Ankry raised the priority of this task from High to Needs Triage.Jul 2 2018, 3:26 PM

The issue was that MediaWiki did not define a default charset it thus used whatever the MySQL server has. On Debian Jessie it used to be Latin1, on Debian Stretch that got changed to utf8mb4.

Eventually that got addressed by https://gerrit.wikimedia.org/r/c/mediawiki/core/+/461279 which now defaults to a binary charset:

--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -1931,7 +1931,7 @@ $wgDBprefix = '';
 /**
  * MySQL table options to use during installation or update
  */
-$wgDBTableOptions = 'ENGINE=InnoDB';
+$wgDBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=binary';

See T193222#4247329 and following comments for more details.