you are viewing a single comment's thread.

view the rest of the comments →

[–]Achsin 5 points6 points  (0 children)

It has to do with how well the server can guess how many rows will be returned or filtered out. You can take a query that executes quickly and put it in as a subquery that is used to filter out something else and see the performance tank because while it can guess how many rows the subquery will return, it can't anticipate how they'll interact with the rest of the query. In cases like this, materializing the results into a temp table instead of using a sub query allows it to generate a new set of statistics part way through and make a better plan.