Skip to content

Commit

Permalink
MDEV-18700 EXPLAIN EXTENDED shows a wrong operation for query
Browse files Browse the repository at this point in the history
           with UNION ALL after INTERSECT

EXPLAIN EXTENDED erroneously showed UNION instead of UNION ALL in
the warning if UNION ALL followed INTERSECT or EXCEPT operations.
The bug was in the function st_select_lex_unit::print() that printed
the text of the query used in the warning.
  • Loading branch information
igorbabaev committed Feb 23, 2019
1 parent 4946eb7 commit 09bd213
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
37 changes: 37 additions & 0 deletions mysql-test/main/union.result
Original file line number Diff line number Diff line change
Expand Up @@ -2568,5 +2568,42 @@ c1
-10
drop table t1,t2;
#
# MDEV-18700: EXPLAIN EXTENDED for query with UNION ALL
# after INTERSECT/EXCEPT operations
#
create table t1 (a int);
insert into t1 values (3), (1), (7), (3), (2), (7), (4);
create table t2 (a int);
insert into t2 values (4), (5), (9), (1), (8), (9);
create table t3 (a int);
insert into t3 values (8), (1), (8), (2), (3), (7), (2);
explain extended
select * from t2 where a < 5
intersect
select * from t3 where a < 5
union all
select * from t1 where a > 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
2 INTERSECT t3 ALL NULL NULL NULL NULL 7 100.00 Using where
3 UNION t1 ALL NULL NULL NULL NULL 7 100.00 Using where
NULL UNIT RESULT <unit1,2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where `test`.`t2`.`a` < 5 intersect /* select#2 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where `test`.`t3`.`a` < 5 union all /* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4
explain extended
select * from t2 where a < 5
except
select * from t3 where a < 5
union all
select * from t1 where a > 4;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
2 EXCEPT t3 ALL NULL NULL NULL NULL 7 100.00 Using where
3 UNION t1 ALL NULL NULL NULL NULL 7 100.00 Using where
NULL UNIT RESULT <unit1,2,3> ALL NULL NULL NULL NULL NULL NULL
Warnings:
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where `test`.`t2`.`a` < 5 except /* select#2 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where `test`.`t3`.`a` < 5 union all /* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4
drop table t1,t2,t3;
#
# End of 10.3 tests
#
30 changes: 30 additions & 0 deletions mysql-test/main/union.test
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,36 @@ SELECT c1 FROM t1 UNION SELECT - @a FROM t2;

drop table t1,t2;

--echo #
--echo # MDEV-18700: EXPLAIN EXTENDED for query with UNION ALL
--echo # after INTERSECT/EXCEPT operations
--echo #

create table t1 (a int);
insert into t1 values (3), (1), (7), (3), (2), (7), (4);

create table t2 (a int);
insert into t2 values (4), (5), (9), (1), (8), (9);

create table t3 (a int);
insert into t3 values (8), (1), (8), (2), (3), (7), (2);

explain extended
select * from t2 where a < 5
intersect
select * from t3 where a < 5
union all
select * from t1 where a > 4;

explain extended
select * from t2 where a < 5
except
select * from t3 where a < 5
union all
select * from t1 where a > 4;

drop table t1,t2,t3;

--echo #
--echo # End of 10.3 tests
--echo #
4 changes: 2 additions & 2 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2897,8 +2897,6 @@ void st_select_lex_unit::print(String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN(" union "));
if (union_all)
str->append(STRING_WITH_LEN("all "));
else if (union_distinct == sl)
union_all= TRUE;
break;
case INTERSECT_TYPE:
str->append(STRING_WITH_LEN(" intersect "));
Expand All @@ -2907,6 +2905,8 @@ void st_select_lex_unit::print(String *str, enum_query_type query_type)
str->append(STRING_WITH_LEN(" except "));
break;
}
if (sl == union_distinct)
union_all= TRUE;
}
if (sl->braces)
str->append('(');
Expand Down

0 comments on commit 09bd213

Please sign in to comment.