SQL Server Interview Question #220

A query is fast in SSMS but slow from an ASP.NET Core application. How would you investigate it?

Advanced Query Optimization Senior Advanced

Detailed Explanation

First confirm that SSMS and the application are truly executing equivalent SQL against the same database, server, data, parameters, and transaction context.

Capture the application's actual SQL and parameter values using appropriate application logging, Query Store, Extended Events, or database monitoring. Compare execution plans and runtime statistics. Check parameter data types and lengths, parameter-sensitive plans, SET options, connection/database context, blocking, transaction scope, network latency, result-set size, and ORM-generated SQL.

With EF Core, also inspect whether the application is causing N+1 queries, unnecessary tracking, premature materialization, client-side processing, excessive Include operations, or retrieving columns/rows it does not need.

The key interview point is that 'fast in SSMS' does not prove the database query is identical to the application's workload. Troubleshooting must compare the actual execution contexts before selecting a fix.