summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2021-01-29 00:27:19 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2021-01-30 14:41:43 +0530
commitb87c342da5e51e112e06b36d8b95037f182bdb0e (patch)
tree2703129479836c5322303591becc3b77d20209e8 /sql
parent0921656734c25143d6070a75a1cbbee58fa42753 (diff)
downloadmariadb-git-b87c342da5e51e112e06b36d8b95037f182bdb0e.tar.gz
MDEV-11172: EXPLAIN shows non-sensical value for key_len with type=index
The issue happens when the secondary keys are extended with primary key parts. Inside the function TABLE_SHARE::init_from_binary_frm_image() adds the length bytes for the primary key key parts to the length of the secondary key. This is not needed because when the extended keys are used we recalculate the length for the used key parts. Also removed TABLE_SHARE::total_key_length as it is not used in the code Apporved-by: Monty <monty@mariadb.org>
Diffstat (limited to 'sql')
-rw-r--r--sql/structs.h2
-rw-r--r--sql/table.cc10
-rw-r--r--sql/table.h2
3 files changed, 10 insertions, 4 deletions
diff --git a/sql/structs.h b/sql/structs.h
index 67fb0d5dd66..27b9725815b 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -90,7 +90,7 @@ class engine_option_value;
struct ha_index_option_struct;
typedef struct st_key {
- uint key_length; /* Tot length of key */
+ uint key_length; /* total length of user defined key parts */
ulong flags; /* dupp key and pack flags */
uint user_defined_key_parts; /* How many key_parts */
uint usable_key_parts; /* Should normally be = user_defined_key_parts */
diff --git a/sql/table.cc b/sql/table.cc
index e4492f21a30..1004f583448 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2273,6 +2273,12 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
key_part->null_bit= field->null_bit;
key_part->store_length+=HA_KEY_NULL_LENGTH;
keyinfo->flags|=HA_NULL_PART_KEY;
+
+ /*
+ This branch is executed only for user defined key parts of the
+ secondary indexes.
+ */
+ DBUG_ASSERT(i < keyinfo->user_defined_key_parts);
keyinfo->key_length+= HA_KEY_NULL_LENGTH;
}
if (field->type() == MYSQL_TYPE_BLOB ||
@@ -2285,7 +2291,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
else
key_part->key_part_flag|= HA_VAR_LENGTH_PART;
key_part->store_length+=HA_KEY_BLOB_LENGTH;
- keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
+ if (i < keyinfo->user_defined_key_parts)
+ keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
}
if (field->type() == MYSQL_TYPE_BIT)
key_part->key_part_flag|= HA_BIT_PART;
@@ -2378,7 +2385,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
set_if_bigger(share->max_key_length,keyinfo->key_length+
keyinfo->user_defined_key_parts);
- share->total_key_length+= keyinfo->key_length;
/*
MERGE tables do not have unique indexes. But every key could be
an unique index on the underlying MyISAM table. (Bug #10400)
diff --git a/sql/table.h b/sql/table.h
index a5d412c2c08..83c72f76831 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -773,7 +773,7 @@ struct TABLE_SHARE
uint rec_buff_length; /* Size of table->record[] buffer */
uint keys, key_parts;
uint ext_key_parts; /* Total number of key parts in extended keys */
- uint max_key_length, max_unique_length, total_key_length;
+ uint max_key_length, max_unique_length;
uint uniques; /* Number of UNIQUE index */
uint db_create_options; /* Create options from database */
uint db_options_in_use; /* Options in use */