Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

SSRS query performance (dynamic SQL vs. stored proc) Expand / Collapse
Author
Message
Posted Monday, August 12, 2013 2:12 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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
Post #1483457
Posted Monday, August 12, 2013 2:51 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:15 PM
Points: 13,731, Visits: 10,692
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1483470
Posted Monday, August 12, 2013 3:35 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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
Post #1483481
Posted Tuesday, August 13, 2013 12:10 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:15 PM
Points: 13,731, Visits: 10,692
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1483569
Posted Tuesday, August 13, 2013 7:05 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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

Post #1483710
Posted Tuesday, August 13, 2013 8:30 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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
Post #1483770
Posted Tuesday, August 13, 2013 9:45 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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
Post #1483833
Posted Wednesday, August 14, 2013 6:27 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 7:46 AM
Points: 316, Visits: 1,487
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



Post #1484238
Posted Wednesday, August 14, 2013 8:51 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 10:46 AM
Points: 1,976, Visits: 3,280
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.

Post #1484344
Posted Friday, August 16, 2013 6:04 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 1,184, Visits: 1,219
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
Post #1485140
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse