I've read up on the SQL Server 2008 OPTIMIZE FOR UNKNOWN query hint. I understand how it works.
However, I have a question on where and when to use it. It cannot be specified inside a UDF. It can be specified inside a stored proc. However, this MSDN blog post states the following:
4.Moving a query into a stored procedure can put it into a separate procedural context and can be a good way to get that value visible to the optimizer (Note: this works in SQL 2000 as well)
That seems to me to be saying that any parameter passed to a stored proc will be "sniffed", thereby helping SQL Server to compile an optimum execution plan. This is implying that the cached plan would be revisited/recompiled (not sure of that mechanism). However, this is confusing, because it negates the whole need for OPTIMIZE FOR UNKNOWN.
The MSDN article on query hints doesn't cover my question.
Can someone answer this for me, ideally with a pointer to something from Microsoft that clears this up. Thanks.