Conditional execution one of two parts of union all query
I have have two complex, expensive queries that I have performed a union all to bring together for use in a report tool
I have a bind variable that, if set to one value, the union query should execute the first part of the union. If the bind variable is set to a second value, then the second part of the union query should be executed.
However, when I look at trace and/or explain plans for my query, there is a cost coming from BOTH parts of the union query.
Here is a simplified version of what I am trying to do :