1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

MDEV-3798: EXPLAIN UPDATE/DELETE

Update the SHOW EXPLAIN code to work with the 
new architecture (part#1):
Before, SHOW EXPLAIN operated on real query plan structures, 
which meant it had to check when SELECTs are created/deleted.
SELECTs would call apc_target->enable() when they got a query 
plan and disable() when their query plan was deleted.

Now, Explain data structure becomes available at once (and we
call apc_target->enable()) and then it stays until it is deleted
(when that happens, we call apc_target->disable()).
This commit is contained in:
Sergey Petrunya
2013-10-14 20:09:33 +04:00
parent f67f8fd00f
commit 105e3ae6c9
11 changed files with 76 additions and 45 deletions

View File

@@ -22,7 +22,8 @@
#include "sql_select.h"
Explain_query::Explain_query() : upd_del_plan(NULL), insert_plan(NULL)
Explain_query::Explain_query(THD *thd_arg) :
upd_del_plan(NULL), insert_plan(NULL), thd(thd_arg), apc_enabled(false)
{
operations= 0;
}
@@ -30,6 +31,9 @@ Explain_query::Explain_query() : upd_del_plan(NULL), insert_plan(NULL)
Explain_query::~Explain_query()
{
if (apc_enabled)
thd->apc_target.disable();
delete upd_del_plan;
delete insert_plan;
uint i;
@@ -62,11 +66,12 @@ Explain_select *Explain_query::get_select(uint select_id)
void Explain_query::add_node(Explain_node *node)
{
uint select_id;
operations++;
if (node->get_type() == Explain_node::EXPLAIN_UNION)
{
Explain_union *u= (Explain_union*)node;
uint select_id= u->get_select_id();
select_id= u->get_select_id();
if (unions.elements() <= select_id)
unions.resize(max(select_id+1, unions.elements()*2), NULL);
@@ -85,7 +90,7 @@ void Explain_query::add_node(Explain_node *node)
}
else
{
uint select_id= sel->select_id;
select_id= sel->select_id;
Explain_select *old_node;
if (selects.elements() <= select_id)
@@ -100,6 +105,27 @@ void Explain_query::add_node(Explain_node *node)
}
void Explain_query::add_insert_plan(Explain_insert *insert_plan_arg)
{
insert_plan= insert_plan_arg;
query_plan_ready();
}
void Explain_query::add_upd_del_plan(Explain_update *upd_del_plan_arg)
{
upd_del_plan= upd_del_plan_arg;
query_plan_ready();
}
void Explain_query::query_plan_ready()
{
if (!apc_enabled)
thd->apc_target.enable();
apc_enabled= true;
}
/*
Send EXPLAIN output to the client.
*/
@@ -915,7 +941,7 @@ void delete_explain_query(LEX *lex)
void create_explain_query(LEX *lex, MEM_ROOT *mem_root)
{
DBUG_ASSERT(!lex->explain);
lex->explain= new Explain_query;
lex->explain= new Explain_query(lex->thd);
DBUG_ASSERT(mem_root == current_thd->mem_root);
lex->explain->mem_root= mem_root;
}