mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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.
This commit is contained in:
@@ -323,7 +323,10 @@ enum enum_alter_inplace_result {
|
||||
/** whether every data field explicitly stores length
|
||||
(holds for InnoDB ROW_FORMAT=REDUNDANT) */
|
||||
#define HA_EXTENDED_TYPES_CONVERSION (1ULL << 57)
|
||||
#define HA_LAST_TABLE_FLAG HA_EXTENDED_TYPES_CONVERSION
|
||||
|
||||
/* Support native hash index */
|
||||
#define HA_CAN_HASH_KEYS (1ULL << 58)
|
||||
#define HA_LAST_TABLE_FLAG HA_CAN_HASH_KEYS
|
||||
|
||||
/* bits in index_flags(index_number) for what you can do with index */
|
||||
#define HA_READ_NEXT 1 /* TODO really use this flag */
|
||||
@@ -3128,7 +3131,7 @@ public:
|
||||
check_table_binlog_row_based_done(0),
|
||||
check_table_binlog_row_based_result(0),
|
||||
row_already_logged(0),
|
||||
in_range_check_pushed_down(FALSE),
|
||||
in_range_check_pushed_down(FALSE), errkey(-1),
|
||||
key_used_on_scan(MAX_KEY),
|
||||
active_index(MAX_KEY), keyread(MAX_KEY),
|
||||
ref_length(sizeof(my_off_t)),
|
||||
|
Reference in New Issue
Block a user