Fixed access to unitialized memory when using unique HASH key
Fixed the following issues: - Call info with HA_STATUS_CONST to ensure that (key_info->rec_per_key) contains latest data - Don't access rec_per_key if key_info->algorithm == HA_KEY_ALG_LONG_HASH is in this case the rec_per_key points to uninitialized data - Cleaned up code to avoid some extra 'if' and to make things more readable - Updated test cases that used 'old' rec_per_key values
This commit is contained in:
parent
2dbe472ed0
commit
c4fd167d5a
@ -1,5 +1,5 @@
|
|||||||
cardinality
|
cardinality
|
||||||
10
|
2
|
||||||
Table Op Msg_type Msg_text
|
Table Op Msg_type Msg_text
|
||||||
test.bug57252 analyze status Engine-independent statistics collected
|
test.bug57252 analyze status Engine-independent statistics collected
|
||||||
test.bug57252 analyze status OK
|
test.bug57252 analyze status OK
|
||||||
|
@ -6636,6 +6636,7 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
|
|||||||
{
|
{
|
||||||
show_table->file->info(HA_STATUS_VARIABLE |
|
show_table->file->info(HA_STATUS_VARIABLE |
|
||||||
HA_STATUS_NO_LOCK |
|
HA_STATUS_NO_LOCK |
|
||||||
|
HA_STATUS_CONST |
|
||||||
HA_STATUS_TIME);
|
HA_STATUS_TIME);
|
||||||
set_statistics_for_table(thd, show_table);
|
set_statistics_for_table(thd, show_table);
|
||||||
}
|
}
|
||||||
@ -6670,18 +6671,23 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
|
|||||||
"D" : "A"), 1, cs);
|
"D" : "A"), 1, cs);
|
||||||
table->field[8]->set_notnull();
|
table->field[8]->set_notnull();
|
||||||
}
|
}
|
||||||
KEY *key=show_table->key_info+i;
|
if (key_info->algorithm == HA_KEY_ALG_LONG_HASH)
|
||||||
if (key->rec_per_key[j] && key->algorithm != HA_KEY_ALG_LONG_HASH)
|
|
||||||
{
|
|
||||||
ha_rows records= (ha_rows) ((double) show_table->stat_records() /
|
|
||||||
key->actual_rec_per_key(j));
|
|
||||||
table->field[9]->store((longlong) records, TRUE);
|
|
||||||
table->field[9]->set_notnull();
|
|
||||||
}
|
|
||||||
if (key->algorithm == HA_KEY_ALG_LONG_HASH)
|
|
||||||
table->field[13]->store(STRING_WITH_LEN("HASH"), cs);
|
table->field[13]->store(STRING_WITH_LEN("HASH"), cs);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
We have to use table key information to get the key statistics
|
||||||
|
from table as key_info points to TABLE_SHARE which has no
|
||||||
|
statistics.
|
||||||
|
*/
|
||||||
|
KEY *key_info= show_table->key_info + i;
|
||||||
|
if (key_info->rec_per_key[j])
|
||||||
|
{
|
||||||
|
ha_rows records= (ha_rows) ((double) show_table->stat_records() /
|
||||||
|
key_info->actual_rec_per_key(j));
|
||||||
|
table->field[9]->store((longlong) records, TRUE);
|
||||||
|
table->field[9]->set_notnull();
|
||||||
|
}
|
||||||
const char *tmp= show_table->file->index_type(i);
|
const char *tmp= show_table->file->index_type(i);
|
||||||
table->field[13]->store(tmp, strlen(tmp), cs);
|
table->field[13]->store(tmp, strlen(tmp), cs);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,6 @@ test.t analyze status OK
|
|||||||
show indexes from t;
|
show indexes from t;
|
||||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
|
||||||
t 0 PRIMARY 1 id A 7 NULL NULL BTREE
|
t 0 PRIMARY 1 id A 7 NULL NULL BTREE
|
||||||
t 1 x 1 x A 7 NULL NULL YES BTREE
|
t 1 x 1 x A 3 NULL NULL YES BTREE
|
||||||
set @@use_stat_tables = @save_use_stat_tables;
|
set @@use_stat_tables = @save_use_stat_tables;
|
||||||
drop table t;
|
drop table t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user