Fast 1
After blogging recently (maybe?) about filters, there was a Stack Exchange question about a performance issue when a variable was declared with a max type.
After looking at it for a minute, I realized that I had never actually checked to see if a recompile hint would allow the optimizer more freedom when dealing with them.
CREATE INDEX u
ON dbo.Users(DisplayName);
DECLARE @d nvarchar(MAX) = N'Jon Skeet';
SELECT
COUNT_BIG(*) AS records
FROM dbo.Users AS u
WHERE u.DisplayName = @d;
SELECT
COUNT_BIG(*) AS records
FROM dbo.Users AS u
WHERE u.DisplayName = @d
OPTION(RECOMPILE);
Turns out that it won’t, which is surprising.

Even though both plans have sort of a weird seek, the filter operator remains as a weird sort of residual predicate.

Thanks for reading!
Going Further
For youWork With Your Databases the Way I DoVideo course, $250 until December 1, then $500For your teamAI for Database Teams WorkshopOne day, on-site or remoteOne-on-oneWork With Me for a Day$2,499
Someone still has to know enough SQL Server to keep the robots in check, and that’s what my training is for.
…And … what is Expr10004?
Is there any way the XML plan could help?