summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2012-07-07 08:47:41 +0400
committerSergey Petrunya <psergey@askmonty.org>2012-07-07 08:47:41 +0400
commita931467e17c4826ce4fa473de0479953d9bbcc59 (patch)
tree6e017fc3f244fa2a9a3f940ded632de0b96822a0
parentae3bc191613fdec05d4d84a74648d1e84edc8ce4 (diff)
downloadmariadb-git-a931467e17c4826ce4fa473de0479953d9bbcc59.tar.gz
Enable PERFORMANCE_SCHEMA tracking for SHOW EXPLAIN's conditions.
-rw-r--r--mysql-test/r/show_explain_ps.result27
-rw-r--r--mysql-test/t/show_explain_ps.test48
-rw-r--r--sql/my_apc.cc25
-rw-r--r--sql/my_apc.h4
-rw-r--r--sql/mysqld.cc1
5 files changed, 102 insertions, 3 deletions
diff --git a/mysql-test/r/show_explain_ps.result b/mysql-test/r/show_explain_ps.result
new file mode 100644
index 00000000000..625b9cfddae
--- /dev/null
+++ b/mysql-test/r/show_explain_ps.result
@@ -0,0 +1,27 @@
+drop table if exists t0, t1;
+select * from performance_schema.setup_instruments where name like '%show_explain%';
+NAME ENABLED TIMED
+wait/synch/cond/sql/show_explain YES YES
+# We've got no instances
+select * from performance_schema.cond_instances where name like '%show_explain%';
+NAME OBJECT_INSTANCE_BEGIN
+# Check out if our cond is hit.
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+set @show_explain_probe_select_id=1;
+set debug_dbug='d,show_explain_probe_join_exec_start';
+select count(*) from t0 where a < 100000;
+show explain for $thr2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
+Warnings:
+Note 1003 select count(*) from t0 where a < 100000
+count(*)
+10
+set debug_dbug='';
+select event_name
+from performance_schema.events_waits_history_long
+where event_name='wait/synch/cond/sql/show_explain';
+event_name
+wait/synch/cond/sql/show_explain
+drop table t0;
diff --git a/mysql-test/t/show_explain_ps.test b/mysql-test/t/show_explain_ps.test
new file mode 100644
index 00000000000..67634ac57e2
--- /dev/null
+++ b/mysql-test/t/show_explain_ps.test
@@ -0,0 +1,48 @@
+#
+# Test how SHOW EXPLAIN is represented in performance schema
+#
+--source include/have_perfschema.inc
+
+--disable_warnings
+drop table if exists t0, t1;
+--enable_warnings
+
+select * from performance_schema.setup_instruments where name like '%show_explain%';
+
+--echo # We've got no instances
+select * from performance_schema.cond_instances where name like '%show_explain%';
+
+--echo # Check out if our cond is hit.
+
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+let $thr1=`select connection_id()`;
+connect (con1, localhost, root,,);
+connection con1;
+let $thr2=`select connection_id()`;
+connection default;
+
+let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
+
+#
+# Test SHOW EXPLAIN for simple queries
+#
+connection con1;
+set @show_explain_probe_select_id=1;
+set debug_dbug='d,show_explain_probe_join_exec_start';
+send select count(*) from t0 where a < 100000;
+
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+
+set debug_dbug='';
+
+select event_name
+from performance_schema.events_waits_history_long
+where event_name='wait/synch/cond/sql/show_explain';
+
+drop table t0;
diff --git a/sql/my_apc.cc b/sql/my_apc.cc
index 4a523fcd03e..c7ba25ad3ba 100644
--- a/sql/my_apc.cc
+++ b/sql/my_apc.cc
@@ -124,6 +124,26 @@ void Apc_target::dequeue_request(Call_request *qe)
qe->next->prev= qe->prev;
}
+#ifdef HAVE_PSI_INTERFACE
+
+/* One key for all conds */
+PSI_cond_key key_show_explain_request_COND;
+
+static PSI_cond_info show_explain_psi_conds[]=
+{
+ { &key_show_explain_request_COND, "show_explain", 0 /* not using PSI_FLAG_GLOBAL*/ }
+};
+
+void init_show_explain_psi_keys(void)
+{
+ if (PSI_server == NULL)
+ return;
+
+ PSI_server->register_cond("sql", show_explain_psi_conds,
+ array_elements(show_explain_psi_conds));
+}
+#endif
+
/*
Make an APC (Async Procedure Call) to another thread.
@@ -154,7 +174,8 @@ bool Apc_target::make_apc_call(THD *caller_thd, Apc_call *call,
Call_request apc_request;
apc_request.call= call;
apc_request.processed= FALSE;
- mysql_cond_init(0 /* do not track in PS */, &apc_request.COND_request, NULL);
+ mysql_cond_init(key_show_explain_request_COND, &apc_request.COND_request,
+ NULL);
enqueue_request(&apc_request);
apc_request.what="enqueued by make_apc_call";
@@ -174,9 +195,7 @@ bool Apc_target::make_apc_call(THD *caller_thd, Apc_call *call,
LOCK_thd_data_ptr, &abstime);
// &apc_request.LOCK_request, &abstime);
if (caller_thd->killed)
- {
break;
- }
}
if (!apc_request.processed)
diff --git a/sql/my_apc.h b/sql/my_apc.h
index 84819b9beea..1c4cc25376b 100644
--- a/sql/my_apc.h
+++ b/sql/my_apc.h
@@ -119,3 +119,7 @@ private:
}
};
+#ifdef HAVE_PSI_INTERFACE
+void init_show_explain_psi_keys(void);
+#endif
+
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 67446ef7239..54b5b95afaf 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3909,6 +3909,7 @@ static int init_thread_environment()
sp_cache_init();
#ifdef HAVE_EVENT_SCHEDULER
Events::init_mutexes();
+ init_show_explain_psi_keys();
#endif
/* Parameter for threads created for connections */
(void) pthread_attr_init(&connection_attrib);