January 26, 2014 at 5:46 pm
Simple question, are the results of a CTE stored in the same place as a temp table (tempdb)?
Thanks
January 26, 2014 at 6:08 pm
smallmoney (1/26/2014)
Simple question, are the results of a CTE stored in the same place as a temp table (tempdb)?Thanks
As with a View or any query, for that matter, they might not be stored at all. Proof of that is if you call the CTE twice as a self join. If you look at the execution plan, you'll see that the CTE actually had to run twice. Any interim storage required by a query, for a working table to support a hash join for example, will make use of TempDB.
That being said, TempDB is NOT disk only. If the optimizer can and does allocate memory for the task, the TempDB part of it will be done in memory. Similarly (and just to be sure), Table Variables are NOT memory only. They will spill to disk if they get too big.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 27, 2014 at 12:10 am
CTEs aren't tables. They're named subqueries. Their results are not necessarily materialised or stored anywhere.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply