From ba09d25abc1fd3dbe55f1d7974cfe6a1ebda4df0 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 27 Oct 2011 21:34:41 +0400 Subject: [PATCH] Fix typo bug in UNION handling, add tests for SHOW EXPLAIN for UNION. --- mysql-test/r/show_explain.result | 29 +++++++++++++++++++++++++++++ mysql-test/t/show_explain.test | 26 +++++++++++++++++++++++++- sql/sql_lex.cc | 6 +++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result index 874af6e720e..9197cc353c6 100644 --- a/mysql-test/r/show_explain.result +++ b/mysql-test/r/show_explain.result @@ -28,6 +28,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 5 NULL 10 Using where max(c) 9 +# We can catch EXPLAIN, too. +set @show_expl_tmp= @@optimizer_switch; set optimizer_switch='index_condition_pushdown=on,mrr=on,mrr_sort_keys=on'; explain select max(c) from t1 where a < 10; show explain for $thr2; @@ -35,4 +37,31 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan +set optimizer_switch= @show_expl_tmp; +# UNION, first branch +set @show_explain_probe_select_id=1; +set debug='d,show_explain_probe_1'; +explain select a from t0 A union select a+1 from t0 B; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +# UNION, second branch +set @show_explain_probe_select_id=1; +set debug='d,show_explain_probe_1'; +explain select a from t0 A union select a+1 from t0 B; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL drop table t0,t1; diff --git a/mysql-test/t/show_explain.test b/mysql-test/t/show_explain.test index dc54ebb9c52..77d79fc78b3 100644 --- a/mysql-test/t/show_explain.test +++ b/mysql-test/t/show_explain.test @@ -87,7 +87,9 @@ evalp show explain for $thr2; connection con1; reap; -# We can catch EXPLAIN, too. + +--echo # We can catch EXPLAIN, too. +set @show_expl_tmp= @@optimizer_switch; set optimizer_switch='index_condition_pushdown=on,mrr=on,mrr_sort_keys=on'; send explain select max(c) from t1 where a < 10; connection default; @@ -95,6 +97,28 @@ connection default; evalp show explain for $thr2; connection con1; reap; +set optimizer_switch= @show_expl_tmp; + + +--echo # UNION, first branch +set @show_explain_probe_select_id=1; +set debug='d,show_explain_probe_1'; +send explain select a from t0 A union select a+1 from t0 B; +connection default; +--source include/wait_condition.inc +evalp show explain for $thr2; +connection con1; +reap; + +--echo # UNION, second branch +set @show_explain_probe_select_id=1; +set debug='d,show_explain_probe_1'; +send explain select a from t0 A union select a+1 from t0 B; +connection default; +--source include/wait_condition.inc +evalp show explain for $thr2; +connection con1; +reap; # Let's try with a subquery diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index f42b9d9ee0e..917502f2b5b 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3667,7 +3667,11 @@ int st_select_lex_unit::print_explain(select_result_sink *output) if ((res= sl->print_explain(output))) break; } - if (!fake_select_lex->join) + + /* + Note: it could be that fake_select_lex->join == NULL still at this point + */ + if (fake_select_lex && !fake_select_lex->join) { res= print_fake_select_lex_join(output, TRUE /* on the fly */, fake_select_lex, 0 /* flags */);