Bug #45295 main.plugin does not work with utf8mb3
Submitted: 3 Jun 2009 10:49 Modified: 28 Jun 2009 0:50
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.4 OS:Any
Assigned to: Alexander Nozdrin CPU Architecture:Any

[3 Jun 2009 10:49] Alexander Nozdrin
Description:
mysql.plugin does not work with utf8mb3 character set.

This is a regression caused by the patch for Bug#33731.
In that patch, column data types were changed from 'char'
to 'varchar'. Since WL#1213 was already pushed, everything
worked well with default utf8mb4 character set.

The thing is:
  - if the data type is char, then MyISAM keys are constructed
    in a form of simple string, like 'this is a key value'.
    _mi_pack_key(), which is used to prepare a key for search
    in MyISAM tables works well with such strings.

  - if the data type is varchar MyISAM keys are constructed
    in a form of length-coded-string, like '<key value length><key value>'.

  - if utf8mb4 is used for mysql.plugin, then 2 bytes are used
    to encode the length. This is what _mi_pack_key() expects of
    length-coded-strings.

  - if utf8mb3 is used for mysql.plugin, then 1 byte is used
    to encode the length. This is _not_ what _mi_pack_key() expects,
    so it creates invalid key, which can not be used to obtain a row.

  - the difference 1 byte / 2 bytes comes from this:
    - the mysql.plugin.name column has length of 64 symbols
    - for utf8mb4 that means, the length in bytes is 64 * 4 = 256
    - for utf8mb3 that means, the length in bytes is 64 * 3 = 192
    - the HA_VARCHAR_PACKLENGTH() macro reserves 2 bytes for lengths
      longer than 255 bytes, thus 1 byte for utf8mb3 and 2 bytes
      for utf8mb4.

How to repeat:
1. Change mysql.plugin definition in scripts/mysql_system_tables.sql as follows:

CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci comment='MySQL plugins';

2. Run main.plugin test case.
   The following error will appear:

mysqltest: At line 15: query 'INSTALL PLUGIN example SONAME $HA_EXAMPLE_SO' failed: 1062: Duplicate entry 'example' for key 'PRIMARY'

Suggested fix:
Either rollback the patch for Bug#33731 and fix it differently,
or change length of 'name' column to something greater than 256/3
(like 90), or something else :).
[4 Jun 2009 13:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75618

2796 Alexander Nozdrin	2009-06-04
      Fix for Bug#45295: mysql.plugin does not work with utf8mb3.
      
      The problem is described in the bug report.
      
      The fix is to use Field::new_key_field() method, which is intended
      to return a Field instance which can be used for keys.
[28 Jun 2009 0:50] Paul DuBois
No changelog entry needed.