question

chan avatar image
chan asked

SSRS 2008 Temp Table

Hi, Here is the what i have encountered. I have a report which uses a couple of temp tables. The reports are deployed and here is the issue. The execution time of report is changing with No.of users. If 2 or 3 users run the report at the same time, then the time taken to run the report is longer almost double. Is it bcoz of using temp tables. Anyone encountered it before. what is the solution for this. [Edit by moderator. Details transferred from content supplied in an answer] @Kev Riley -- Thanks for the quick reply Here is the psuedo code. If i replace the temp tables with temp variables, then with no of users the execution time remains the same. Any idea why this happens with only temp tables I have 3 parameters, they are the zone, state and job type CREATE TABLE #table1 ( Cnt INT, MM INT ) CREATE TABLE #Mth ( MM VARCHAR(6) ) INSERT INTO #Mth(MM) SELECT -- (12 Distinct Months ) INSERT INTO #table1 Select --------- FROM (Joins) WHERE ----------- GROUP BY -------------- SELECT * FROM #table1 -- DataSet Output DROP TABLE (Temp Tables), If i replace the temp tables with temp variables, then with no of users the execution time remains the same. Any idea why this happens with only temp tables
tempdbreporting_servicestemporary-tables
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
This may sound harsh, but if you've not got the access to view the execution plan, you might be the wrong person to ask sort out the performance issue. It's like asking a mechanic to look at your badly running car, but then say he can't have the keys!!!
1 Like 1 ·
chan avatar image chan commented ·
@Sacred Jewel -- Thanks for the quick reply I am not using Stored proc and i typically join 4 tables for the report and i do not have access to look at execution plan !!! Well i executed the same report from 2 or 3 different PC's in report viewer. Thats how i saw the slow performance. Any insight is greatly appreciated.
0 Likes 0 ·
Usman Butt avatar image Usman Butt commented ·
+1. Nice example ;)
0 Likes 0 ·
chan avatar image chan commented ·
@Kev Riley -- Good example, I know, but sometimes u have to work the way it is. Thanks all for your time, i will try looking at the execution plan hopefully soon.
0 Likes 0 ·
Kev Riley avatar image
Kev Riley answered
At a guess I would say that you have a bad execution plan, possibly caused by parameter sniffing, possibly due to differing uses of the underlying query - can you post the query and sample parameters?
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

SirSQL avatar image SirSQL commented ·
You could also be running into tempdb contention, especially if you are loading large datasets into the temp tables.
1 Like 1 ·
Sacred Jewel avatar image Sacred Jewel commented ·
You can also use OPTION(RECOMPILE), OPTION(OPTIMIZE FOR @variable_name = literal_constant [ ,…n ] ) for that matter. I've found the latter more handy in certain cases. I feel the ugly code is hidden under your joins (missing indexes) and you are highlighting the temporary table issue. It can also be a case of outdated statistics... It will be interesting to know how did you find that it happens when multiple users access it? Why don't you attach the execution plan to clarify?....Also, your psuedo code does not justify the use of temporary tables at all. Post your query and hopefully I will show why don't you need them ;)
1 Like 1 ·
chan avatar image chan commented ·
@sirsql -- I have about 2232 rows as the output of 1 st table and 100 rows as the final output of second table. I am just wondering why the execution time varies with Temp tables only when multiple users access the report
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
Try using local variables instead of the parameters in the query
0 Likes 0 ·
Gogolo avatar image
Gogolo answered
Try to Lock a Stored Procedure for Single Use Only, I think that this would be a good solution for your problem.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
That would rule out ANY concurrency - there are better ways of solving this problem.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.