Enable PERFORMANCE_SCHEMA tracking for SHOW EXPLAIN's conditions.

This commit is contained in:
Sergey Petrunya 2012-07-07 08:47:41 +04:00
parent ae3bc19161
commit a931467e17
5 changed files with 102 additions and 3 deletions

View file

@ -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;

View file

@ -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;

View file

@ -124,6 +124,26 @@ void Apc_target::dequeue_request(Call_request *qe)
qe->next->prev= qe->prev; 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. 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; Call_request apc_request;
apc_request.call= call; apc_request.call= call;
apc_request.processed= FALSE; 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); enqueue_request(&apc_request);
apc_request.what="enqueued by make_apc_call"; apc_request.what="enqueued by make_apc_call";
@ -174,10 +195,8 @@ bool Apc_target::make_apc_call(THD *caller_thd, Apc_call *call,
LOCK_thd_data_ptr, &abstime); LOCK_thd_data_ptr, &abstime);
// &apc_request.LOCK_request, &abstime); // &apc_request.LOCK_request, &abstime);
if (caller_thd->killed) if (caller_thd->killed)
{
break; break;
} }
}
if (!apc_request.processed) if (!apc_request.processed)
{ {

View file

@ -119,3 +119,7 @@ private:
} }
}; };
#ifdef HAVE_PSI_INTERFACE
void init_show_explain_psi_keys(void);
#endif

View file

@ -3909,6 +3909,7 @@ static int init_thread_environment()
sp_cache_init(); sp_cache_init();
#ifdef HAVE_EVENT_SCHEDULER #ifdef HAVE_EVENT_SCHEDULER
Events::init_mutexes(); Events::init_mutexes();
init_show_explain_psi_keys();
#endif #endif
/* Parameter for threads created for connections */ /* Parameter for threads created for connections */
(void) pthread_attr_init(&connection_attrib); (void) pthread_attr_init(&connection_attrib);