Hello, Sergie!
I tried to explore the source code from mi_create.c,ha_myisam.cc,sql/sql_table.cc,include/myisam.h,.and some other files.
The main task is to create MI_UNIQUEDEF "uniques" for long unique constraints.
We have to consider all the cases where we need to create MI_UNIQUEDEF instead of MI_KEYDEF.
It will include queries like
create table table1 (blob_column blob,unique(blob_column) );
create table table1 (a int,blob_column blob,unique(a,blob_column) );
create table table1 (a int,blob_column1 blob,blob_column2 blob,unique(blob_column1(300),blob_column2) );
(key with multiple blob columns and one of the blob column specified with prefix length).
I think we have to create MI_UNIQUEDEF if any one of the columns in a key is a blob field without prefix length.
In sql/sql_table, mysql_prepare_create_table is the function which prepares the table and key structures for table creation in mi_create. It generates an error if any one of the blob fields in a key is specified without length.
Currently, this task is limited to MyISAM, so if any other storage engine is selected, we have to generate the same error in mysql_prepare_create_table.
In storage/myisam/ha_myisam.cc, table2myisam is a function which allocates and initializes myisam key and column definitions.The current function prototype of table2myisam is
table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out, MI_COLUMNDEF **recinfo_out, uint records_out)
We have to change it to
table2myisam(TABLE *table_arg,MI_KEYDEF **keydef_out,MI_UNIQUEDEF ** uniquedef_out,MI_COLUMNDEF **recinfo_out,uint records_out)
table2myisam initializes all the key definitions from table_arg->keyinfo.
So we can set a new flag (say uniquedef) in a keyinfo struct in mysql_prepare_create_table if any one of the key_part consists of blob field without prefix length.
Later we can check the flag in table2myisam to see if we want to create MI_KEYDEF or MI_UNIQUEDEF.
Thanks,
Shubham.