May 2, 2012 at 10:25 am
This one has me sort of stumped. When I profile this not only does the time increase but so does cpu and logical reads. Reads go from 16,000 to 44 million.:w00t:
May 2, 2012 at 11:18 am
Could be a result of bad parameter sniffing. Without more information as to what the stored procedure does, the calls that are made to it (i.e. parameters), and execution plans though it's just going to be guessing at this point. Please post more details.
May 2, 2012 at 11:24 am
Thomas Stringer (5/2/2012)
Could be a result of bad parameter sniffing. Without more information as to what the stored procedure does, the calls that are made to it (i.e. parameters), and execution plans though it's just going to be guessing at this point. Please post more details.
No parameters. Just stored procedure call from SSMS vs same call from agent job.
May 2, 2012 at 11:56 am
The problem here is that we can't see what you see. What little you have provided only allows us to take wild shots in the dark and hope the answer fits your problem.
Read the second article I reference below in my signature block. Follow the instructions and we should be able to help you.
May 2, 2012 at 12:44 pm
Lynn Pettis (5/2/2012)
The problem here is that we can't see what you see. What little you have provided only allows us to take wild shots in the dark and hope the answer fits your problem.Read the second article I reference below in my signature block. Follow the instructions and we should be able to help you.
This really comes down to a different query plan being generated when I run this from an agent job. Here the part of the query doing the bulk of the work and the 2 plans that are generated. I did forget to mention this is a linked server query. Can't really post the DDL because there are too many tables.
May 2, 2012 at 12:45 pm
There has to be something that sql agent is doing or isn't doing that would cause a different query plan to be generated.
May 2, 2012 at 12:49 pm
as mentioned, without specifics, wer can only guess;
a different process smay have different ANSI settings, like ANSI NULLS, etc, which can affect the query(whatever it does).
it could be the database context is not what you think it is.
it could be something related to permissions.
it could be that it is thrashing around in tempdb, and that's what takes too long.
Lowell
May 2, 2012 at 12:52 pm
doesn't the slow plan say it is copying 3.8 million rows @ 115 gig via a table spooll from the linked server?
Lowell
May 2, 2012 at 1:03 pm
Lowell (5/2/2012)
doesn't the slow plan say it is copying 3.8 million rows @ 115 gig via a table spooll from the linked server?
Indeed it does. Actual is 0 rows.
May 2, 2012 at 1:14 pm
As others mentioned, we can only guess.
From your query, why you use "UNION" and "DISTINCT" at the same time? You can use "UNION ALL" and "DISTINCT". It may save you a little bit time.
Since a linked server is involved, is the remote login a db_ddladmin role in the remote database? If not, it can't use the stats on the remote tables.
(I guess your linked server uses "Be made using the login's current security context" since you did have the issue when you ran it from SSMS by yourself.)
-------
Edit: .....you did not have the issue....
May 2, 2012 at 1:22 pm
Wildcat (5/2/2012)
As others mentioned, we can only guess.From your query, why you use "UNION" and "DISTINCT" at the same time? You can use "UNION ALL" and "DISTINCT". It may save you a little bit time.
Since a linked server is involved, is the remote login a db_ddladmin role in the remote database? If not, it can't use the stats on the remote tables.
(I guess your linked server uses "Be made using the login's current security context" since you did have the issue when you ran it from SSMS by yourself.)
-------
Edit: .....you did not have the issue....
Linked server uses "Be made using this security context". The login on the remote server is not db_ddladmin.
May 2, 2012 at 1:33 pm
Wildcat (5/2/2012)
As others mentioned, we can only guess.From your query, why you use "UNION" and "DISTINCT" at the same time? You can use "UNION ALL" and "DISTINCT". It may save you a little bit time.
Since a linked server is involved, is the remote login a db_ddladmin role in the remote database? If not, it can't use the stats on the remote tables.
(I guess your linked server uses "Be made using the login's current security context" since you did have the issue when you ran it from SSMS by yourself.)
-------
Edit: .....you did not have the issue....
Dude!, It was the distinct. Don't need it. Union alone does the trick.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply