summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2013-10-07 17:29:51 +0400
committerSergey Petrunya <psergey@askmonty.org>2013-10-07 17:29:51 +0400
commit98a8642fe827fd9ac16bdfaf556599fa509d4180 (patch)
tree4215cf494f23de959522090ee386e125ba359308 /sql/sql_insert.cc
parent69393db3d15b5eac143ab6068037f938b3003ce1 (diff)
downloadmariadb-git-98a8642fe827fd9ac16bdfaf556599fa509d4180.tar.gz
MDEV-3798: EXPLAIN UPDATE/DELETE
- Add support for EXPLAIN INSERT.
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc47
1 files changed, 46 insertions, 1 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 982524e7e32..10cd8a6a7f6 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -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);
}