I have two SQL queries, each of which is about 2-3 INNER JOINS. I need to do an INTERSECT between them.
The problem is that individually requests are executed quickly, but after crossing it takes only about 4 seconds.
Now, if I put OPTION (RECOMPILE) at the end of this entire query, the query works fine, working pretty fast again, returning almost instantly!
I understand that the recopile option forces me to rebuild the execution plan, so I'm confused now if my request for the early ones, which takes 4 seconds, is better or now the one that is recompiled, but best for 0 seconds.
optimization sql sql-server
Saurabh kumar
source share