views:

29

answers:

1

Hi There,

i have many queries which needs to be tunned and i was relaying on DTA(datbase engine tuning adviser which comes with sql 2005) to give me some recommendation on indexes. but looks like DTA fails to understand the queries which uses temp tables . is there any way we could get the index recommendation.

Thanks for your suggestions

Regards DEE

+1  A: 

To do this sort of thing you will have to pull the stored procedures apart and set up some 'fake' scenarios based on the temp tables built by the sprocs (i.e. make a scratch database and reconstruct the tables as permanent tables). Set up the scenario and try tuning advisor on it.

In practice, you're pretty much stuck doing this sort of thing if you want to tune sprocs that use temporary tables in any particularly complex way.

ConcernedOfTunbridgeWells
Thanks for your comment , but if i do this and DTA advices to create indexes on the faked tables(temp tables) , then what is the next resort?
DEE
Well, you could create indexes on the #temp tables as part of the stored procedure code, if they make sense. I have several modules where I create a #temp table and then create indexes on them before performing any work. How many rows go into the #temp tables typically? Have you tried table variables or CTEs?
Aaron Bertrand
it has been my experience that if if you have enough rows in a #temp table to need an index, then @table_variables will be even slower
KM
As Aaron Bertrand says, you can modify the stored procedures to create indexes on the temporary tables (you can create clustered indexes on temp tables as well). After that, do a benchmark on before/after performance to see if you got any significant benefit.
ConcernedOfTunbridgeWells