I had written a cte which has come complex joins and selected 7 columns for output. It contained 4 million rows.
Now I write my Cte like this:
with cte as
tbl1 Join tbl2 ....
(above code is just for reference)
When I execute :
select * from cte : takes 14 secs
select count(1) from cte : takes 1 sec.
Now my question is, when I ask for the count does SQL ignore all the columns defined in the cte ?
Which would essentially mean that based on how you query CTE, the definition would be compiled ?