I have a code which basically implements the below logic
select something
from few tables
where not exists (select query with some logic, say L1)
union all
select query with logic L1
As you can see, the select query with logic L1 is being run twice. It is quite a big logic and could take some time to run. Is there anyway to re-format the code to make the execution better?