📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

When can a filtered index fail to be used by an EF Core query, and how do you make sure it is?

Mid-Level Theory Intermediate

🎯 Key points

  • The optimiser must prove the query predicate implies the filter at compile time
  • Literals match; parameters usually do not (plan reuse)
  • Predicate shape must match: ORs, functions or different expressions break matching
  • Cost-based choice: an uncovered filtered index may lose to a scan
  • Filtered index statistics can be stale; update them after large changes
  • Global query filter DeletedAt == null becomes IS NULL and matches
  • EF.Constant forces a literal in EF Core 8+; verify in the actual plan

⏱ 30-second answer

SQL Server uses a filtered index only if it can prove at compile time that the query's predicate implies the index filter. It fails when: the filter value is a parameter (WHERE Status = @status), because the cached plan must work for any value; the predicate is written differently from the filter (an OR, a function, a different column expression) so the optimiser can't match it; the index doesn't cover the query and a scan looks cheaper on the cost estimate; or statistics on the filtered index are stale (they update on modifications to the filtered rows only, so they can lag). In EF Core, keep global query filters as simple literals (DeletedAt == null becomes IS NULL), use EF.Constant (EF Core 8+) where a fixed value matters, include the projected columns, and verify the seek in the actual plan.

🔍 What the interviewer is checking

Checks that the candidate understands how the optimiser matches filtered indexes, why parameterisation and predicate shape matter, and how to make EF Core generate SQL that uses them.

Green flags

  • Explains compile-time predicate matching and the parameter problem
  • Names EF.Constant or literal global filters as the fix
  • Mentions coverage, cost estimates and statistics
  • Verifies with the actual plan

Red flags

  • Assumes any index matching the column will be used
  • Proposes OPTION (RECOMPILE) everywhere as the fix

↩ Usually asked after

More in EF Core Performance

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me