From f6000782fbcd8c0576cb89737ad66902f6113966 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 22 Feb 2019 11:56:13 +0100 Subject: [PATCH] mysql_prepare_create_table() inconsistency sql_field->key_length was 0 for blob fields when a field was being added, but Field_blob::character_octet_length() on subsequent ALTER TABLE's (when the Field object in the old table already existed). This means mysql_prepare_create_table() couldn't reliably detect if the keyseg was a prefix. --- sql/sql_table.cc | 5 +++-- sql/sql_type.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1f00c4c95cb..47a82295719 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4135,7 +4135,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->key_length && + key_part_length != sql_field->type_handler()->max_octet_length()) key_info->flags|= HA_KEY_HAS_PART_KEY_SEG; key_length+= key_part_length; @@ -4482,7 +4483,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= 0; + length= key_length= 0; } DBUG_RETURN(0); } diff --git a/sql/sql_type.h b/sql/sql_type.h index 23a3f7fccb7..b3e6ae9e622 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3228,6 +3228,7 @@ public: { return false; } + virtual uint max_octet_length() const { return 0; } /** Prepared statement long data: Check whether this parameter data type is compatible with long data. @@ -5864,6 +5865,7 @@ public: const Record_addr &addr, const Type_all_attributes &attr, TABLE *table) const; + uint max_octet_length() const { return UINT_MAX8; } }; @@ -5879,6 +5881,7 @@ public: const Record_addr &addr, const Type_all_attributes &attr, TABLE *table) const; + uint max_octet_length() const { return UINT_MAX24; } }; @@ -5896,6 +5899,7 @@ public: const Record_addr &addr, const Type_all_attributes &attr, TABLE *table) const; + uint max_octet_length() const { return UINT_MAX32; } }; @@ -5911,6 +5915,7 @@ public: const Record_addr &addr, const Type_all_attributes &attr, TABLE *table) const; + uint max_octet_length() const { return UINT_MAX16; } };