[Commits] Rev 3364: Fixed bug mdev-487. in file:///home/igor/maria/maria-5.5-mdev487/

Igor Babaev igor at askmonty.org
Tue Aug 28 00:19:26 EEST 2012


At file:///home/igor/maria/maria-5.5-mdev487/

------------------------------------------------------------
revno: 3364
revision-id: igor at askmonty.org-20120827211925-qntj56tfdm8vqsx0
parent: igor at askmonty.org-20120823182226-tv99ic3pbk5wela9
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.5-mdev487
timestamp: Mon 2012-08-27 14:19:25 -0700
message:
  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.
-------------- next part --------------
=== modified file 'mysql-test/r/stat_tables.result'
--- a/mysql-test/r/stat_tables.result	2012-08-23 18:22:26 +0000
+++ b/mysql-test/r/stat_tables.result	2012-08-27 21:19:25 +0000
@@ -353,4 +353,15 @@
 test.t1	analyze	status	Table is already up to date
 alter table t1 add column a varchar(8);
 drop table t1;
+#
+# Bug mdev-487: memory leak in ANALYZE with stat tables
+# 
+SET  use_stat_tables = 'preferably';
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+DELETE FROM t1 WHERE a=1;
+ANALYZE TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+DROP TABLE t1;
 set use_stat_tables=@save_use_stat_tables;

=== modified file 'mysql-test/r/stat_tables_innodb.result'
--- a/mysql-test/r/stat_tables_innodb.result	2012-08-23 18:22:26 +0000
+++ b/mysql-test/r/stat_tables_innodb.result	2012-08-27 21:19:25 +0000
@@ -380,6 +380,17 @@
 test.t1	analyze	status	OK
 alter table t1 add column a varchar(8);
 drop table t1;
+#
+# Bug mdev-487: memory leak in ANALYZE with stat tables
+# 
+SET  use_stat_tables = 'preferably';
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+DELETE FROM t1 WHERE a=1;
+ANALYZE TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	analyze	status	OK
+DROP TABLE t1;
 set use_stat_tables=@save_use_stat_tables;
 set optimizer_switch=@save_optimizer_switch_for_stat_tables_test;
 SET SESSION STORAGE_ENGINE=DEFAULT;

=== modified file 'mysql-test/t/stat_tables.test'
--- a/mysql-test/t/stat_tables.test	2012-08-23 18:22:26 +0000
+++ b/mysql-test/t/stat_tables.test	2012-08-27 21:19:25 +0000
@@ -166,5 +166,18 @@
 
 drop table t1;
 
+--echo #
+--echo # Bug mdev-487: memory leak in ANALYZE with stat tables
+--echo # 
+
+SET  use_stat_tables = 'preferably';
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1),(2);
+DELETE FROM t1 WHERE a=1;
+
+ANALYZE TABLE t1;
+
+DROP TABLE t1;
 
 set use_stat_tables=@save_use_stat_tables;

=== modified file 'sql/sql_statistics.cc'
--- a/sql/sql_statistics.cc	2012-08-18 18:49:14 +0000
+++ b/sql/sql_statistics.cc	2012-08-27 21:19:25 +0000
@@ -179,6 +179,7 @@
   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 @@
 
 /**
   @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 @@
         break;
 
       if (rc)
+      {
+        if (rc == HA_ERR_RECORD_DELETED)
+          continue;
         break;
+      }
 
       for (field_ptr= table->field; *field_ptr; field_ptr++)
       {
@@ -2071,14 +2092,17 @@
   {
     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)



More information about the commits mailing list