summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2014-06-25 20:47:54 +0400
committerSergei Petrunia <psergey@askmonty.org>2014-06-25 20:47:54 +0400
commit4a7cacda58a33da48da30e255a12194ee8fa6243 (patch)
tree90c57d2747bba69b0f8879dd69358b86072bad37
parent3da81ab97f33c696b03bd41dc664c103e060941b (diff)
downloadmariadb-git-4a7cacda58a33da48da30e255a12194ee8fa6243.tar.gz
MDEV-406: ANALYZE $stmt: fix "explain UPDATE view problem".
-rw-r--r--sql/sql_select.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 266b542a7ba..b35d53c0950 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -23361,6 +23361,26 @@ void JOIN_TAB::save_explain_data(Explain_table_access *eta, table_map prefix_tab
else
{
TABLE_LIST *real_table= table->pos_in_table_list;
+ /*
+ When multi-table UPDATE/DELETE does updates/deletes to a VIEW, the view
+ is merged in a certain particular way (grep for DT_MERGE_FOR_INSERT).
+
+ As a result, view's underlying tables have $tbl->pos_in_table_list={view}.
+ We don't want to print view name in EXPLAIN, we want underlying table's
+ alias (like specified in the view definition).
+ */
+ if (real_table->merged_for_insert)
+ {
+ TABLE_LIST *view_child= real_table->view->select_lex.table_list.first;
+ for (;view_child; view_child= view_child->next_local)
+ {
+ if (view_child->table == table)
+ {
+ real_table= view_child;
+ break;
+ }
+ }
+ }
eta->table_name.copy(real_table->alias, strlen(real_table->alias), cs);
}