[Commits] Rev 3571: MWL#248: Engine-independent statistics in file:///data0/psergey/dev2/maria-5.5-mwl248/

Sergey Petrunya psergey at askmonty.org
Mon Nov 26 16:33:27 EET 2012


At file:///data0/psergey/dev2/maria-5.5-mwl248/

------------------------------------------------------------
revno: 3571
revision-id: psergey at askmonty.org-20121126143325-j69zbl7tl79ns2bm
parent: igor at askmonty.org-20121119210437-yw8dv6nwhuv3269g
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: maria-5.5-mwl248
timestamp: Mon 2012-11-26 18:33:25 +0400
message:
  MWL#248: Engine-independent statistics
  - Collection statistics can take a long time. Add progress reporting.
=== modified file 'sql/sql_admin.cc'
--- a/sql/sql_admin.cc	2012-09-11 05:22:57 +0000
+++ b/sql/sql_admin.cc	2012-11-26 14:33:25 +0000
@@ -713,6 +713,15 @@
         operator_func == &handler::ha_analyze && 
 	thd->variables.use_stat_tables > 0)
     {
+      thd_proc_info(thd, "Collecting engine-independent stats");
+
+      /* 
+        We will do a full table scan + full index scan for each used index +
+        a final stage.
+      */
+      thd_progress_init(thd, table->table->keys_in_use_for_query.bits_set() + 2);
+
+
       if (!(compl_result_code=
             alloc_statistics_for_table(thd, table->table)) &&
           !(compl_result_code=
@@ -720,6 +729,7 @@
         compl_result_code= update_statistics_for_table(thd, table->table);
       if (compl_result_code)
         result_code= HA_ADMIN_FAILED;
+      thd_proc_info(thd, NULL);
     }
 
     if (result_code == HA_ADMIN_NOT_IMPLEMENTED && need_repair_or_alter)

=== modified file 'sql/sql_statistics.cc'
--- a/sql/sql_statistics.cc	2012-09-12 05:36:04 +0000
+++ b/sql/sql_statistics.cc	2012-11-26 14:33:25 +0000
@@ -1943,7 +1943,7 @@
 */
 
 static
-int collect_statistics_for_index(THD *thd, TABLE *table, uint index)
+int collect_statistics_for_index(THD *thd, TABLE *table, ha_rows total_rows, uint index)
 {
   int rc= 0;
   KEY *key_info= &table->key_info[index];
@@ -1967,6 +1967,10 @@
     if (rc)
       break;
     rows++;
+
+    if (!(rows % 10000))
+      thd_progress_report(thd, rows, total_rows);
+
     index_prefix_calc.add();
     rc= table->file->ha_index_next(table->record[0]);
   }
@@ -2055,6 +2059,8 @@
     table_field->collected_stats->init(thd, table_field);
   }
 
+  ha_rows estimated_rows= table->file->stats.records; // todo: is this the right number?
+
   /* Perform a full table scan to collect statistics on 'table's columns */
   if (!(rc= file->ha_rnd_init(TRUE)))
   {  
@@ -2078,9 +2084,13 @@
         table_field->collected_stats->add(rows);
       }
       rows++;
+      if (!(rows % 10000))
+        thd_progress_report(thd, rows, estimated_rows);
     }
     file->ha_rnd_end();
   }
+  thd_progress_next_stage(thd);
+
   rc= (rc == HA_ERR_END_OF_FILE && !thd->killed) ? 0 : 1;
 
   /* 
@@ -2117,8 +2127,9 @@
     /* Collect statistics for indexes */
     while ((key= it++) != key_map::Iterator::BITMAP_END)
     {
-      if ((rc= collect_statistics_for_index(thd, table, key)))
+      if ((rc= collect_statistics_for_index(thd, table, rows, key)))
         break;
+      thd_progress_next_stage(thd);
     }
 
     table->read_set= save_read_set;



More information about the commits mailing list