[Commits] c46eadb: EXPLAIN FORMAT=JSON: support EXPLAIN FORMAT=JSON INSERT ...

Sergei Petrunia psergey at askmonty.org
Sat Nov 29 02:28:46 EET 2014


revision-id: c46eadb2b33ca152525a18d9b5425fedbef7f277
parent(s): e235bb864d2b8daae3dc7061249f59fb0127bdc5
committer: Sergei Petrunia
branch nick: 10.1-explain-json-r5
timestamp: 2014-11-29 03:28:46 +0300
message:

EXPLAIN FORMAT=JSON: support EXPLAIN FORMAT=JSON INSERT ...

---
 mysql-test/r/explain_json.result |   37 ++++++++++++++++++++++++++++++++++++-
 mysql-test/t/explain_json.test   |    9 ++++++++-
 sql/sql_explain.cc               |   19 +++++++++++++++----
 sql/sql_explain.h                |    3 +--
 4 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/mysql-test/r/explain_json.result b/mysql-test/r/explain_json.result
index 2211c0a..8353a6b 100644
--- a/mysql-test/r/explain_json.result
+++ b/mysql-test/r/explain_json.result
@@ -343,7 +343,7 @@ EXPLAIN
 }
 drop table t1;
 #
-# Single-table UPDATE/DELETE
+# Single-table UPDATE/DELETE, INSERT
 #
 explain format=json delete from t0;
 EXPLAIN
@@ -393,6 +393,41 @@ EXPLAIN
     }
   }
 }
+explain format=json insert into t0 values (1);
+EXPLAIN
+{
+  "query_block": {
+    "select_id": 1,
+    "table": {
+      "table_name": "t0"
+    }
+  }
+}
+create table t1 like t0;
+explain format=json insert into t1 values ((select max(a) from t0));
+EXPLAIN
+{
+  "query_block": {
+    "select_id": 1,
+    "table": {
+      "table_name": "t1"
+    },
+    "subqueries": [
+      {
+        "query_block": {
+          "select_id": 2,
+          "table": {
+            "table_name": "t0",
+            "access_type": "ALL",
+            "rows": 10,
+            "filtered": 100
+          }
+        }
+      }
+    ]
+  }
+}
+drop table t1;
 #
 # A derived table
 #
diff --git a/mysql-test/t/explain_json.test b/mysql-test/t/explain_json.test
index 6e3e874..ed0cfda 100644
--- a/mysql-test/t/explain_json.test
+++ b/mysql-test/t/explain_json.test
@@ -71,7 +71,7 @@ select * from t1 tbl1, t1 tbl2 where tbl1.a=tbl2.a and tbl1.b < 3 and tbl2.b < 5
 drop table t1;
 
 --echo #
---echo # Single-table UPDATE/DELETE
+--echo # Single-table UPDATE/DELETE, INSERT
 --echo #
 explain format=json delete from t0;
 explain format=json delete from t0 where 1 > 2;
@@ -80,6 +80,13 @@ explain format=json delete from t0 where a < 3;
 
 explain format=json update t0 set a=3 where a in (2,3,4);
 
+explain format=json insert into t0 values (1);
+
+create table t1 like t0;
+explain format=json insert into t1 values ((select max(a) from t0));
+
+drop table t1;
+
 --echo #
 --echo # A derived table
 --echo #
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc
index 7297382..77ce692 100644
--- a/sql/sql_explain.cc
+++ b/sql/sql_explain.cc
@@ -194,10 +194,7 @@ void Explain_query::print_explain_json(select_result_sink *output, bool is_analy
   if (upd_del_plan)
     upd_del_plan->print_explain_json(this, &writer, is_analyze);
   else if (insert_plan)
-  {
-    //insert_plan->print_explain(this, output, explain_flags, is_analyze);
-    DBUG_ASSERT(0);
-  }
+    insert_plan->print_explain_json(this, &writer, is_analyze);
   else
   {
     /* Start printing from node with id=1 */
@@ -1808,6 +1805,20 @@ int Explain_insert::print_explain(Explain_query *query,
   return print_explain_for_children(query, output, explain_flags, is_analyze);
 }
 
+void Explain_insert::print_explain_json(Explain_query *query, 
+                                        Json_writer *writer, bool is_analyze)
+{
+  Json_writer_nesting_guard guard(writer);
+
+  writer->add_member("query_block").start_object();
+  writer->add_member("select_id").add_ll(1);
+  writer->add_member("table").start_object();
+  writer->add_member("table_name").add_str(table_name.c_ptr());
+  writer->end_object(); // table
+  print_explain_json_for_children(query, writer, is_analyze);
+  writer->end_object(); // query_block
+}
+
 
 void delete_explain_query(LEX *lex)
 {
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 5d6b28f..9cdaacd 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -704,8 +704,7 @@ class Explain_insert : public Explain_node
   int print_explain(Explain_query *query, select_result_sink *output, 
                     uint8 explain_flags, bool is_analyze);
   void print_explain_json(Explain_query *query, Json_writer *writer, 
-                          bool is_analyze)
-  { /* EXPLAIN_JSON_NOT_IMPL */}
+                          bool is_analyze);
 };
 
 


More information about the commits mailing list