|
|
|
SSC-Dedicated
           
Group: Administrators
Last Login: Today @ 11:09 AM
Points: 31,416,
Visits: 13,730
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 30, 2013 11:18 PM
Points: 13,
Visits: 64
|
|
| I use them all the time on temporary tables. Where you have temp tables with lots of data, or they are joining onto normal tables with lots of data, adding an index can have a massive positive impact on performance in joins. The improvement far outweighs any overhead caused by SQL Server creating and updating the index.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, October 05, 2012 3:30 AM
Points: 138,
Visits: 351
|
|
Most definitely. Most common situation is a version-upgrade of the application where the schema is changing and data needs to be migrated (especially when a normalization-change is involved). The standard pattern for this is to add one or more additional (physical or computed) columns to the old tables that provide some new key used to obtain info handy for the migration. Create an index on those new columns if they are going to be used to filter the old data for migration purposes. Then build the new tables from the old (here the indexes could seriously speed up the migration process). BTW, all this could be part of the multi-step release patter described in Solomon's article "Restructure 100 Million Row (or more) Tables in Seconds. SRSLY!" (http://www.sqlservercentral.com/articles/Data+Modeling/72814/). Where those additional columns/indexes are created in the pre-release (as a separate new table).
Another case is to investigate some bug and I want to analyse the data in ways never foreseen in original development. Some additional indexes can help playing with the data-query iteratively in a timely fashion (having to wait 10s of seconds for a result can be very annoying when you want to play with the query after seeing the results). I normally do this in a database copied to my local machine, since this sort of querying could seriously hamper the production tables (being locked for long periods).
Marco
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, March 12, 2013 7:10 AM
Points: 146,
Visits: 36
|
|
| I do use temporary indexes when I'm crunching large datasets. This is usually the case for our month-end reports. In one report it cut our execution time from over 8 minutes to under 2. Even when I use table variables I've found performance gains by declaring a Primary Key if I can.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 6:25 AM
Points: 1,364,
Visits: 289
|
|
| Marco +1. I'll also use them in a version upgrade, where the schema is changing and I am converting tables to the new schema, I may need to store an old key in a table in order to use it to also convert the data in detail tables below the current one. In that case I'll create a temp (working) index on that old key, then drop the index and column at the end of the patch. Performance is vastly improved in the conversion.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, May 07, 2012 9:23 AM
Points: 304,
Visits: 716
|
|
I would guess that about 50-75% of our SQL use is to fill Datasets on the .NET side of things. We once had a talented DBA who suggested we use temporary indexes on a number of our SQL queries used to fill these Datasets in an effort in increase performance. We gave it a try...
What we found was that on queries that fill large Datasets, we did see some improvement, but on smaller (or some medium) fills, the temporary indexes were actually slowing performance. We were able to increase performance there by making a number of these indexes permanent so we avoided the create-on-the-fly element involved.
What is interesting about all this is that in "our world" we have to do a bit of experimenting each time we get into these situations. For example, sometimes its better to take just a plain old 'give me the data' Dataset fill, and then play with code on the .NET side to get whatever result we might be after - where other times (especially in reporting) we find its better to work on the SQL side and tweak around with temporary indexes and in some cases temporary tables/cursors to maximize performance.
I think temporary indexes have their place, but like most 'get the data' situations in software development, they are not the be-all-end-all answer to performance. They can be in individual cases, but it really depends on what the end goal is, and that takes some experimenting to determine.
There's no such thing as dumb questions, only poorly thought-out answers...
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:44 AM
Points: 1,555,
Visits: 1,925
|
|
blandry (4/29/2011) What we found was that on queries that fill large Datasets, we did see some improvement, but on smaller (or some medium) fills, the temporary indexes were actually slowing performance. We were able to increase performance there by making a number of these indexes permanent so we avoided the create-on-the-fly element involved.
I was actually wondering how many of these would work better as permanent indexes. The last place I worked used them for upgrades but that was it. We did index temporary tables but in those cases the indexes were permanent in relation to the lifespan of the table so I wouldn't consider those temporary indexes.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 1,162,
Visits: 3,333
|
|
SQL Server routinely creates temporary "index" structures in memory or tempdb all the time, like during a hash join on large tables. Staging tables and temporary indexes are common in scenarios where a moderate amount of reporting is performed directly out of the OLTP database rather than from a snapshot or external data mart. This can speed up the reporting process, but of course it will also result in a lot of transaction logging. When I stage data for something like month end reporting purposes it's in summary form, and I generally retain it for archival purposes in case the reports need to be re-run later or leveraged for some other BI process. In that case the indexes are on the staging tables, so there is not so much reason to drop them afterward.
"Wise people understand the 10,000 things without going to each one. They know them without having to look at each one, and they transform all without acting on each one." - The Tao Te Ching: Verse 47
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Yesterday @ 12:28 PM
Points: 675,
Visits: 2,031
|
|
Quite common: indexes on #temp tables.
Uncommon, but not unheard of: temporary indexes on permanent tables, always as a result of benchmarking with our actual production dataset such that the aggregate (Profiler SQL:BatchCompleted) stats, particularly Reads and Writes, are significantly better (including all the overhead) with the temporary index than without.
As another user mentioned, these really depend.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|