diff options
author | Sachin <sachin.setiya@mariadb.com> | 2019-02-20 02:53:08 +0530 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-02-22 00:35:40 +0100 |
commit | d00f19e8325cd2f4beb10cc89f25ada8434099db (patch) | |
tree | d09ee2cc68ef9d7db9c9e7f6fdf175ef9597c647 /mysql-test/main/long_unique_debug.test | |
parent | 5b4d6595d26aaaf0bf8bb3c9171cf1da96306a7c (diff) | |
download | mariadb-git-d00f19e8325cd2f4beb10cc89f25ada8434099db.tar.gz |
MDEV-371 Unique Index for long columns
This patch implements engine independent unique hash index.
Usage:- Unique HASH index can be created automatically for blob/varchar/test column whose key
length > handler->max_key_length()
or it can be explicitly specified.
Automatic Creation:-
Create TABLE t1 (a blob unique);
Explicit Creation:-
Create TABLE t1 (a int , unique(a) using HASH);
Internal KEY_PART Representations:-
Long unique key_info will have 2 representations.
(lets understand this with an example create table t1(a blob, b blob , unique(a, b)); )
1. User Given Representation:- key_info->key_part array will be similar to what user has defined.
So in case of example it will have 2 key_parts (a, b)
2. Storage Engine Representation:- In this case there will be only one key_part and it will point to
HASH_FIELD. This key_part will be always after user defined key_parts.
So:- User Given Representation [a] [b] [hash_key_part]
key_info->key_part ----^
Storage Engine Representation [a] [b] [hash_key_part]
key_info->key_part ------------^
Table->s->key_info will have User Given Representation, While table->key_info will have Storage Engine
Representation.Representation can be changed into each other by calling re/setup_keyinfo_hash function.
Working:-
1. So when user specifies HASH_INDEX or key_length is > handler->max_key_length(), In mysql_prepare_create_table
One extra vfield is added (for each long unique key). And key_info->algorithm is set to HA_KEY_ALG_LONG_HASH.
2. In init_from_binary_frm_image values for hash_keypart is set (like fieldnr , field and flags)
3. In parse_vcol_defs, HASH_FIELD->vcol_info is created. Item_func_hash is used with list of Item_fields,
When Explicit length is given by user then Item_left is used to concatenate Item_field values.
4. In ha_write_row/ha_update_row check_duplicate_long_entry_key is called which will create the hash key from
table->record[0] and then call ha_index_read_map , if we found duplicated hash , we will compare the result
field by field.
Diffstat (limited to 'mysql-test/main/long_unique_debug.test')
-rw-r--r-- | mysql-test/main/long_unique_debug.test | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/mysql-test/main/long_unique_debug.test b/mysql-test/main/long_unique_debug.test new file mode 100644 index 00000000000..63ebfa89b48 --- /dev/null +++ b/mysql-test/main/long_unique_debug.test @@ -0,0 +1,91 @@ +--source include/have_debug.inc +--source include/have_innodb.inc +--echo #In this test case we will check what will happen in the case of hash collision + +SET debug_dbug="d,same_long_unique_hash"; +create table t1(a blob unique); + +FLUSH STATUS; +insert into t1 values('xyz'); +insert into t1 values('abc'); +insert into t1 values('sachin'); +--error ER_DUP_ENTRY +insert into t1 values('sachin'); +insert into t1 values('maria'); +--error ER_DUP_ENTRY +insert into t1 values('maria'); +drop table t1; +SHOW STATUS LIKE 'handler_read_next'; + +SET debug_dbug=""; +create table t1(a blob unique); +FLUSH STATUS; + +insert into t1 values('xyz'); +insert into t1 values('abc'); +insert into t1 values('sachin'); +--error ER_DUP_ENTRY +insert into t1 values('sachin'); +insert into t1 values('maria'); +--error ER_DUP_ENTRY +insert into t1 values('maria'); +drop table t1; +SHOW STATUS LIKE 'handler_read_next'; + +SET debug_dbug="d,same_long_unique_hash"; +create table t1(a blob unique, b blob unique); + +insert into t1 values('xyz', 11); +insert into t1 values('abc', 22); +insert into t1 values('sachin', 1); +--error ER_DUP_ENTRY +insert into t1 values('sachin', 4); +insert into t1 values('maria', 2); +--error ER_DUP_ENTRY +insert into t1 values('maria', 3); +drop table t1; + +create table t1(a blob , b blob , unique(a,b)); + +insert into t1 values('xyz', 11); +insert into t1 values('abc', 22); +insert into t1 values('sachin', 1); +--error ER_DUP_ENTRY +insert into t1 values('sachin', 1); +insert into t1 values('maria', 2); +--error ER_DUP_ENTRY +insert into t1 values('maria', 2); +drop table t1; + +--echo ##Internal State of long unique tables +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1 ( a blob unique); +SET debug_dbug=""; +drop table t1; + +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1 ( a blob unique, b blob unique , c blob unique); +SET debug_dbug=""; +drop table t1; + +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1 ( a blob , b blob , c blob , d blob , unique (a,b), unique(c, d)); +SET debug_dbug=""; +drop table t1; + +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1(a int primary key, b blob unique , c blob unique not null); +SET debug_dbug=""; +drop table t1; + +--echo ##Using hash +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1(a int ,b int , c int, unique(a, b, c) using hash); +SET debug_dbug=""; +drop table t1; + +--echo ##Using hash but with memory engine so no long unique column +SET debug_dbug="d,print_long_unique_internal_state"; +create table t1(a int ,b int , c int, unique(a, b, c) using hash) engine=memory; +SET debug_dbug=""; +drop table t1; |