Bug #40026 CREATE INDEX not online when using utf8 columns
Submitted: 14 Oct 2008 16:20 Modified: 14 Oct 2008 20:37
Reporter: Tim Clark Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: DDL Severity:S2 (Serious)
Version:5.1.26 OS:Any
Assigned to: CPU Architecture:Any
Tags: alter, create index, online, utf8

[14 Oct 2008 16:20] Tim Clark
Description:
When using a storage engine capable of adding indexes online (without recreating the table), tables with utf8 character sets do not honor the online alter capability.

The problem appears to be this: In comparing the sets of old and new fields to determine whether an online alter is possible, the length of the new utf8 field is calculated as characters, not bytes. However, the existing field's length is in bytes. Thus, in sql_table.cc::compare_tables(), when the old and new fields are compared, the fields are determined to be not equal, and a full alter is required.

How to repeat:
This was discovered while using the IMBDB2I storage engine, which is under development, but the incorrect behavior can be observed with any storage engine under debug.

Set a breakpoint in sql_table.cc::compare_tables() and observe the value returned in need_copy_table.

Compare:
create table t1 (s1 char(5) character set latin1 collate latin1_swedish_ci);
create index it1 on t1(s1);
>> need_copy_table == ALTER_TABLE_INDEX_CHANGED

to:
create table t1 (s1 char(5) character set utf8 collate utf8_unicode_ci);
create index it1 on t1 (s1);
>> need_copy_table == ALTER_TABLE_DATA_CHANGED

Suggested fix:
Correct the new field information used by mysql_alter_table so that it reflects the length of columns in bytes.
[14 Oct 2008 20:37] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior with current development sources, although bug is repeatable with version 5.1.28. Please wait next release.