From d0ad93fbc7eca575364e46f67c4613efb0807047 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Mon, 27 Aug 2012 14:19:25 -0700 Subject: Fixed bug mdev-487. The function collect_statistics_for_table() when scanning a table did not take into account that the handler function ha_rnd_next could return the code HA_ERR_RECORD_DELETE that should not be considered as an indication of an error. Also fixed a potential memory leak in this function. --- sql/sql_statistics.cc | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'sql/sql_statistics.cc') diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index f58659862c4..c3d95da007e 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -179,6 +179,7 @@ public: inline void init(THD *thd, Field * table_field); inline void add(ha_rows rowno); inline void finish(ha_rows rows); + inline void cleanup(); }; @@ -1893,6 +1894,22 @@ void Column_statistics_collected::finish(ha_rows rows) } +/** + @brief + Clean up auxiliary structures used for aggregation +*/ + +inline +void Column_statistics_collected::cleanup() +{ + if (count_distinct) + { + delete count_distinct; + count_distinct= NULL; + } +} + + /** @brief Collect statistical data on an index @@ -2047,7 +2064,11 @@ int collect_statistics_for_table(THD *thd, TABLE *table) break; if (rc) + { + if (rc == HA_ERR_RECORD_DELETED) + continue; break; + } for (field_ptr= table->field; *field_ptr; field_ptr++) { @@ -2071,14 +2092,17 @@ int collect_statistics_for_table(THD *thd, TABLE *table) { table->collected_stats->cardinality_is_null= FALSE; table->collected_stats->cardinality= rows; + } - for (field_ptr= table->field; *field_ptr; field_ptr++) - { - table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) - continue; + for (field_ptr= table->field; *field_ptr; field_ptr++) + { + table_field= *field_ptr; + if (!bitmap_is_set(table->read_set, table_field->field_index)) + continue; + if (!rc) table_field->collected_stats->finish(rows); - } + else + table_field->collected_stats->cleanup(); } if (!rc) -- cgit v1.2.1