How can I force a subquery to perform as well as a #temp table?

后端 未结 4 2085
既然无缘
既然无缘 2020-12-17 08:21

I am re-iterating the question asked by Mongus Pong Why would using a temp table be faster than a nested query? which doesn\'t have an answer that works for me.

Mos

4条回答
  •  天涯浪人
    2020-12-17 08:54

    I do not believe there is a query hint that instructs the engine to spool each subquery in turn.

    There is the OPTION (FORCE ORDER) query hint which forces the engine to perform the JOINs in the order specified, which could potentially coax it into achieving that result in some instances. This hint will sometimes result in a more efficient plan for a complex query and the engine keeps insisting on a sub-optimal plan. Of course, the optimizer should usually be trusted to determine the best plan.

    Ideally there would be a query hint that would allow you to designate a CTE or subquery as "materialized" or "anonymous temp table", but there is not.

提交回复
热议问题