Commit c4f01334 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: stat tables

don't allocate Column_statistics_collected objects that won't
be used.

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