OK now, I have a moderately large and ugly dynamic query from the entity framework coming in, and I thought I'd try playing with it. I added a few indexes and took it from 150++ seconds to about 10 seconds.
It's full of our favorite construction (but SQL Server's not favorite), "where (@foo = null or @foo = sometable.foo)". There's a bunch of these, and the values mostly are null, fwiw. OK, I thought, let's try slapping an option(recompile) on it and see if that helps.
So what happens? The compile time alone is six seconds. Well, but maybe we make it up in volume? Nosir. Execution time increases to 46 seconds - total 52 minus the compile time. Logical reads go from 10m to 25m.
Now, is that fair?
I mean, shouldn't that basically never happen?
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
Thanks,
Josh