Azure SQL Performance Tuning With AI: Stop Scaling Up the Problem
The reflex when Azure SQL is slow is to scale up the tier. It's usually wrong. Here's how AI helps you tune from execution plans and wait stats before you pay for more capacity.
- #azure
- #ai
- #azure-sql
- #database
- #performance
The dashboard was red, the database was slow, and the easiest button to press was “scale up the service tier.” Somebody pressed it. The dashboard went yellow for a week, the bill went up permanently, and then the slowness came back as traffic grew — because the real problem was a single query doing a table scan where it should have done an index seek, and a bigger tier just bought time before the inefficiency caught up again. Scaling up is the most expensive way to hide a tuning problem, and it’s the first thing most teams reach for. The discipline is to tune from evidence first and right-size last.
Azure SQL gives you everything you need to tune properly — execution plans, wait statistics, the Query Store — but reading them takes experience, and that’s where AI earns its place. It can read a plan for the operator that’s actually hurting, correlate it with wait stats to tell a CPU problem from an IO or locking problem, and propose the narrowest fix. It will not run DDL against your production database; you own every index and every tier change. But it turns a red dashboard into a diagnosis.
Read the plan before you touch an index
The cardinal sin of SQL tuning is adding an index based on a hunch. Indexes aren’t free — each one taxes every write and consumes storage — so you add one only after the execution plan shows you the operator it will fix. Scans where a seek belongs, key lookups, sort spills, and wildly wrong row estimates are what you’re hunting for.
Prompt: “Here is the execution plan for a slow query (plan summary below) and the wait stats from
sys.dm_db_resource_stats. The plan shows a clustered index scan on a 40-million-row table feeding a hash match, and waits are dominated by IO. Diagnose the bottleneck and tell me whether an index, a query rewrite, or a tier change is the right fix — don’t recommend an index until you’ve named the operator it fixes.”
A good answer ties the recommendation to the plan operator and the wait type: an IO-dominated scan on a big table that should be a seek points at a missing index on the filter columns — but only if the predicate is SARGable. If it isn’t, the index won’t help and a rewrite is the real fix. That distinction is what separates evidence-based tuning from cargo-culting indexes, and it’s the through-line in the broader Azure database work.
Add the narrowest index, not the widest
When an index genuinely is the answer, the goal is the narrowest one that converts the costly operator into a seek — the right key column order, with INCLUDE columns to cover the query so it doesn’t need a key lookup. A wide, redundant index speeds one read and slows every write to that table.
-- Narrow, covering: seeks on the filter, includes what the query selects
CREATE INDEX IX_Orders_CustomerId_Status
ON dbo.Orders (CustomerId, Status)
INCLUDE (OrderDate, TotalAmount);
Prompt: “My query filters on CustomerId and Status and selects OrderDate and TotalAmount. Recommend the narrowest covering index — correct key order and INCLUDE columns — to turn the scan into a seek. Then check my existing indexes for duplicates or unused ones I could drop to offset the write cost.”
AI is good at both halves: proposing the tight covering index and spotting existing indexes that overlap or never get used. Dropping an unused index to offset a new one keeps the write path honest. The full tuning prompt that walks this is in the prompts library.
Fix the query when the index can’t
Sometimes no index helps because the query defeats indexing. A function wrapped around an indexed column (WHERE YEAR(OrderDate) = 2026) is non-SARGable and forces a scan; an implicit type conversion does the same; an N+1 pattern hammers the database with a query per row. The fix is the rewrite, not the index.
Prompt: “This query has
WHERE YEAR(OrderDate) = 2026on an indexed OrderDate column and runs slowly. Explain why the index isn’t being used, rewrite it to be SARGable, and show the date-range form that lets the optimizer seek the index.”
The SARGable rewrite — WHERE OrderDate >= '2026-01-01' AND OrderDate < '2027-01-01' — lets the optimizer seek the index it was ignoring. AI spots these patterns quickly; you confirm the rewrite returns identical results before shipping it.
Validate against the Query Store, then right-size
Only after query and index tuning should you ask whether the tier is genuinely too small — and you answer it with the Query Store, which shows you whether your change actually improved the target query and, just as important, whether it regressed any others.
-- Compare a query's performance before and after your change
SELECT qt.query_sql_text, rs.avg_duration, rs.avg_logical_io_reads, rs.count_executions
FROM sys.query_store_query q
JOIN sys.query_store_query_text qt ON q.query_text_id = qt.query_text_id
JOIN sys.query_store_plan p ON q.query_id = p.query_id
JOIN sys.query_store_runtime_stats rs ON p.plan_id = rs.plan_id
ORDER BY rs.avg_duration DESC;
Prompt: “I’ve added an index and rewritten a query. Using Query Store data, how do I confirm the target query improved AND that I didn’t regress other queries that used the old plan? If the workload is still saturating the tier after tuning, what evidence justifies moving to a higher vCore tier rather than tuning more?”
This is where right-sizing becomes defensible: if the database still saturates after the queries are efficient, a bigger tier is buying capacity you actually need, not hiding waste. AI helps you read the Query Store comparison; you apply DDL via a tested staging copy and own the tier decision.
The order of operations
Azure SQL tuning has an order, and scaling up is last. Read the plan and wait stats to name the real bottleneck. Add the narrowest covering index only when the plan shows the operator it fixes, and offset it by dropping dead indexes. Rewrite non-SARGable queries the index can’t save. Validate every change against the Query Store on a staging copy before production, watching for regressions. Right-size the tier only when efficient queries still saturate it. AI reads the plans and proposes the fixes; you run the DDL through staging and own the capacity call. Do that and the red dashboard turns into a tuned database instead of a bigger invoice. There’s more database material in the Azure category, and the SQL tuning prompt is ready to copy from the prompts library.
Download the Free 500-Prompt DevOps AI Toolkit
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.