mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-3798: EXPLAIN UPDATE/DELETE
- Add support for EXPLAIN INSERT.
This commit is contained in:
@@ -644,6 +644,36 @@ create_insert_stmt_from_insert_delayed(THD *thd, String *buf)
|
||||
}
|
||||
|
||||
|
||||
static void save_insert_query_plan(THD* thd, TABLE_LIST *table_list)
|
||||
{
|
||||
Explain_insert* explain= new Explain_insert;
|
||||
explain->table_name.append(table_list->table->alias);
|
||||
|
||||
thd->lex->explain->insert_plan= explain;
|
||||
|
||||
/* See Update_plan::updating_a_view for details */
|
||||
bool skip= test(table_list->view);
|
||||
|
||||
/* Save subquery children */
|
||||
for (SELECT_LEX_UNIT *unit= thd->lex->select_lex.first_inner_unit();
|
||||
unit;
|
||||
unit= unit->next_unit())
|
||||
{
|
||||
if (skip)
|
||||
{
|
||||
skip= false;
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
Table elimination doesn't work for INSERTS, but let's still have this
|
||||
here for consistency
|
||||
*/
|
||||
if (!(unit->item && unit->item->eliminated))
|
||||
explain->add_child(unit->first_select()->select_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
INSERT statement implementation
|
||||
|
||||
@@ -660,6 +690,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
|
||||
enum_duplicates duplic,
|
||||
bool ignore)
|
||||
{
|
||||
bool retval= true;
|
||||
int error, res;
|
||||
bool transactional_table, joins_freed= FALSE;
|
||||
bool changed;
|
||||
@@ -780,6 +811,17 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
|
||||
|
||||
/* Restore the current context. */
|
||||
ctx_state.restore_state(context, table_list);
|
||||
|
||||
if (thd->lex->unit.first_select()->optimize_unflattened_subqueries(false))
|
||||
{
|
||||
goto abort;
|
||||
}
|
||||
save_insert_query_plan(thd, table_list);
|
||||
if (thd->lex->describe)
|
||||
{
|
||||
retval= 0;
|
||||
goto exit_without_my_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
Fill in the given fields and dump it to the table file
|
||||
@@ -1128,16 +1170,19 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
|
||||
DBUG_RETURN(FALSE);
|
||||
|
||||
abort:
|
||||
exit_without_my_ok:
|
||||
#ifndef EMBEDDED_LIBRARY
|
||||
if (lock_type == TL_WRITE_DELAYED)
|
||||
end_delayed_insert(thd);
|
||||
#endif
|
||||
if (table != NULL)
|
||||
table->file->ha_release_auto_increment();
|
||||
retval= thd->lex->explain->send_explain(thd);
|
||||
|
||||
if (!joins_freed)
|
||||
free_underlaid_joins(thd, &thd->lex->select_lex);
|
||||
thd->abort_on_warning= 0;
|
||||
DBUG_RETURN(TRUE);
|
||||
DBUG_RETURN(retval);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user