Why is this CTE so much slower than using temp tables?
问题 We had an issue since a recent update on our database (I made this update, I am guilty here), one of the query used was much slower since then. I tried to modify the query to get faster result, and managed to achieve my goal with temp tables , which is not bad, but I fail to understand why this solution performs better than a CTE based one , which does the same queries. Maybe it has to do that some tables are in a different DB ? Here's the query that performs badly (22 minutes on our hardware