summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r--sql/sql_union.cc40
1 files changed, 23 insertions, 17 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 919ed2256a9..f35a371b90b 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -20,7 +20,7 @@
UNION's were introduced by Monty and Sinisa <sinisa@mysql.com>
*/
-
+#include <my_global.h>
#include "sql_priv.h"
#include "unireg.h"
#include "sql_union.h"
@@ -64,7 +64,7 @@ int select_union::send_data(List<Item> &values)
return 0;
if (table->no_rows_with_nulls)
table->null_catch_flags= CHECK_ROW_FOR_NULLS_TO_REJECT;
- fill_record(thd, table->field, values, TRUE, FALSE);
+ fill_record(thd, table, table->field, values, TRUE, FALSE);
if (thd->is_error())
return 1;
if (table->no_rows_with_nulls)
@@ -245,7 +245,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
bool is_union_select;
DBUG_ENTER("st_select_lex_unit::prepare");
- describe= test(additional_options & SELECT_DESCRIBE);
+ describe= MY_TEST(additional_options & SELECT_DESCRIBE);
/*
result object should be reassigned even if preparing already done for
@@ -287,8 +287,6 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{
if (!(tmp_result= union_result= new select_union))
goto err;
- if (describe)
- tmp_result= sel_result;
}
else
tmp_result= sel_result;
@@ -465,7 +463,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
if (global_parameters->ftfunc_list->elements)
create_options= create_options | TMP_TABLE_FORCE_MYISAM;
- if (union_result->create_result_table(thd, &types, test(union_distinct),
+ if (union_result->create_result_table(thd, &types, MY_TEST(union_distinct),
create_options, "", FALSE, TRUE))
goto err;
if (fake_select_lex && !fake_select_lex->first_cond_optimization)
@@ -647,6 +645,7 @@ bool st_select_lex_unit::exec()
ha_rows examined_rows= 0;
bool first_execution= !executed;
DBUG_ENTER("st_select_lex_unit::exec");
+ bool was_executed= executed;
if (executed && !uncacheable && !describe)
DBUG_RETURN(FALSE);
@@ -654,7 +653,14 @@ bool st_select_lex_unit::exec()
if (!(uncacheable & ~UNCACHEABLE_EXPLAIN) && item)
item->make_const();
- if ((saved_error= optimize()))
+ saved_error= optimize();
+
+ create_explain_query_if_not_exists(thd->lex, thd->mem_root);
+
+ if (!saved_error && !was_executed)
+ save_union_explain(thd->lex->explain);
+
+ if (saved_error)
DBUG_RETURN(saved_error);
if (uncacheable || !item || !item->assigned() || describe)
@@ -707,13 +713,8 @@ bool st_select_lex_unit::exec()
0);
if (!saved_error)
{
- /*
- Save the current examined row count locally and clear the global
- counter, so that we can accumulate the number of evaluated rows for
- the current query block.
- */
- examined_rows+= thd->examined_row_count;
- thd->examined_row_count= 0;
+ examined_rows+= thd->get_examined_row_count();
+ thd->set_examined_row_count(0);
if (union_result->flush())
{
thd->lex->current_select= lex_select_save;
@@ -751,7 +752,7 @@ bool st_select_lex_unit::exec()
Stop execution of the remaining queries in the UNIONS, and produce
the current result.
*/
- push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
ER(ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
thd->accessed_rows_and_keys,
@@ -762,6 +763,8 @@ bool st_select_lex_unit::exec()
}
}
+ DBUG_EXECUTE_IF("show_explain_probe_union_read",
+ dbug_serve_apcs(thd, 1););
/* Send result to 'result' */
saved_error= TRUE;
{
@@ -810,6 +813,9 @@ bool st_select_lex_unit::exec()
*/
if (!fake_select_lex->ref_pointer_array)
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,
&result_table_list,
@@ -855,7 +861,7 @@ bool st_select_lex_unit::exec()
if (!saved_error)
{
thd->limit_found_rows = (ulonglong)table->file->stats.records + add_rows;
- thd->examined_row_count+= examined_rows;
+ thd->inc_examined_row_count(examined_rows);
}
/*
Mark for slow query log if any of the union parts didn't use
@@ -988,7 +994,7 @@ bool st_select_lex_unit::change_result(select_result_interceptor *new_result,
List<Item> *st_select_lex_unit::get_unit_column_types()
{
SELECT_LEX *sl= first_select();
- bool is_procedure= test(sl->join->procedure);
+ bool is_procedure= MY_TEST(sl->join->procedure);
if (is_procedure)
{