Commit b3841ae9 authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-267: SHOW EXPLAIN: Server crashes in JOIN::print_explain on most of queries

- Make SHOW EXPLAIN code handle degenerate subquery cases (No tables, impossible where, etc)
parent 6bce3366
......@@ -370,4 +370,48 @@ a b
set debug='';
DROP VIEW v1;
DROP TABLE t2, t3;
#
# MDEV-267: SHOW EXPLAIN: Server crashes in JOIN::print_explain on most of queries
#
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
select sleep(1);
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select sleep(1)
sleep(1)
0
set debug='';
#
# Same as above, but try another reason for JOIN to be degenerate
#
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
select * from t0 where 1>10;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
Warnings:
Note 1003 select * from t0 where 1>10
a
set debug='';
#
# Same as above, but try another reason for JOIN to be degenerate (2)
#
create table t3(a int primary key);
insert into t3 select a from t0;
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
select * from t0,t3 where t3.a=112233;
show explain for $thr2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t3 const PRIMARY PRIMARY 4 0 unique row not found
1 SIMPLE t0 ALL NULL NULL NULL NULL 10
Warnings:
Note 1003 select * from t0,t3 where t3.a=112233
a a
set debug='';
drop table t3;
drop table t0,t1;
......@@ -371,6 +371,49 @@ set debug='';
DROP VIEW v1;
DROP TABLE t2, t3;
--echo #
--echo # MDEV-267: SHOW EXPLAIN: Server crashes in JOIN::print_explain on most of queries
--echo #
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
send select sleep(1);
connection default;
--source include/wait_condition.inc
evalp show explain for $thr2;
connection con1;
reap;
set debug='';
--echo #
--echo # Same as above, but try another reason for JOIN to be degenerate
--echo #
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
send select * from t0 where 1>10;
connection default;
--source include/wait_condition.inc
evalp show explain for $thr2;
connection con1;
reap;
set debug='';
--echo #
--echo # Same as above, but try another reason for JOIN to be degenerate (2)
--echo #
create table t3(a int primary key);
insert into t3 select a from t0;
set @show_explain_probe_select_id=1;
set debug='d,show_explain_probe_join_exec_end';
send select * from t0,t3 where t3.a=112233;
connection default;
--source include/wait_condition.inc
evalp show explain for $thr2;
connection con1;
reap;
set debug='';
drop table t3;
## TODO: Test this: have several SHOW EXPLAIN requests be queued up for a
## thread and served together.
......
......@@ -3751,12 +3751,23 @@ int st_select_lex::print_explain(select_result_sink *output,
{
int res;
if (join && join->optimized == JOIN::OPTIMIZATION_DONE)
{
if (!join->table_count)
{
/* It's a degenerate join */
const char *cause= join->zero_result_cause ? join-> zero_result_cause :
"No tables used";
res= join->print_explain(output, explain_flags, TRUE, FALSE, FALSE,
FALSE, cause);
}
else
{
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
NULL); //const char *message
}
if (res)
goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment