The following is an example shows a SQL statement with two union operator in a subquery. The SQL retrieve records from EMPLOYEE table that EMP_ID should satisfy with the union result set from two queries in a subquery.
select * from employee
where emp_id IN
Here the following are the query plans in Tosska proprietary tree format, it takes 3 minutes 27 seconds...
How to Tune SQL Statement with Multiple Union in Subquery for MySQL?
select * from employee
where emp_id IN
(select emp_id from emp_subsidiary where emp_grade=1000
union
select emp_id from employee where emp_dept='AAA')
union
select emp_id from employee where emp_dept='AAA')
Here the following are the query plans in Tosska proprietary tree format, it takes 3 minutes 27 seconds...
How to Tune SQL Statement with Multiple Union in Subquery for MySQL?