Optimal search queries

前端 未结 3 417
有刺的猬
有刺的猬 2021-01-15 14:34

Following on from my last question Sql Server query performance, and discovering that my method of allowing optional parameters in a search query is sub optimal, does anyone

3条回答
  •  天涯浪人
    2021-01-15 15:08

    Ok, here we go

    OPTION (RECOMPILE)

    is a must - otherwise the first query plan is being reused, regardless how the parameters match. Sorry, no real way to do that better.

    Besides that - no, sorry. Dynamic SQL can get more efficient (by avoiding the IS NULL alternatives), but you basically have it nailed down if that is not possible.

    With Dynamic SQL you basically do not have aline for HP.phonenumber if the HomePhone variable is null ;)

提交回复
热议问题