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

Statistics on temp table Expand / Collapse
Author
Message
Posted Thursday, January 2, 2014 9:23 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, November 17, 2014 9:57 AM
Points: 323, Visits: 1,471
From what I've read, temp tables do have statistics on them. Would SQL Server create its own on them if you don't have an index on the table? Like the _WA_Sys ones.They're tough to find and DBCC ShowStatistics requires a statistic name.

This could be a red herring as I don't see a lot of folks asking about this.

Ken
Post #1527185
Posted Thursday, January 2, 2014 9:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Today @ 12:16 PM
Points: 301, Visits: 1,276
Grant Wrote a wonderful article on statistics early this year, explaining stats on Temp Tables/Variables.

From his article:
Are statistics created on temporary tables?
Yes. The major difference between a table variable and a temporary table is that a temporary table has statistics. The rules for the creation and maintenance of these statistics are exactly the same as for a regular table within SQL Server. So if you reference a column in a temporary table in a filtering command in T-SQL such as WHERE or JOIN, then a set of statistics will get created. Unfortunately, the creation of the statistics causes a statement recompile. This is a potential disadvantage of temporary tables: For small statements this is a cheap operation. For larger queries this can be very expensive. That’s a reason why you have to be careful about how you work with your temporary tables.

You can find his full article(where I got this info) here for more details on Statistics: https://www.simple-talk.com/sql/performance/sql-server-statistics-questions-we-were-too-shy-to-ask/
Post #1527196
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse