Commit 3616175f authored by Alexander Barkov's avatar Alexander Barkov

MDEV-20760 Add Type_handler::KEY_pack_flags()

parent c717483c
...@@ -4147,16 +4147,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -4147,16 +4147,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
/* Use packed keys for long strings on the first column */ /* Use packed keys for long strings on the first column */
if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) && if (!((*db_options) & HA_OPTION_NO_PACK_KEYS) &&
!((create_info->table_options & HA_OPTION_NO_PACK_KEYS)) && !((create_info->table_options & HA_OPTION_NO_PACK_KEYS)) &&
(key_part_length >= KEY_DEFAULT_PACK_LENGTH && (key_part_length >= KEY_DEFAULT_PACK_LENGTH) &&
(sql_field->real_field_type() == MYSQL_TYPE_STRING || !is_hash_field_needed)
sql_field->real_field_type() == MYSQL_TYPE_VARCHAR || {
f_is_blob(sql_field->pack_flag))) && !is_hash_field_needed) key_info->flags|= sql_field->type_handler()->KEY_pack_flags(column_nr);
{
if ((column_nr == 0 && f_is_blob(sql_field->pack_flag)) ||
sql_field->real_field_type() == MYSQL_TYPE_VARCHAR)
key_info->flags|= HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
else
key_info->flags|= HA_PACK_KEY;
} }
/* Check if the key segment is partial, set the key flag accordingly */ /* Check if the key segment is partial, set the key flag accordingly */
if (key_part_length != sql_field->type_handler()-> if (key_part_length != sql_field->type_handler()->
......
...@@ -3362,6 +3362,7 @@ class Type_handler ...@@ -3362,6 +3362,7 @@ class Type_handler
virtual const Name version() const; virtual const Name version() const;
virtual const Name &default_value() const= 0; virtual const Name &default_value() const= 0;
virtual uint32 flags() const { return 0; } virtual uint32 flags() const { return 0; }
virtual ulong KEY_pack_flags(uint column_nr) const { return 0; }
bool is_unsigned() const { return flags() & UNSIGNED_FLAG; } bool is_unsigned() const { return flags() & UNSIGNED_FLAG; }
virtual enum_field_types field_type() const= 0; virtual enum_field_types field_type() const= 0;
virtual enum_field_types real_field_type() const { return field_type(); } virtual enum_field_types real_field_type() const { return field_type(); }
...@@ -6410,6 +6411,10 @@ class Type_handler_string: public Type_handler_longstr ...@@ -6410,6 +6411,10 @@ class Type_handler_string: public Type_handler_longstr
virtual ~Type_handler_string() {} virtual ~Type_handler_string() {}
const Name name() const override; const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_STRING; } enum_field_types field_type() const override { return MYSQL_TYPE_STRING; }
ulong KEY_pack_flags(uint column_nr) const override
{
return HA_PACK_KEY;
}
bool is_param_long_data_type() const override { return true; } bool is_param_long_data_type() const override { return true; }
uint32 max_display_length_for_field(const Conv_source &src) const override; uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override { return length; } uint32 calc_pack_length(uint32 length) const override { return length; }
...@@ -6481,6 +6486,12 @@ class Type_handler_varchar: public Type_handler_longstr ...@@ -6481,6 +6486,12 @@ class Type_handler_varchar: public Type_handler_longstr
virtual ~Type_handler_varchar() {} virtual ~Type_handler_varchar() {}
const Name name() const override; const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_VARCHAR; } enum_field_types field_type() const override { return MYSQL_TYPE_VARCHAR; }
ulong KEY_pack_flags(uint column_nr) const override
{
if (column_nr == 0)
return HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
return HA_PACK_KEY;
}
enum_field_types type_code_for_protocol() const override enum_field_types type_code_for_protocol() const override
{ {
return MYSQL_TYPE_VAR_STRING; // Keep things compatible for old clients return MYSQL_TYPE_VAR_STRING; // Keep things compatible for old clients
...@@ -6547,6 +6558,11 @@ class Type_handler_varchar_compressed: public Type_handler_varchar ...@@ -6547,6 +6558,11 @@ class Type_handler_varchar_compressed: public Type_handler_varchar
{ {
return MYSQL_TYPE_VARCHAR_COMPRESSED; return MYSQL_TYPE_VARCHAR_COMPRESSED;
} }
ulong KEY_pack_flags(uint column_nr) const override
{
DBUG_ASSERT(0);
return 0;
}
uint32 max_display_length_for_field(const Conv_source &src) const override; uint32 max_display_length_for_field(const Conv_source &src) const override;
void show_binlog_type(const Conv_source &src, const Field &dst, String *str) void show_binlog_type(const Conv_source &src, const Field &dst, String *str)
const override; const override;
...@@ -6567,6 +6583,12 @@ class Type_handler_blob_common: public Type_handler_longstr ...@@ -6567,6 +6583,12 @@ class Type_handler_blob_common: public Type_handler_longstr
public: public:
virtual ~Type_handler_blob_common() { } virtual ~Type_handler_blob_common() { }
virtual uint length_bytes() const= 0; virtual uint length_bytes() const= 0;
ulong KEY_pack_flags(uint column_nr) const override
{
if (column_nr == 0)
return HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY;
return HA_PACK_KEY;
}
Field *make_conversion_table_field(MEM_ROOT *root, Field *make_conversion_table_field(MEM_ROOT *root,
TABLE *table, uint metadata, TABLE *table, uint metadata,
const Field *target) const override; const Field *target) const override;
...@@ -6713,6 +6735,11 @@ class Type_handler_blob_compressed: public Type_handler_blob ...@@ -6713,6 +6735,11 @@ class Type_handler_blob_compressed: public Type_handler_blob
{ {
return MYSQL_TYPE_BLOB_COMPRESSED; return MYSQL_TYPE_BLOB_COMPRESSED;
} }
ulong KEY_pack_flags(uint column_nr) const override
{
DBUG_ASSERT(0);
return 0;
}
uint32 max_display_length_for_field(const Conv_source &src) const override; uint32 max_display_length_for_field(const Conv_source &src) const override;
void show_binlog_type(const Conv_source &src, const Field &, String *str) void show_binlog_type(const Conv_source &src, const Field &, String *str)
const override; const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment