summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2016-02-09 12:35:59 -0800
committerIgor Babaev <igor@askmonty.org>2016-02-09 12:35:59 -0800
commit2cfc450bf78c2d951729d1a0e8f731c0d987b1d5 (patch)
tree6c15f411927c9da723265d5f9891592390e97cea /sql/sql_union.cc
parent7b50447aa6d051b8d14bb01ef14802cb8ffee223 (diff)
downloadmariadb-git-bb-10.2-mdev8646.tar.gz
This is the consolidated patch for mdev-8646:bb-10.2-mdev8646
"Re-factor the code for post-join operations". The patch mainly contains the code ported from mysql-5.6 and created for two essential architectural changes: 1. WL#5558: Resolve ORDER BY execution method at the optimization stage 2. WL#6071: Inline tmp tables into the nested loops algorithm The first task was implemented for mysql-5.6 by Ole John Aske. It allows to make all decisions on ORDER BY operation at the optimization stage. The second task implemented for mysql-5.6 by Evgeny Potemkin adds JOIN_TAB nodes for post-join operations that require temporary tables. It allows to execute these operations within the nested loops algorithm that used to be used before this task only for join queries. Besides these task moves all planning on the execution of these operations from the execution phase to the optimization phase. Some other re-factoring changes of mysql-5.6 were pulled in, mainly because it was easier to pull them in than roll them back. In particular all changes concerning Ref_ptr_array were incorporated. The port required some changes in the MariaDB code that concerned the functionality of EXPLAIN and ANALYZE. This was done mainly by Sergey Petrunia.
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r--sql/sql_union.cc39
1 files changed, 15 insertions, 24 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 069eadc7519..4dac37eb563 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -437,8 +437,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit);
- saved_error= join->prepare(&sl->ref_pointer_array,
- sl->table_list.first,
+ saved_error= join->prepare(sl->table_list.first,
sl->with_wild,
sl->where,
(can_skip_order_by ? 0 :
@@ -647,8 +646,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
fake_select_lex->n_child_sum_items+= global_parameters()->n_sum_items;
saved_error= fake_select_lex->join->
- prepare(&fake_select_lex->ref_pointer_array,
- fake_select_lex->table_list.first,
+ prepare(fake_select_lex->table_list.first,
0, 0,
global_parameters()->order_list.elements, // og_num
global_parameters()->order_list.first, // order
@@ -703,7 +701,7 @@ bool st_select_lex_unit::optimize()
{
item->assigned(0); // We will reinit & rexecute unit
item->reset();
- if (table->created)
+ if (table->is_created())
{
table->file->ha_delete_all_rows();
table->file->info(HA_STATUS_VARIABLE);
@@ -947,13 +945,13 @@ bool st_select_lex_unit::exec()
Don't add more sum_items if we have already done JOIN::prepare
for this (with a different join object)
*/
- if (!fake_select_lex->ref_pointer_array)
+ if (fake_select_lex->ref_pointer_array.is_null())
fake_select_lex->n_child_sum_items+= global_parameters()->n_sum_items;
if (!was_executed)
save_union_explain_part2(thd->lex->explain);
- saved_error= mysql_select(thd, &fake_select_lex->ref_pointer_array,
+ saved_error= mysql_select(thd,
&result_table_list,
0, item_list, NULL,
global_parameters()->order_list.elements,
@@ -976,7 +974,7 @@ bool st_select_lex_unit::exec()
to reset them back, we re-do all of the actions (yes it is ugly):
*/ // psergey-todo: is the above really necessary anymore??
join->init(thd, item_list, fake_select_lex->options, result);
- saved_error= mysql_select(thd, &fake_select_lex->ref_pointer_array,
+ saved_error= mysql_select(thd,
&result_table_list,
0, item_list, NULL,
global_parameters()->order_list.elements,
@@ -1023,27 +1021,11 @@ bool st_select_lex_unit::cleanup()
}
cleaned= 1;
- if (union_result)
- {
- delete union_result;
- union_result=0; // Safety
- if (table)
- free_tmp_table(thd, table);
- table= 0; // Safety
- }
-
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
error|= sl->cleanup();
if (fake_select_lex)
{
- JOIN *join;
- if ((join= fake_select_lex->join))
- {
- join->tables_list= 0;
- join->table_count= 0;
- join->top_join_tab_count= 0;
- }
error|= fake_select_lex->cleanup();
/*
There are two cases when we should clean order items:
@@ -1065,6 +1047,15 @@ bool st_select_lex_unit::cleanup()
}
}
+ if (union_result)
+ {
+ delete union_result;
+ union_result=0; // Safety
+ if (table)
+ free_tmp_table(thd, table);
+ table= 0; // Safety
+ }
+
DBUG_RETURN(error);
}