In some cases, a SQL statement can be simplified by using procedural logic.  Instead of issuing one complex query to cover multiple cases with UNION or OR, it is better to use and if..else logic to separate the cases into different SQL statements.  In this way, the optimizer optimizes multiple simpler statements instead of a single complex statement and may be able to get better performing plans for each case.