slow run on query when is joined with another view
When I run this query it takes 37 s to execute,
When I join it with another view it takes 11 mins to execute.
But the other view only takes 3 s to execute alone.
Would can be the issue?
Thanks in advance
The thing to keep in mind is that if it takes 3s to execute one operation against your second view, joining that operation to another view isn't additive, it's MULTIPLICATIVE.
So depending on where in the 1st view you join to the 2nd, you might need to multiply the 3s of the 2nd view by the number of estimated rows for the join operation in the 1st view. Most of those operations estimate 5k to 6k rows.
Is there any chance you can create intermediate temp tables rather that doing this in a single huge, multipart view?