iTask’s SQL Server consulting starts from one fact: a slow database is often treated as a server problem. In our experience, the problem is usually in the query, the index or the long transaction. That is why, before talking about hardware, we open Query Store.
We have maintained SQL Server systems for years, from an order system with an SSDT project to messaging platforms. The techniques below come from that work.
How we diagnose
Query Store. We turn on Query Store and let it collect for a few days of real traffic. For each query it keeps the plans used, duration, CPU and reads. It shows regressions: the same query that started using a worse plan after a statistics or version change.
Execution plans. We read the actual plan, and not only the estimated one. We look for table scans where a seek was expected, key lookups at high volume, row estimates far from the real count, spills to tempdb and expensive sort operators.
Wait statistics. Waits say where the server waits: disk, memory, locking, CPU. They separate a query problem from an infrastructure problem.
Index DMVs. Missing, unused and duplicate indexes come from dm_db_missing_index and dm_db_index_usage_stats. We treat the suggestions as a clue and not as an order. A suggested index may overlap another that already exists.
What we usually find
- Non-sargable queries. A function on the filter column, implicit type conversion and LIKE with a leading wildcard prevent index use.
- Parameter sniffing. A plan that is good for one parameter is terrible for another. We handle it with a rewrite, a targeted OPTION (RECOMPILE) or plan forcing through Query Store.
- Indexes that are too wide. Unneeded columns bloat the index. We use included columns with judgment.
- Long transactions. Holding a transaction open during an external call blocks other sessions and causes deadlocks.
- OFFSET paging on large tables. Switch to keyset paging and latency becomes stable.
- Reports on the transactional database. We move them to a read replica, an aggregate table or queue processing.
Deadlocks and blocking
We capture the deadlock graph with extended events. The most common pattern is two transactions that access the same tables in opposite order. The fixes, in order of preference:
- Always access tables in the same order.
- Shorten the transaction and remove any external call from it.
- Create the index that avoids the scan and reduces the set of locked rows.
- Use READ_COMMITTED_SNAPSHOT so readers do not block writers.
- Handle error 1205 with a retry in the application, because a rare deadlock is acceptable as long as the operation is idempotent.
Maintenance and growth
Index reorganization and rebuilds driven by fragmentation and size, and not by a blind calendar. Statistics updates on tables that change a lot. Partitioning and archiving when a log table grows beyond what maintenance can handle. A documented backup plan with restore testing.
Database as code
Every database object lives in an SSDT project or in versioned migrations. The pipeline applies changes to staging and production. This ends the cycle of loose scripts and differences between environments. In an order system served since 2018, this model gives every change an owner, a review and a history.
Working with a Brazilian team
Our engineers are based in Brazil, in time zones that overlap with the US working day, and we communicate in English.
How we deliver in weeks
- Our own boilerplates. Collection scripts, dashboards and maintenance routines are ready.
- AI agents with senior review. Agents help read plans, propose rewrites and generate tests. A senior engineer decides every change.
- The same team from assessment to deploy. The person who measures is the one who fixes.
- Fixed scope after the assessment. The free assessment lists the most expensive queries and the action plan, with a timeline in weeks.
A typical pattern
A typical pattern: a slow report screen. Query Store shows an implicit conversion between varchar and nvarchar on the filter column, which switches off index use. Once the parameter type is fixed and a composite index with included columns is created, the plan goes from a scan to a seek. The gain shows in logical reads and duration, and does not require changing servers. We measure both before and after the change and keep the result in the report we hand to your team.
What we deliver
A report with the most expensive queries, the plan for each and the proposed fix. Index scripts with tests and rollback. Performance alerts in your monitoring. A short training session so your team can read execution plans and use Query Store on its own.
After the fix, we leave a dashboard that shows the ten most expensive queries of the week. That way a regression appears before it becomes a complaint.
Related
Database work goes hand in hand with .NET development and with the custom software development service. See the case Regina Festas, where a database routine confirms the score on the server. Request the free assessment of your database.