[Commits] da36b92: MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print the r_total_time_ms

sanja at mariadb.com sanja at mariadb.com
Thu Mar 26 11:49:09 EET 2015


revision-id: da36b92a122cb0e35ed75eff8869bc39dacf1583
parent(s): 01d7da6785284383b2c04f2d4474feccebb0bb6f
committer: Oleksandr Byelkin
branch nick: server
timestamp: 2015-03-26 10:48:56 +0100
message:

MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print the r_total_time_ms

Tracking total time added in UPDATE/DELETE
Fixed selectivity calculation in UPDATE/DELETE
Macro definitions of time tracting fixed.

---
 mysql-test/r/analyze_format_json.result | 77 +++++++++++++++++++++++++++++++++
 mysql-test/t/analyze_format_json.test   | 29 +++++++++++++
 sql/sql_delete.cc                       |  2 +
 sql/sql_explain.cc                      |  6 ++-
 sql/sql_explain.h                       |  5 ++-
 sql/sql_update.cc                       |  2 +
 6 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/mysql-test/r/analyze_format_json.result b/mysql-test/r/analyze_format_json.result
index 9022d8c..8b6cc43 100644
--- a/mysql-test/r/analyze_format_json.result
+++ b/mysql-test/r/analyze_format_json.result
@@ -264,3 +264,80 @@ ANALYZE
   }
 }
 drop table t1;
+#
+# MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print
+# the r_total_time_ms
+#
+create table t2(a int);
+insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t3(a int);
+insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C;
+create table t1 (pk int primary key);
+insert into t1 select a from t3;
+alter table t1 add b int;
+analyze format=json
+update t1 set b=pk;
+ANALYZE
+{
+  "query_block": {
+    "select_id": 1,
+    "table": {
+      "update": 1,
+      "table_name": "t1",
+      "access_type": "ALL",
+      "rows": 1000,
+      "r_rows": 1000,
+      "r_filtered": 100,
+      "r_total_time_ms": "REPLACED"
+    }
+  }
+}
+analyze format=json
+select * from t1 where pk < 10 and b > 4;
+ANALYZE
+{
+  "query_block": {
+    "select_id": 1,
+    "r_loops": 1,
+    "r_total_time_ms": "REPLACED",
+    "table": {
+      "table_name": "t1",
+      "access_type": "range",
+      "possible_keys": ["PRIMARY"],
+      "key": "PRIMARY",
+      "key_length": "4",
+      "used_key_parts": ["pk"],
+      "r_loops": 1,
+      "rows": 11,
+      "r_rows": 10,
+      "r_total_time_ms": "REPLACED",
+      "filtered": 100,
+      "r_filtered": 50,
+      "index_condition": "(t1.pk < 10)",
+      "attached_condition": "(t1.b > 4)"
+    }
+  }
+}
+analyze format=json
+delete from t1 where pk < 10 and b > 4;
+ANALYZE
+{
+  "query_block": {
+    "select_id": 1,
+    "table": {
+      "delete": 1,
+      "table_name": "t1",
+      "access_type": "range",
+      "possible_keys": ["PRIMARY"],
+      "key": "PRIMARY",
+      "key_length": "4",
+      "used_key_parts": ["pk"],
+      "rows": 11,
+      "r_rows": 10,
+      "r_filtered": 50,
+      "r_total_time_ms": "REPLACED",
+      "attached_condition": "((t1.pk < 10) and (t1.b > 4))"
+    }
+  }
+}
+drop table t1, t3, t2;
diff --git a/mysql-test/t/analyze_format_json.test b/mysql-test/t/analyze_format_json.test
index 64bafd7..473c9b3 100644
--- a/mysql-test/t/analyze_format_json.test
+++ b/mysql-test/t/analyze_format_json.test
@@ -75,3 +75,32 @@ disconnect con1;
 connection default;
 drop table t1;
 
+
+--echo #
+--echo # MDEV-7812: ANALYZE FORMAT=JSON UPDATE/DELETE doesnt print
+--echo # the r_total_time_ms
+--echo #
+
+create table t2(a int);
+insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t3(a int);
+insert into t3 select A.a + B.a* 10 + C.a * 100 from t2 A, t2 B, t2 C;
+
+create table t1 (pk int primary key);
+insert into t1 select a from t3;
+alter table t1 add b int;
+
+--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/
+analyze format=json
+update t1 set b=pk;
+
+--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/
+analyze format=json
+select * from t1 where pk < 10 and b > 4;
+
+--replace_regex /"r_total_time_ms": [0-9]*[.]?[0-9]*/"r_total_time_ms": "REPLACED"/
+analyze format=json
+delete from t1 where pk < 10 and b > 4;
+
+drop table t1, t3, t2;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 8fd9b0b..d0c304f 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -542,6 +542,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
 
   explain= (Explain_delete*)thd->lex->explain->get_upd_del_plan();
   explain->tracker.on_scan_init();
+  ANALYZE_START_TRACKING(&explain->time_tracker);
 
   while (!(error=info.read_record(&info)) && !thd->killed &&
 	 ! thd->is_error())
@@ -619,6 +620,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
   end_read_record(&info);
   if (options & OPTION_QUICK)
     (void) table->file->extra(HA_EXTRA_NORMAL);
+  ANALYZE_STOP_TRACKING(&explain->time_tracker);
 
 cleanup:
   /*
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 9d82f4f..6c35318 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -1892,7 +1892,7 @@ void Explain_update::print_explain_json(Explain_query *query,
   /* `r_filtered` */
   if (is_analyze)
   {
-    double r_filtered= tracker.get_filtered_after_where();
+    double r_filtered= tracker.get_filtered_after_where() * 100.0;
     writer->add_member("r_filtered").add_double(r_filtered);
   }
 
@@ -1905,6 +1905,10 @@ void Explain_update::print_explain_json(Explain_query *query,
   if (using_io_buffer)
     writer->add_member("using_io_buffer").add_ll(1);
 
+  if (is_analyze && time_tracker.get_loops())
+    writer->
+      add_member("r_total_time_ms").add_double(time_tracker.get_time_ms());
+
   if (where_cond)
   {
     writer->add_member("attached_condition");
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index e3b41ee..65027bd 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -131,11 +131,11 @@ class Table_op_tracker
 
 #define ANALYZE_START_TRACKING(tracker) \
   if (tracker) \
-  { tracker->start_tracking(); }
+  { (tracker)->start_tracking(); }
 
 #define ANALYZE_STOP_TRACKING(tracker) \
   if (tracker) \
-  { tracker->stop_tracking(); }
+  { (tracker)->stop_tracking(); }
 
 
 /**************************************************************************************
@@ -809,6 +809,7 @@ class Explain_update : public Explain_node
 
   /* ANALYZE members and methods */
   Table_access_tracker tracker;
+  Exec_time_tracker time_tracker;
   //psergey-todo: io-tracker here.
 
   virtual int print_explain(Explain_query *query, select_result_sink *output, 
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index be4038e..680d3d7 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -731,6 +731,7 @@ int mysql_update(THD *thd,
   */
   can_compare_record= records_are_comparable(table);
   explain->tracker.on_scan_init();
+  ANALYZE_START_TRACKING(&explain->time_tracker);
 
   while (!(error=info.read_record(&info)) && !thd->killed)
   {
@@ -907,6 +908,7 @@ int mysql_update(THD *thd,
       break;
     }
   }
+  ANALYZE_STOP_TRACKING(&explain->time_tracker);
   table->auto_increment_field_not_null= FALSE;
   dup_key_found= 0;
   /*


More information about the commits mailing list