|
|
|
@ -1042,15 +1042,15 @@ public: |
|
|
|
|
|
|
|
void store_stat_fields() |
|
|
|
{ |
|
|
|
char buff[MAX_FIELD_WIDTH]; |
|
|
|
String val(buff, sizeof(buff), &my_charset_bin); |
|
|
|
StringBuffer<MAX_FIELD_WIDTH> val; |
|
|
|
|
|
|
|
MY_BITMAP *old_map= dbug_tmp_use_all_columns(stat_table, &stat_table->read_set); |
|
|
|
|
|
|
|
for (uint i= COLUMN_STAT_MIN_VALUE; i <= COLUMN_STAT_HISTOGRAM; i++) |
|
|
|
{ |
|
|
|
Field *stat_field= stat_table->field[i]; |
|
|
|
if (table_field->collected_stats->is_null(i)) |
|
|
|
Column_statistics *stats= table_field->collected_stats; |
|
|
|
if (stats->is_null(i)) |
|
|
|
stat_field->set_null(); |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -1058,10 +1058,10 @@ public: |
|
|
|
switch (i) { |
|
|
|
case COLUMN_STAT_MIN_VALUE: |
|
|
|
if (table_field->type() == MYSQL_TYPE_BIT) |
|
|
|
stat_field->store(table_field->collected_stats->min_value->val_int(),true); |
|
|
|
stat_field->store(stats->min_value->val_int(),true); |
|
|
|
else |
|
|
|
{ |
|
|
|
table_field->collected_stats->min_value->val_str(&val); |
|
|
|
stats->min_value->val_str(&val); |
|
|
|
uint32 length= Well_formed_prefix(val.charset(), val.ptr(), |
|
|
|
MY_MIN(val.length(), stat_field->field_length)).length(); |
|
|
|
stat_field->store(val.ptr(), length, &my_charset_bin); |
|
|
|
@ -1069,37 +1069,33 @@ public: |
|
|
|
break; |
|
|
|
case COLUMN_STAT_MAX_VALUE: |
|
|
|
if (table_field->type() == MYSQL_TYPE_BIT) |
|
|
|
stat_field->store(table_field->collected_stats->max_value->val_int(),true); |
|
|
|
stat_field->store(stats->max_value->val_int(),true); |
|
|
|
else |
|
|
|
{ |
|
|
|
table_field->collected_stats->max_value->val_str(&val); |
|
|
|
stats->max_value->val_str(&val); |
|
|
|
uint32 length= Well_formed_prefix(val.charset(), val.ptr(), |
|
|
|
MY_MIN(val.length(), stat_field->field_length)).length(); |
|
|
|
stat_field->store(val.ptr(), length, &my_charset_bin); |
|
|
|
} |
|
|
|
break; |
|
|
|
case COLUMN_STAT_NULLS_RATIO: |
|
|
|
stat_field->store(table_field->collected_stats->get_nulls_ratio()); |
|
|
|
stat_field->store(stats->get_nulls_ratio()); |
|
|
|
break; |
|
|
|
case COLUMN_STAT_AVG_LENGTH: |
|
|
|
stat_field->store(table_field->collected_stats->get_avg_length()); |
|
|
|
stat_field->store(stats->get_avg_length()); |
|
|
|
break; |
|
|
|
case COLUMN_STAT_AVG_FREQUENCY: |
|
|
|
stat_field->store(table_field->collected_stats->get_avg_frequency()); |
|
|
|
stat_field->store(stats->get_avg_frequency()); |
|
|
|
break; |
|
|
|
case COLUMN_STAT_HIST_SIZE: |
|
|
|
stat_field->store(table_field->collected_stats->histogram.get_size()); |
|
|
|
stat_field->store(stats->histogram.get_size()); |
|
|
|
break; |
|
|
|
case COLUMN_STAT_HIST_TYPE: |
|
|
|
stat_field->store(table_field->collected_stats->histogram.get_type() + |
|
|
|
1); |
|
|
|
stat_field->store(stats->histogram.get_type() + 1); |
|
|
|
break; |
|
|
|
case COLUMN_STAT_HISTOGRAM: |
|
|
|
const char * col_histogram= |
|
|
|
(const char *) (table_field->collected_stats->histogram.get_values()); |
|
|
|
stat_field->store(col_histogram, |
|
|
|
table_field->collected_stats->histogram.get_size(), |
|
|
|
&my_charset_bin); |
|
|
|
stat_field->store((char *)stats->histogram.get_values(), |
|
|
|
stats->histogram.get_size(), &my_charset_bin); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -2100,20 +2096,24 @@ void create_min_max_statistical_fields_for_table_share(THD *thd, |
|
|
|
int alloc_statistics_for_table(THD* thd, TABLE *table) |
|
|
|
{ |
|
|
|
Field **field_ptr; |
|
|
|
uint fields; |
|
|
|
|
|
|
|
DBUG_ENTER("alloc_statistics_for_table"); |
|
|
|
|
|
|
|
uint columns= 0; |
|
|
|
for (field_ptr= table->field; *field_ptr; field_ptr++) |
|
|
|
{ |
|
|
|
if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) |
|
|
|
columns++; |
|
|
|
} |
|
|
|
|
|
|
|
Table_statistics *table_stats= |
|
|
|
(Table_statistics *) alloc_root(&table->mem_root, |
|
|
|
sizeof(Table_statistics)); |
|
|
|
|
|
|
|
fields= table->s->fields ; |
|
|
|
Column_statistics_collected *column_stats= |
|
|
|
(Column_statistics_collected *) alloc_root(&table->mem_root, |
|
|
|
sizeof(Column_statistics_collected) * |
|
|
|
(fields+1)); |
|
|
|
columns); |
|
|
|
|
|
|
|
uint keys= table->s->keys; |
|
|
|
Index_statistics *index_stats= |
|
|
|
@ -2124,12 +2124,6 @@ int alloc_statistics_for_table(THD* thd, TABLE *table) |
|
|
|
ulonglong *idx_avg_frequency= (ulonglong*) alloc_root(&table->mem_root, |
|
|
|
sizeof(ulonglong) * key_parts); |
|
|
|
|
|
|
|
uint columns= 0; |
|
|
|
for (field_ptr= table->field; *field_ptr; field_ptr++) |
|
|
|
{ |
|
|
|
if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) |
|
|
|
columns++; |
|
|
|
} |
|
|
|
uint hist_size= thd->variables.histogram_size; |
|
|
|
Histogram_type hist_type= (Histogram_type) (thd->variables.histogram_type); |
|
|
|
uchar *histogram= NULL; |
|
|
|
@ -2151,9 +2145,9 @@ int alloc_statistics_for_table(THD* thd, TABLE *table) |
|
|
|
table_stats->idx_avg_frequency= idx_avg_frequency; |
|
|
|
table_stats->histograms= histogram; |
|
|
|
|
|
|
|
memset(column_stats, 0, sizeof(Column_statistics) * (fields+1)); |
|
|
|
memset(column_stats, 0, sizeof(Column_statistics) * columns); |
|
|
|
|
|
|
|
for (field_ptr= table->field; *field_ptr; field_ptr++, column_stats++) |
|
|
|
for (field_ptr= table->field; *field_ptr; field_ptr++) |
|
|
|
{ |
|
|
|
if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) |
|
|
|
{ |
|
|
|
@ -2161,7 +2155,7 @@ int alloc_statistics_for_table(THD* thd, TABLE *table) |
|
|
|
column_stats->histogram.set_type(hist_type); |
|
|
|
column_stats->histogram.set_values(histogram); |
|
|
|
histogram+= hist_size; |
|
|
|
(*field_ptr)->collected_stats= column_stats; |
|
|
|
(*field_ptr)->collected_stats= column_stats++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|