I have a sql query that runs super fast, around one second, when not using variables, like:
WHERE id BETWEEN 5461094 and 5461097
But when I
Is ID in an Index (eg Primary Key)? If not, try adding one.
Another thing could be that in the first (fast) instance the query is getting executed slightly differently. The most common thing I've seen happen is that the joins get done in an inefficient order. Try re-ordering the joins, or converting some to subqueries. If you post more of your query we can assist further.