Found an interesting little problem recently. We had a query we wanted to upgrade for the next release, and added an OR statement to allow us to pre-release the functionality for the new code drop. This had a really big impact on performance and caused lots of issues.
When we investigated it turns out that OR queries in a join are really expensive. Consider the following statement.
The sql query analyser can’t do anything to optimize this query, and effectively runs the following…
If you want to squeeze performance out of it - consider the following alternative…
This runs more quickly.
Obviously the most ideal scenario is you refactor the data and add a proper key!