Alternative to using local variables in a where clause

后端 未结 4 1657
清歌不尽
清歌不尽 2021-01-24 07:24

I have a query that has a where clause built using a number of local variables, This however is painfully slow. Below is a rough example as I don\'t have access to the query cur

4条回答
  •  无人共我
    2021-01-24 07:39

    No.

    For constants, the optimizer can work out the best plan based on statistics for the given values.

    When you use variable you are forcing parameterization and the plan will be designed to be reusable for a wide range of values.

    In this case you can try OPTIMISE FOR UNKNOWN which may give better results. Or don't filter like this: use different queries for different permutations. Do you have LIKE too with leading wildcards?

提交回复
热议问题