[Maria-developers] Gsoc 2016 Mdev 371 Unique index for blob
Dear Developers, I was doing prototype for this project as Mr Sergei Golubchik suggested "This task is about creating MI_UNIQUEDEF "uniques" instead of MI_KEYDEF "keys" for long unique constraints." Here is my output MariaDB [sachin]> create table tbl(int_key int primary key , blob_key blob unique); Query OK, 0 rows affected (0.03 sec) MariaDB [sachin]> insert into tbl values(1,1); Query OK, 1 row affected (0.01 sec) MariaDB [sachin]> insert into tbl values(2,1); ERROR 1062 (23000): Duplicate entry '1' for key 'blob_key' MariaDB [sachin]> insert into tbl values(2,2); Query OK, 1 row affected (0.00 sec) MariaDB [sachin]> insert into tbl values(3,3); Query OK, 1 row affected (0.00 sec) MariaDB [sachin]> select * from tbl; +---------+----------+ | int_key | blob_key | +---------+----------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +---------+----------+ 3 rows in set (0.00 sec) I am assuming that unique blob will have 0 zero key . Should i mail you the source code.Please let me know Regards sachin
Sorry one correction @-- I am assuming that unique blob will have 0 zero key @++ I am assuming that unique blob will have 0 zero key length Regards sachin On Tue, Mar 15, 2016 at 11:02 PM, Sachin Setia <sachinsetia1001@gmail.com> wrote:
Dear Developers,
I was doing prototype for this project as Mr Sergei Golubchik suggested
"This task is about creating MI_UNIQUEDEF "uniques" instead of MI_KEYDEF "keys" for long unique constraints."
Here is my output
MariaDB [sachin]> create table tbl(int_key int primary key , blob_key blob unique); Query OK, 0 rows affected (0.03 sec)
MariaDB [sachin]> insert into tbl values(1,1); Query OK, 1 row affected (0.01 sec)
MariaDB [sachin]> insert into tbl values(2,1); ERROR 1062 (23000): Duplicate entry '1' for key 'blob_key' MariaDB [sachin]> insert into tbl values(2,2); Query OK, 1 row affected (0.00 sec)
MariaDB [sachin]> insert into tbl values(3,3); Query OK, 1 row affected (0.00 sec)
MariaDB [sachin]> select * from tbl; +---------+----------+ | int_key | blob_key | +---------+----------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +---------+----------+ 3 rows in set (0.00 sec)
I am assuming that unique blob will have 0 zero key . Should i mail you the source code.Please let me know Regards sachin
Hi, Sachin! On Mar 15, Sachin Setia wrote:
I was doing prototype for this project as Mr Sergei Golubchik suggested
"This task is about creating MI_UNIQUEDEF "uniques" instead of MI_KEYDEF "keys" for long unique constraints."
Here is my output
MariaDB [sachin]> create table tbl(int_key int primary key , blob_key blob unique); Query OK, 0 rows affected (0.03 sec)
MariaDB [sachin]> insert into tbl values(1,1); Query OK, 1 row affected (0.01 sec)
MariaDB [sachin]> insert into tbl values(2,1); ERROR 1062 (23000): Duplicate entry '1' for key 'blob_key'
Very cool!
Should i mail you the source code.Please let me know Regards sachin
Sure! Please, do. Regards, Sergei Chief Architect MariaDB and security@mariadb.org
Thanks sir for your reply I have done two thing 1. First commenting some code to remove the error we get when we try to create unique blob file=sql/sql_table.cc line no=3877 /* * Gsoc 2016 * I am implementing this so comment this stuff out */ // if (!column->length) // { // my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str); // DBUG_RETURN(TRUE); // } 2. here I am assuming this thing for for just prototyping Assumption My table will just contain two column first will be primary key second will be unique blob So basically what i am doing is create a custom unique key and passing it to mi_create Of course in real patching i will replace this code with logic like if i have m unique blobs (i will find this using key_length ==0) create m unique key array and pass it file=storage/myisam/ha_myisam.cc line no=2067 //some tweak in share for prototype share->keys--; share->uniques=1; MI_UNIQUEDEF uniquedef; MI_KEYDEF keydef_blob=*(keydef+1); bzero((char*) &uniquedef,sizeof(uniquedef)); uniquedef.keysegs=1; uniquedef.seg=keydef_blob.seg; uniquedef.null_are_equal=1; /* TODO: Check that the following fn_format is really needed */ error= mi_create(fn_format(buff, name, "", "", MY_UNPACK_FILENAME|MY_APPEND_EXT), share->keys, keydef, record_count, recinfo, 1, &uniquedef, &create_info, create_flags); If i am doing it wrongly please let me know Regards sachin On Wed, Mar 16, 2016 at 12:37 AM, Sergei Golubchik <serg@mariadb.org> wrote:
Hi, Sachin!
On Mar 15, Sachin Setia wrote:
I was doing prototype for this project as Mr Sergei Golubchik suggested
"This task is about creating MI_UNIQUEDEF "uniques" instead of MI_KEYDEF "keys" for long unique constraints."
Here is my output
MariaDB [sachin]> create table tbl(int_key int primary key , blob_key blob unique); Query OK, 0 rows affected (0.03 sec)
MariaDB [sachin]> insert into tbl values(1,1); Query OK, 1 row affected (0.01 sec)
MariaDB [sachin]> insert into tbl values(2,1); ERROR 1062 (23000): Duplicate entry '1' for key 'blob_key'
Very cool!
Should i mail you the source code.Please let me know Regards sachin
Sure! Please, do.
Regards, Sergei Chief Architect MariaDB and security@mariadb.org
Hi, Sachin! On Mar 16, Sachin Setia wrote:
Thanks sir for your reply I have done two thing 1. First commenting some code to remove the error we get when we try to create unique blob file=sql/sql_table.cc line no=3877
It'd be easier to read, if you'd sent a patch instead.
/* * Gsoc 2016 * I am implementing this so comment this stuff out */ // if (!column->length) // { // my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str); // DBUG_RETURN(TRUE); // }
2. here I am assuming this thing for for just prototyping Assumption My table will just contain two column first will be primary key second will be unique blob So basically what i am doing is create a custom unique key and passing it to mi_create Of course in real patching i will replace this code with logic like if i have m unique blobs (i will find this using key_length ==0) create m unique key array and pass it
file=storage/myisam/ha_myisam.cc line no=2067 //some tweak in share for prototype share->keys--; share->uniques=1; MI_UNIQUEDEF uniquedef; MI_KEYDEF keydef_blob=*(keydef+1); bzero((char*) &uniquedef,sizeof(uniquedef)); uniquedef.keysegs=1; uniquedef.seg=keydef_blob.seg; uniquedef.null_are_equal=1;
/* TODO: Check that the following fn_format is really needed */ error= mi_create(fn_format(buff, name, "", "", MY_UNPACK_FILENAME|MY_APPEND_EXT), share->keys, keydef, record_count, recinfo, 1, &uniquedef, &create_info, create_flags);
If i am doing it wrongly please let me know
Looks fine for a prototype. Very good! Regards, Sergei Chief Architect MariaDB and security@mariadb.org
participants (2)
-
Sachin Setia
-
Sergei Golubchik