Why does a query slow down drastically if in the WHERE clause a constant is replaced by a parameter (having the same value)?

前端 未结 4 1951
清歌不尽
清歌不尽 2021-01-02 03:19

I have a recursive query which executes very fast if the WHERE clause contains a constant but becomes very slow if I replace the constant with a parameter havin

4条回答
  •  Happy的楠姐
    2021-01-02 03:54

    For your second Query try using the OPTIMIZE FOR or OPTION(RECOMPILE) query hint to see if that forces it to recomplile based on the provided parameter value.

提交回复
热议问题