diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-09-29 22:10:42 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-09-29 22:10:42 +0400 |
commit | f610529d230f080681b6979880225aebc248bf91 (patch) | |
tree | ef468597e2eeb75bc3146e89e49dad69cbc6d0c9 | |
parent | cd41ffe1f1e86891b12878af0d9efcc6f7320f59 (diff) | |
download | mariadb-git-f610529d230f080681b6979880225aebc248bf91.tar.gz |
MDEV-20696 Remove Column_definition::key_length
-rw-r--r-- | sql/field.cc | 8 | ||||
-rw-r--r-- | sql/field.h | 11 | ||||
-rw-r--r-- | sql/sql_table.cc | 8 | ||||
-rw-r--r-- | sql/sql_type.cc | 52 | ||||
-rw-r--r-- | sql/sql_type.h | 11 |
5 files changed, 61 insertions, 29 deletions
diff --git a/sql/field.cc b/sql/field.cc index 8f2312a0ca6..a5d5da5eaca 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10205,13 +10205,11 @@ void Column_definition::create_length_to_internal_length_bit() { if (f_bit_as_char(pack_flag)) { - key_length= pack_length= ((length + 7) & ~7) / 8; + pack_length= ((length + 7) & ~7) / 8; } else { pack_length= (uint) length / 8; - /* We need one extra byte to store the bits we save among the null bits */ - key_length= pack_length + MY_TEST(length & 7); } } @@ -10220,7 +10218,7 @@ void Column_definition::create_length_to_internal_length_newdecimal() { DBUG_ASSERT(length < UINT_MAX32); uint prec= get_decimal_precision((uint)length, decimals, flags & UNSIGNED_FLAG); - key_length= pack_length= my_decimal_get_binary_size(prec, decimals); + pack_length= my_decimal_get_binary_size(prec, decimals); } @@ -10572,7 +10570,6 @@ Column_definition::Column_definition(THD *thd, Field *old_field, field_name= old_field->field_name; flags= old_field->flags; pack_length=old_field->pack_length(); - key_length= old_field->key_length(); set_handler(old_field->type_handler()); comment= old_field->comment; decimals= old_field->decimals(); @@ -10657,7 +10654,6 @@ Column_definition::redefine_stage1_common(const Column_definition *dup_field, schema->default_table_charset; length= dup_field->char_length; pack_length= dup_field->pack_length; - key_length= dup_field->key_length; decimals= dup_field->decimals; unireg_check= dup_field->unireg_check; flags= dup_field->flags; diff --git a/sql/field.h b/sql/field.h index 1ac2c4a7616..981f0fa3be4 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4887,7 +4887,7 @@ public: for most of the types, or of bytes for BLOBs or numeric types. */ uint32 char_length; - uint decimals, flags, pack_length, key_length; + uint decimals, flags, pack_length; List<String> interval_list; engine_option_value *option_list; @@ -4911,7 +4911,7 @@ public: compression_method_ptr(0), comment(null_clex_str), on_update(NULL), invisible(VISIBLE), char_length(0), decimals(0), - flags(0), pack_length(0), key_length(0), + flags(0), pack_length(0), option_list(NULL), vcol_info(0), default_value(0), check_constraint(0), versioning(VERSIONING_NOT_SET), period(NULL) @@ -4924,11 +4924,11 @@ public: void create_length_to_internal_length_null() { DBUG_ASSERT(length == 0); - key_length= pack_length= 0; + pack_length= 0; } void create_length_to_internal_length_simple() { - key_length= pack_length= type_handler()->calc_pack_length((uint32) length); + pack_length= type_handler()->calc_pack_length((uint32) length); } void create_length_to_internal_length_string() { @@ -4936,14 +4936,12 @@ public: if (real_field_type() == MYSQL_TYPE_VARCHAR && compression_method()) length++; set_if_smaller(length, UINT_MAX32); - key_length= (uint) length; pack_length= type_handler()->calc_pack_length((uint32) length); } void create_length_to_internal_length_typelib() { /* Pack_length already calculated in sql_parse.cc */ length*= charset->mbmaxlen; - key_length= pack_length; } bool vers_sys_field() const { @@ -5073,7 +5071,6 @@ public: decimals= other.decimals; flags= other.flags; pack_length= other.pack_length; - key_length= other.key_length; unireg_check= other.unireg_check; interval= other.interval; charset= other.charset; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 13478be4674..4a0ae550234 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4054,7 +4054,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, key_part_info->fieldnr= field; key_part_info->offset= (uint16) sql_field->offset; key_part_info->key_type=sql_field->pack_flag; - uint key_part_length= sql_field->key_length; + uint key_part_length= sql_field->type_handler()-> + calc_key_length(*sql_field); if (column->length) { @@ -4159,7 +4160,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, key_info->flags|= HA_PACK_KEY; } /* Check if the key segment is partial, set the key flag accordingly */ - if (key_part_length != sql_field->key_length && + if (key_part_length != sql_field->type_handler()-> + calc_key_length(*sql_field) && key_part_length != sql_field->type_handler()->max_octet_length()) key_info->flags|= HA_KEY_HAS_PART_KEY_SEG; @@ -4500,7 +4502,7 @@ bool Column_definition::prepare_blob_field(THD *thd) set_handler(Type_handler::blob_type_handler((uint) length)); pack_length= type_handler()->calc_pack_length(0); } - length= key_length= 0; + length= 0; } DBUG_RETURN(0); } diff --git a/sql/sql_type.cc b/sql/sql_type.cc index bc401fbc9a0..5f37851955e 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2920,15 +2920,6 @@ bool Type_handler_bit:: /*************************************************************************/ -void Type_handler_blob_common:: - Column_definition_reuse_fix_attributes(THD *thd, - Column_definition *def, - const Field *field) const -{ - DBUG_ASSERT(def->key_length == 0); -} - - void Type_handler_typelib:: Column_definition_reuse_fix_attributes(THD *thd, Column_definition *def, @@ -3408,6 +3399,49 @@ uint32 Type_handler_enum::calc_pack_length(uint32 length) const /*************************************************************************/ +uint Type_handler::calc_key_length(const Column_definition &def) const +{ + DBUG_ASSERT(def.pack_length == calc_pack_length((uint32) def.length)); + return def.pack_length; +} + +uint Type_handler_bit::calc_key_length(const Column_definition &def) const +{ + if (f_bit_as_char(def.pack_flag)) + return def.pack_length; + /* We need one extra byte to store the bits we save among the null bits */ + return def.pack_length + MY_TEST(def.length & 7); +} + +uint Type_handler_newdecimal::calc_key_length(const Column_definition &def) const +{ + return def.pack_length; +} + +uint +Type_handler_string_result::calc_key_length(const Column_definition &def) const +{ + return (uint) def.length; +} + +uint Type_handler_enum::calc_key_length(const Column_definition &def) const +{ + DBUG_ASSERT(def.interval); + return get_enum_pack_length(def.interval->count); +} + +uint Type_handler_set::calc_key_length(const Column_definition &def) const +{ + DBUG_ASSERT(def.interval); + return get_set_pack_length(def.interval->count); +} + +uint Type_handler_blob_common::calc_key_length(const Column_definition &def) const +{ + return 0; +} + +/*************************************************************************/ Field *Type_handler::make_and_init_table_field(MEM_ROOT *root, const LEX_CSTRING *name, const Record_addr &addr, diff --git a/sql/sql_type.h b/sql/sql_type.h index dff37959892..459904f4ac0 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3645,6 +3645,7 @@ public: virtual uint32 max_display_length(const Item *item) const= 0; virtual uint32 calc_pack_length(uint32 length) const= 0; + virtual uint calc_key_length(const Column_definition &def) const; virtual void Item_update_null_value(Item *item) const= 0; virtual bool Item_save_in_value(THD *thd, Item *item, st_value *value) const= 0; virtual void Item_param_setup_conversion(THD *thd, Item_param *) const {} @@ -4870,6 +4871,7 @@ public: const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const override; bool union_element_finalize(const Item * item) const override; + uint calc_key_length(const Column_definition &def) const override; bool Column_definition_prepare_stage1(THD *thd, MEM_ROOT *mem_root, Column_definition *c, @@ -5405,6 +5407,7 @@ public: uint32 max_display_length(const Item *item) const override; uint32 max_display_length_for_field(const Conv_source &src) const override; uint32 calc_pack_length(uint32 length) const override { return length / 8; } + uint calc_key_length(const Column_definition &def) const override; bool Item_send(Item *item, Protocol *protocol, st_value *buf) const override { return Item_send_str(item, protocol, buf); @@ -6218,6 +6221,7 @@ public: enum_field_types field_type() const override { return MYSQL_TYPE_NEWDECIMAL; } uint32 max_display_length_for_field(const Conv_source &src) const override; uint32 calc_pack_length(uint32 length) const override; + uint calc_key_length(const Column_definition &def) const override; void show_binlog_type(const Conv_source &src, const Field &, String *str) const override; Field *make_conversion_table_field(MEM_ROOT *root, @@ -6501,11 +6505,8 @@ public: return false; // Materialization does not work with BLOB columns } bool is_param_long_data_type() const override { return true; } + uint calc_key_length(const Column_definition &def) const override; bool Column_definition_fix_attributes(Column_definition *c) const override; - void Column_definition_reuse_fix_attributes(THD *thd, - Column_definition *c, - const Field *field) const - override; bool Column_definition_prepare_stage2(Column_definition *c, handler *file, ulonglong table_flags) const override; @@ -6690,6 +6691,7 @@ public: return MYSQL_TYPE_ENUM; } uint32 calc_pack_length(uint32 length) const override; + uint calc_key_length(const Column_definition &def) const override; Field *make_conversion_table_field(MEM_ROOT *root, TABLE *table, uint metadata, const Field *target) @@ -6729,6 +6731,7 @@ public: return MYSQL_TYPE_SET; } uint32 calc_pack_length(uint32 length) const override; + uint calc_key_length(const Column_definition &def) const override; Field *make_conversion_table_field(MEM_ROOT *root, TABLE *table, uint metadata, const Field *target) |