1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-18 23:03:28 +03:00

MDEV-23753: SIGSEGV in Column_stat::store_stat_fields

only collect persistent stats for columns explicitly listed
by the user in the  ANALYZE TABLE PERSISTENT FOR COLUMNS (...)
clause. The engine can extend table->read_set as much as
it wants, it should not affect the collected statistics.

Test case from the 3b94309a6c applies - it used to crash,
because ha_partition extended table->read_set after the loop that
initialized some objects based on bits in the read_set but before the
loop that used these objects based on bits in the read_set.
This commit is contained in:
Sergei Golubchik
2021-02-01 13:01:12 +01:00
parent caad32ca92
commit 06a791aa12

View File

@ -2155,15 +2155,13 @@ int alloc_statistics_for_table(THD* thd, TABLE *table)
for (field_ptr= table->field; *field_ptr; field_ptr++, column_stats++) for (field_ptr= table->field; *field_ptr; field_ptr++, column_stats++)
{ {
(*field_ptr)->collected_stats= column_stats;
(*field_ptr)->collected_stats->max_value= NULL;
(*field_ptr)->collected_stats->min_value= NULL;
if (bitmap_is_set(table->read_set, (*field_ptr)->field_index)) if (bitmap_is_set(table->read_set, (*field_ptr)->field_index))
{ {
column_stats->histogram.set_size(hist_size); column_stats->histogram.set_size(hist_size);
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;
} }
} }
@ -2612,7 +2610,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
for (field_ptr= table->field; *field_ptr; field_ptr++) for (field_ptr= table->field; *field_ptr; field_ptr++)
{ {
table_field= *field_ptr; table_field= *field_ptr;
if (!bitmap_is_set(table->read_set, table_field->field_index)) if (!table_field->collected_stats)
continue; continue;
table_field->collected_stats->init(thd, table_field); table_field->collected_stats->init(thd, table_field);
} }
@ -2639,7 +2637,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
for (field_ptr= table->field; *field_ptr; field_ptr++) for (field_ptr= table->field; *field_ptr; field_ptr++)
{ {
table_field= *field_ptr; table_field= *field_ptr;
if (!bitmap_is_set(table->read_set, table_field->field_index)) if (!table_field->collected_stats)
continue; continue;
if ((rc= table_field->collected_stats->add(rows))) if ((rc= table_field->collected_stats->add(rows)))
break; break;
@ -2667,7 +2665,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table)
for (field_ptr= table->field; *field_ptr; field_ptr++) for (field_ptr= table->field; *field_ptr; field_ptr++)
{ {
table_field= *field_ptr; table_field= *field_ptr;
if (!bitmap_is_set(table->read_set, table_field->field_index)) if (!table_field->collected_stats)
continue; continue;
bitmap_set_bit(table->write_set, table_field->field_index); bitmap_set_bit(table->write_set, table_field->field_index);
if (!rc) if (!rc)
@ -2771,7 +2769,7 @@ int update_statistics_for_table(THD *thd, TABLE *table)
for (Field **field_ptr= table->field; *field_ptr; field_ptr++) for (Field **field_ptr= table->field; *field_ptr; field_ptr++)
{ {
Field *table_field= *field_ptr; Field *table_field= *field_ptr;
if (!bitmap_is_set(table->read_set, table_field->field_index)) if (!table_field->collected_stats)
continue; continue;
restore_record(stat_table, s->default_values); restore_record(stat_table, s->default_values);
column_stat.set_key_fields(table_field); column_stat.set_key_fields(table_field);