When OR Just Won't Do: Using UNION for Higher SQL Performance
Copyright © 2024 PawSQL
Problem Definition
If two query conditions are connected by OR, the database optimizer may not be able to use indexes to execute the query. For example, for the following SQL statement:
select * from customer where c_phone like '139%' or c_name = 'Ray'
Even if both fields have indexes, they can be rewritten as a UNION query to leverage the indexes and improve query performance:
