Hi, Shubham! On Mar 16, Shubham Barai wrote:
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.
Yes. And also for any other UNIQUE constraint that is too long for a normal index. For example, many long VARCHAR columns. But, of course, for a prototype one can start just with blobs.
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.
There's a generic check whether the key is too long. It can be used here, it doesn't depend on the storage engine.
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)
Right.
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.
There's a field 'algorithm' already. Because MI_UNIQUEDEF in MyISAM is, basically, an index of hashed column values, it is kind of a hash index. So you can use algorithm=HA_KEY_ALG_HASH to mark such columns. And the user will be able to create these indexes explicitly with create table table1 (blob_column blob,unique(blob_column) using hash);
Later we can check the flag in table2myisam to see if we want to create MI_KEYDEF or MI_UNIQUEDEF.
Thanks, Shubham.
Very good! Regards, Sergei Chief Architect MariaDB and security@mariadb.org