As far as I know, the OPTIMIZE FOR
hint helps to avoid parameter sniffing.
For such a stored procedure:
SELECT * FROM Table WHERE param=@param1
We have two parameters S1
with high selectivity and S2
with low selectivity.
If we are using such a hint:
OPTION(OPTIMIZE FOR @param1=S1)
and then send S2
to the stored procedure, we have still parameter sniffing.
Now I have a conceptual question:
How does the OPTIMZE FOR
hint help us avoid parameter sniffing?