summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/show_explain.result28
-rw-r--r--mysql-test/t/show_explain.test27
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_lex.cc16
-rw-r--r--sql/sql_lex.h4
-rw-r--r--sql/sql_select.cc34
-rw-r--r--sql/sql_select.h3
7 files changed, 89 insertions, 25 deletions
diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result
index db1d57b7004..4f0e89975ff 100644
--- a/mysql-test/r/show_explain.result
+++ b/mysql-test/r/show_explain.result
@@ -309,4 +309,32 @@ a
4
set debug='';
DROP TABLE t2;
+#
+# MDEV-239: Assertion `field_types == 0 ... ' failed in Protocol_text::store(double, uint32, String*) with
+# SHOW EXPLAIN over EXPLAIN EXTENDED
+#
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1),(2),(1),(4),(2);
+EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` join `test`.`t2` group by `test`.`t2`.`a`
+set @show_explain_probe_select_id=1;
+set debug='d,show_explain_probe_join_exec_end';
+EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+show explain for $thr2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort
+1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join)
+Warnings:
+Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` join `test`.`t2` group by `test`.`t2`.`a`
+set debug='';
+DROP TABLE t2;
drop table t0,t1;
diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test
index 8c9d5f4c1e8..02850efedd8 100644
--- a/mysql-test/t/show_explain.test
+++ b/mysql-test/t/show_explain.test
@@ -319,11 +319,34 @@ evalp show explain for $thr2;
connection con1;
reap;
set debug='';
+DROP TABLE t2;
-## TODO: Test this: have several SHOW EXPLAIN requests be queued up for a
-## thread and served together.
+--echo #
+--echo # MDEV-239: Assertion `field_types == 0 ... ' failed in Protocol_text::store(double, uint32, String*) with
+--echo # SHOW EXPLAIN over EXPLAIN EXTENDED
+--echo #
+
+
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (1),(2),(1),(4),(2);
+
+EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+
+set @show_explain_probe_select_id=1;
+set debug='d,show_explain_probe_join_exec_end';
+send EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ;
+connection default;
+--source include/wait_condition.inc
+evalp show explain for $thr2;
+connection con1;
+reap;
+set debug='';
DROP TABLE t2;
+
+## TODO: Test this: have several SHOW EXPLAIN requests be queued up for a
+## thread and served together.
+
drop table t0,t1;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 4e9a0507bba..89d80dc1ec2 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3039,7 +3039,7 @@ void Show_explain_request::get_explain_data(void *arg)
target_thd->query_length(),
&my_charset_bin);
- if (target_thd->lex->unit.print_explain(req->explain_buf))
+ if (target_thd->lex->unit.print_explain(req->explain_buf, 0 /* explain flags */))
req->failed_to_produce= TRUE;
target_thd->restore_active_arena((Query_arena*)req->request_thd,
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index a47ba9b5024..69bb822f05a 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3746,12 +3746,13 @@ bool st_select_lex::is_merged_child_of(st_select_lex *ancestor)
}
-int st_select_lex::print_explain(select_result_sink *output)
+int st_select_lex::print_explain(select_result_sink *output,
+ uint8 explain_flags)
{
int res;
if (join && join->optimized == 2)
{
- res= join->print_explain(output, TRUE,
+ res= join->print_explain(output, explain_flags, TRUE,
join->need_tmp, // need_tmp_table
(join->order != 0 && !join->skip_sort_order), // bool need_order
join->select_distinct, // bool distinct
@@ -3769,7 +3770,7 @@ int st_select_lex::print_explain(select_result_sink *output)
*/
if (!(unit->item && unit->item->eliminated))
{
- unit->print_explain(output);
+ unit->print_explain(output, explain_flags);
}
}
}
@@ -3777,7 +3778,7 @@ int st_select_lex::print_explain(select_result_sink *output)
{
/* Produce "not yet optimized" line */
const char *msg="Not yet optimized";
- res= join->print_explain(output, TRUE,
+ res= join->print_explain(output, explain_flags, TRUE,
FALSE, // need_tmp_table,
FALSE, // bool need_order,
FALSE, // bool distinct,
@@ -3788,7 +3789,8 @@ err:
}
-int st_select_lex_unit::print_explain(select_result_sink *output)
+int st_select_lex_unit::print_explain(select_result_sink *output,
+ uint8 explain_flags)
{
int res= 0;
SELECT_LEX *first= first_select();
@@ -3804,7 +3806,7 @@ int st_select_lex_unit::print_explain(select_result_sink *output)
for (SELECT_LEX *sl= first; sl; sl= sl->next_select())
{
- if ((res= sl->print_explain(output)))
+ if ((res= sl->print_explain(output, explain_flags)))
break;
}
@@ -3814,7 +3816,7 @@ int st_select_lex_unit::print_explain(select_result_sink *output)
if (fake_select_lex && !fake_select_lex->join)
{
res= print_fake_select_lex_join(output, TRUE /* on the fly */,
- fake_select_lex, 0 /* flags */);
+ fake_select_lex, explain_flags);
}
return res;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 6f72c9e3f7b..8a7547691e9 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -595,7 +595,7 @@ public:
friend int subselect_union_engine::exec();
List<Item> *get_unit_column_types();
- int print_explain(select_result_sink *output);
+ int print_explain(select_result_sink *output, uint8 explain_flags);
};
typedef class st_select_lex_unit SELECT_LEX_UNIT;
@@ -918,7 +918,7 @@ public:
bool save_prep_leaf_tables(THD *thd);
bool is_merged_child_of(st_select_lex *ancestor);
- int print_explain(select_result_sink *output);
+ int print_explain(select_result_sink *output, uint8 explain_flags);
/*
For MODE_ONLY_FULL_GROUP_BY we need to maintain two flags:
- Non-aggregated fields are used in this select.
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 6a842ead2a4..f48f180d1dd 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2123,6 +2123,14 @@ void JOIN::exec()
*/
thd->apc_target.enable();
exec_inner();
+
+ DBUG_EXECUTE_IF("show_explain_probe_join_exec_end",
+ if (dbug_user_var_equals_int(thd,
+ "show_explain_probe_select_id",
+ select_lex->select_number))
+ dbug_serve_apcs(thd, 1);
+ );
+
thd->apc_target.disable();
}
@@ -21075,7 +21083,7 @@ void JOIN::clear()
int print_fake_select_lex_join(select_result_sink *result, bool on_the_fly,
- SELECT_LEX *select_lex, uint8 select_options)
+ SELECT_LEX *select_lex, uint8 explain_flags)
{
const CHARSET_INFO *cs= system_charset_info;
Item *item_null= new Item_null();
@@ -21121,7 +21129,7 @@ int print_fake_select_lex_join(select_result_sink *result, bool on_the_fly,
item_list.push_back(new Item_string(table_name_buffer, len, cs));
}
/* partitions */
- if (/*join->thd->lex->describe*/ select_options & DESCRIBE_PARTITIONS)
+ if (explain_flags & DESCRIBE_PARTITIONS)
item_list.push_back(item_null);
/* type */
item_list.push_back(new Item_string(join_type_str[JT_ALL],
@@ -21136,7 +21144,7 @@ int print_fake_select_lex_join(select_result_sink *result, bool on_the_fly,
/* ref */
item_list.push_back(item_null);
/* in_rows */
- if (select_options & DESCRIBE_EXTENDED)
+ if (explain_flags & DESCRIBE_EXTENDED)
item_list.push_back(item_null);
/* rows */
item_list.push_back(item_null);
@@ -21162,7 +21170,8 @@ int print_fake_select_lex_join(select_result_sink *result, bool on_the_fly,
modifications to any select's data structures
*/
-int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
+int JOIN::print_explain(select_result_sink *result, uint8 explain_flags,
+ bool on_the_fly,
bool need_tmp_table, bool need_order,
bool distinct, const char *message)
{
@@ -21199,9 +21208,9 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
strlen(join->select_lex->type), cs));
for (uint i=0 ; i < 7; i++)
item_list.push_back(item_null);
- if (join->thd->lex->describe & DESCRIBE_PARTITIONS)
+ if (explain_flags & DESCRIBE_PARTITIONS)
item_list.push_back(item_null);
- if (join->thd->lex->describe & DESCRIBE_EXTENDED)
+ if (explain_flags & DESCRIBE_EXTENDED)
item_list.push_back(item_null);
item_list.push_back(new Item_string(message,strlen(message),cs));
@@ -21212,7 +21221,7 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
{
if (print_fake_select_lex_join(result, on_the_fly,
join->select_lex,
- join->thd->lex->describe))
+ explain_flags))
error= 1;
}
else if (!join->select_lex->master_unit()->derived ||
@@ -21317,7 +21326,7 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
cs));
}
/* "partitions" column */
- if (join->thd->lex->describe & DESCRIBE_PARTITIONS)
+ if (explain_flags & DESCRIBE_PARTITIONS)
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *part_info;
@@ -21460,7 +21469,7 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
table_list->schema_table)
{
/* in_rows */
- if (join->thd->lex->describe & DESCRIBE_EXTENDED)
+ if (explain_flags & DESCRIBE_EXTENDED)
item_list.push_back(item_null);
/* rows */
item_list.push_back(item_null);
@@ -21497,7 +21506,7 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
MY_INT64_NUM_DECIMAL_DIGITS));
/* Add "filtered" field to item_list. */
- if (join->thd->lex->describe & DESCRIBE_EXTENDED)
+ if (explain_flags & DESCRIBE_EXTENDED)
{
float f= 0.0;
if (examined_rows)
@@ -21577,7 +21586,7 @@ int JOIN::print_explain(select_result_sink *result, bool on_the_fly,
{
extra.append(STRING_WITH_LEN("; Using where with pushed "
"condition"));
- if (thd->lex->describe & DESCRIBE_EXTENDED)
+ if (explain_flags & DESCRIBE_EXTENDED)
{
extra.append(STRING_WITH_LEN(": "));
((COND *)pushed_cond)->print(&extra, QT_ORDINARY);
@@ -21732,7 +21741,8 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
THD *thd=join->thd;
select_result *result=join->result;
DBUG_ENTER("select_describe");
- join->error= join->print_explain(result, FALSE, /* Not on-the-fly */
+ join->error= join->print_explain(result, thd->lex->describe,
+ FALSE, /* Not on-the-fly */
need_tmp_table, need_order, distinct,
message);
diff --git a/sql/sql_select.h b/sql/sql_select.h
index c60419f1ffd..a15720b4b30 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1405,7 +1405,8 @@ public:
return (unit->item && unit->item->is_in_predicate());
}
- int print_explain(select_result_sink *result, bool on_the_fly,
+ int print_explain(select_result_sink *result, uint8 explain_flags,
+ bool on_the_fly,
bool need_tmp_table, bool need_order,
bool distinct,const char *message);
private: