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

Performance using CTE vs temp tables Expand / Collapse
Author
Message
Posted Thursday, December 13, 2012 5:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, August 8, 2014 5:51 AM
Points: 48, Visits: 297
Hi All,

I have replaced 3 temp tables in my batch with multiple CTEs.
I see remarkable 50% benefit in REads and Writes have reduced to 0, however, I wanted to know on the CPU.
Is CTE CPU Intensive? I am getting varying CPU results.

Also, I see from other questions that CTEs hit performance when table size is v great. Is that so?
Post #1396135
Posted Thursday, December 13, 2012 8:23 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 8:27 AM
Points: 37,076, Visits: 31,637
nidhis (12/13/2012)
Hi All,

I have replaced 3 temp tables in my batch with multiple CTEs.
I see remarkable 50% benefit in REads and Writes have reduced to 0, however, I wanted to know on the CPU.
Is CTE CPU Intensive? I am getting varying CPU results.

Also, I see from other questions that CTEs hit performance when table size is v great. Is that so?


"It Depends" on what the Temp Tables are being used for and how they are being used. Just like views and derived tables, CTEs can be quite good at performance and quite bad.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1396459
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse