June 18, 2013 at 5:18 am
Hi ,
I am confused I had seen a rather long query in SQL profiler its all on one line and I ran it to capture the query plan.
For readability I added some line breaks and executed it again.. and the query plan had totally changed to a far more efficient plan.
I thought I was mad so I went back and tried it again and again.. and every time the query plan was different when line breaks where introduced.
I have no idea why this is happening? Any ideas?
Many thanks
June 18, 2013 at 5:27 am
Whenever you fire same query second time or more, it will be faster anyways as it will pick the result from cache and gives faster results. This may be the reason for this.
June 18, 2013 at 7:13 am
Bhaskar.Shetty (6/18/2013)
Whenever you fire same query second time or more, it will be faster anyways as it will pick the result from cache and gives faster results. This may be the reason for this.
Hi I am aware of that , sorry I didn't make myself clear, interchanging between the two queries , one with no line breaks and one with line breaks causes a different execution plan to fire
June 18, 2013 at 7:18 am
Edward-445599 (6/18/2013)
Bhaskar.Shetty (6/18/2013)
Whenever you fire same query second time or more, it will be faster anyways as it will pick the result from cache and gives faster results. This may be the reason for this.Hi I am aware of that , sorry I didn't make myself clear, interchanging between the two queries , one with no line breaks and one with line breaks causes a different execution plan to fire
care to share the queries and exec plans?
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
June 18, 2013 at 8:18 am
J Livingston SQL (6/18/2013)
Edward-445599 (6/18/2013)
Bhaskar.Shetty (6/18/2013)
Whenever you fire same query second time or more, it will be faster anyways as it will pick the result from cache and gives faster results. This may be the reason for this.Hi I am aware of that , sorry I didn't make myself clear, interchanging between the two queries , one with no line breaks and one with line breaks causes a different execution plan to fire
care to share the queries and exec plans?
The query's are large and would take a while to rename everything for privacy. But that's beside the point I am more interested what would be the reason for something like this to happen?
Does anyone know of anything which who cause this to happen
June 18, 2013 at 5:08 pm
Remember, the query optimizer looks for a verbatimly equal query in the plan cache and will use that if it finds one. Your replacing CRs and LFs changes the query, hence it will look for a different plan, which if it doesn't exist will cause it to create a new one. And that leaves parameter sniffing out of the equation...
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply