I have been working on a solution (in SQL Server) where all the sub queries with no exception have been rewritten with temp tables in order to boost performance.
To give an example, all the queries like this:
SELECT something
FROM (SELECT * FROM T1 WHERE condition1)
JOIN ...
have been rewritten to be like this:
SELECT *
INTO #tempTable
FROM T1
WHERE condition1
SELECT something
FROM #tempTable
JOIN ...
It has also been suggested here that all sub queries should be avoided in favor of temp tables.
Based on the given facts, Should all sub queries be replaced with temp table? If not when should one be considered over the other?
http://stackoverflow.com/questions/16767645/why-is-there-a-huge-performance-difference-between-temp-table-and-subselect and this:
http://stackoverflow.com/questions/2825342/why-would-using-a-temp-table-be-faster-than-a-nested-query – Putra Christianto Purba Mar 13 '17 at 20:08