summaryrefslogtreecommitdiff
path: root/sql/sql_statistics.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2012-08-27 14:19:25 -0700
committerIgor Babaev <igor@askmonty.org>2012-08-27 14:19:25 -0700
commitd0ad93fbc7eca575364e46f67c4613efb0807047 (patch)
tree6b9aae82750afbb2093c2d997076666b91838dcc /sql/sql_statistics.cc
parentf4631d6f71c19a98eccf4998eccb49dd69897661 (diff)
downloadmariadb-git-d0ad93fbc7eca575364e46f67c4613efb0807047.tar.gz
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.
Diffstat (limited to 'sql/sql_statistics.cc')
-rw-r--r--sql/sql_statistics.cc36
1 files changed, 30 insertions, 6 deletions
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();
};
@@ -1895,6 +1896,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
@param
@@ -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)