I am struggling with query that takes long time. Just briefly, I have got two CTE's that have not much data and joining them take long time (about 10 seconds). But when I pack each cte into pure temp table like this:
with cte as (...)
select * into tbl_cte from cte
and then join temp tables, everything works very fast.
I can't understand why this approach is faster. I don't use either an identity column or primary key on temp tables.