Skip to content
Skills Library
Programming · Analysis

sql-server-tuning

/sql-server-tuning

Diagnose and fix slow SQL Server queries: read the actual execution plan, find scans, key lookups, spills and bad estimates, use Query Store to find regressions and plan changes, handle parameter sniffing, design covering indexes without over-indexing, and check statistics; measure logical reads before and after. Use when a query, report, batch or endpoint backed by SQL Server is slow, when CPU or blocking spikes, or when reviewing indexes.

Licence
MIT
Last repository change
10.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 10.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Diagnose and fix slow SQL Server queries: read the actual execution plan, find scans, key lookups, spills and bad estimates, use Query Store to find regressions and plan changes, handle parameter sniffing, design covering indexes without over-indexing, and check statistics; measure logical reads before and after. Use when a query, report, batch or endpoint backed by SQL Server is slow, when CPU or blocking spikes, or when reviewing indexes.

Original author description

Diagnose and fix slow SQL Server queries: read the actual execution plan, find scans, key lookups, spills and bad estimates, use Query Store to find regressions and plan changes, handle parameter sniffing, design covering indexes without over-indexing, and check statistics; measure logical reads before and after. Use when a query, report, batch or endpoint backed by SQL Server is slow, when CPU or blocking spikes, or when reviewing indexes.

How it works

  1. Measure
  2. Read the plan, right to left
  3. Rules
Original SKILL.md headings · 25 lines, 243 words
SKILL.md preview
---
name: sql-server-tuning
description: "Diagnose and fix slow SQL Server queries: read the actual execution plan, find scans, key lookups, spills and bad estimates, use Query Store to find regressions and plan changes, handle parameter sniffing, design covering indexes without over-indexing, and check statistics; measure logical reads before and after. Use when a query, report, batch or endpoint backed by SQL Server is slow, when CPU or blocking spikes, or when reviewing indexes."
---

# SQL Server tuning

## Measure
```sql
SET STATISTICS IO, TIME ON;   -- logical reads and CPU per statement
-- run the query, keep the ACTUAL execution plan
```
Query Store: "Top resource consuming queries" and "Regressed queries" show what got worse and when (a plan change after a deployment or a statistics update).

## Read the plan, right to left
| You see | Usually means | Try |
|---|---|---|
| Index scan on a big table with a selective `WHERE` | no usable index, or non-sargable predicate | index on the filter columns; remove functions on columns (`WHERE YEAR(d)=2026` -> range) |
| Key lookup executed thousands of times | index lacks columns | covering index with `INCLUDE` |
| Estimated rows << actual rows | stale statistics, parameter sniffing, table variables | update statistics; `OPTION (RECOMPILE)` or `OPTIMIZE FOR` on that statement; temp tables |
| Sort/hash with warning (spill) | memory grant too small, bad estimate | fix estimates first |
| Implicit conversion warning | type mismatch (`nvarchar` parameter vs `varchar` column) | align parameter types (EF: column types, Dapper: `DbString`) |

## Rules
- One change at a time; compare logical reads and duration on production-like data volume.
- Every new index has a cost on writes: check existing indexes for overlap (`sys.dm_db_index_usage_stats`).
- Blocking: look at the head blocker and the transaction length, not only the waiting query.
- Never tune on an empty dev database.

Versions

The database has no other skills named sql-server-tuning.

Database snapshot: 13.11.2026 · package version 041444d4c985 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100query-optimization
    This skill should be used when the user asks to optimize slow T-SQL queries, fix SQL Server performance regressions, improve SARGability, rewrite joins, prove whether joins can be removed, compare temp-table data types, select rewrite templates, diagnose parameter sniffing,…
  • 100query-optimization
    Diagnose and optimize existing slow SQL queries using execution plans, indexing strategies, query rewriting, and ORM tuning. Use when the user provides a query, performance symptom, or EXPLAIN plan; use sql-query-generation when creating a new query from requirements.
  • 100flux-query
    Optimize slow database queries — analyze execution plans, add indexes, rewrite queries. Use when asked about "slow query", "optimize SQL", "query performance", or "explain this query".
  • 100sql-style-and-tuning
    Write SQL that is easy to read and review, and make slow queries fast by reading the plan first. Use it whenever you write or review a query, view or model, when a query or page is slow, when the same query runs many times in a row (N+1), or before adding an index.
  • 100sql-optimizer
    Analyzes SQL queries for missing indexes, N+1 patterns, suboptimal joins, and full table scans. Interprets EXPLAIN, detects anti-patterns, rewrites queries. Triggers on: "optimize this query", "slow query", "add indexes", "explain plan", "N+1 query", "why is this query slow".
  • 100query-optimizer
    Optimize SQL queries for performance with indexing strategies, query rewriting, and execution plan analysis. Use when queries are slow, optimizing database performance, or analyzing query execution.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.