SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSRS query performance (dynamic SQL vs. stored proc)


SSRS query performance (dynamic SQL vs. stored proc)

Author
Message
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
In SSRS 2008 R2, I have a query that runs in 5-8 seconds in SSMS. When I run the report it takes about four minutes and when I run the same query in Report Builder's Query Designer it takes about four minutes. (db, query, SSRS, all running locally)

I turned on profiler to capture the activity between the query run in SSMS vs. the query run in SSRS and I see that SSRS puts my query in a string and does an exec sp_executesql command. Is it the dynamic SQL in the sp_executesql that's giving such a dramatic performance difference?

If I change the report's data source to a stored procedure would that eliminate this seeming overhead?

Thanks,
Rob
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27701 Visits: 13268
Are you sure the reason the report runs so long is the query (data retrievel) and not the generation of the report?


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
Koen,

No, I'm not positive in what takes the report so long. I'm not sorting or filtering in SSRS -- that's all taken care of in the query; it's a pretty basic rows and columns report. My only clue seems to be when I watch SQL Server with profiler running SSRS seems to wrap the SELECT in an executesql. I can then copy this executesql into SSMS and that takes minutes compared to executing the statements outside the executesql which takes under 10 seconds.

Rob
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27701 Visits: 13268
Maybe parameter sniffing? I noticed some threads where this was the cause of slow SSRS reports.

T-SQL Best Practices - Parameter Sniffing


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
Thank you for the link -- a good explanation of parameter sniffing. Perhaps you're on to something with parameter sniffing. My Confio tool (Ignite) did say that the execution plan had changed for this query -- though when I compare the two execution plans they look exactly the same to me (as viewed in SQL Sentry's Plan Explorer). There has been a schema change -- a bit field was added to one of the tables used in the query, though that particular new field is not used anywhere in this particular query.

The query brings back customers for open sales orders. I ran it individually for each of our franchises and the number of records returned didn't vary all that much (approx. 10 - 100 records per run).

Rob
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
I'm running on a dev box and I'm the only one on it, so I can do a check point and flush caches ect. to get reasonable timings.

I changed the report's dataset from SQL (text) to executing a stored procedure and I still get similar results. When I execute the stored proc in SSMS, it executes in 5-8 seconds, but the report takes 4 minutes to generate.

That sure makes it seem like it's something in SSRS and dynamic SQL as I first thought.

Rob
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
We ended up changing the SharePoint "Manage Processing Options" setting to allow the report to run an unlimited time. This didn't speed anything up, but it did stop the report from "timing out".

Rob
peterzeke
peterzeke
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 1766
Rob --

Two things:

1) Did you actually modify the query to handle parameter sniffing? From my own experience, I've had situations where parameter sniffing was the problem -- modifying a stored proc to include a declared variable that gets assigned the parameter value that is initially passed to the stored proc solved my performance problems.

2) I've also had problems with a slow report if the sql was returning a dataset as "Select * From ...." Changing the "*" to an explicit list of fields has proven beneficial.

--pete



Gazareth
Gazareth
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4046 Visits: 5843
Could be a difference in SET options between SSMS & SSRS? (I'm thinking ARITHABORT)

You can query the TimeDataRetrieval, TimeProcessing, and TimeRendering fields in ReportServer.dbo.ExecutionLog view to find what's taking all the time.
robert.gerald.taylor
robert.gerald.taylor
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1810 Visits: 1493
Pete,

Thanks for your feedback.

peterzeke (8/14/2013)

1) Did you actually modify the query to handle parameter sniffing? From my own experience, I've had situations where parameter sniffing was the problem -- modifying a stored proc to include a declared variable that gets assigned the parameter value that is initially passed to the stored proc solved my performance problems.

Yes; at the top of the stored proc, I set local declared variables equal to the parameters and then use the local variables in the WHERE clause of the query.


2) I've also had problems with a slow report if the sql was returning a dataset as "Select * From ...." Changing the "*" to an explicit list of fields has proven beneficial.

No SELECT * in the query either -- I explicitly list the fields.

Thanks,
Rob
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search