Not sure what perf issue you're running into with that query. It seems like it is going to run just fine. One thing that comes to mind is character sets. We've seen perf issues in queries where the DB is using VARCHAR and we are passing parameters as NVARCHAR. The DB has to do a conversion which, for large tables is slow (relative).
You could try rewriting your query to this.
WHERE MyField = COALESCE(@MyParam, MyField)
If MyParam
is null then it compares MyField
to itself. Of course if that is a nullable field then it isn't going to work so well. Alternatively ISNULL
could also be used but I don't know that there is a perf difference.