Sr. Content Developer at Microsoft, working remotely in PA, TechBash conference organizer, former Microsoft MVP, Husband, Dad and Geek.
160463 stories
·
33 followers

Finding the Root Cause of Slow Queries

1 Share

Finding the root cause of slow queries starts by separating work from waits, then testing theories against plans and history.

Finding the root cause of slow queries begins with an illustrative Tuesday morning. At 10:12, an order lookup that normally returned in 180 milliseconds took 14.8 seconds. Forty-three sessions piled up within five minutes, and the application team wanted a new index before lunch.

CPU stayed modest, logical reads remained familiar, and the cached plan matched yesterday’s fast plan. The request spent almost its whole life on an LCK_M_S wait. A nightly inventory process had left an update transaction open. The visible query was the victim, not the offender.

The team followed blocking_session_id until the chain ended at a sleeping session. Its last batch showed the inventory update, and transaction data confirmed the uncommitted work. Once that owner committed safely, latency fell below 200 milliseconds. Nobody edited the victim’s code, indexes, or statistics.

Slow Is a Symptom

Elapsed time tells you that users waited, not what consumed the time. A request can execute expensive work, wait for a resource, or alternate between both. Tuning begins only after you know which state dominates.

This distinction prevents attractive mistakes. Adding an index cannot release a lock held by another transaction. Updating statistics cannot repair storage latency. More CPU cannot help a request waiting for memory, a client, or a network response.

Make the First Split

A practical troubleshooting method separates running from waiting. Compare elapsed time with worker time for the request. Similar values usually indicate active processing, while a large gap means substantial waiting.

That first split does not solve the incident. It eliminates classes of wrong fixes before they reach the production server.

Parallel plans require care because total worker time can exceed wall-clock duration. The principle still holds: determine whether schedulers are working or a resource is unavailable. Then inspect the current wait type, wait duration, and wait resource.

Finding the Root Cause of Slow Queries root-cause-slow-queries-scaled
Observed signal Frequent misreading Better next check
Long duration, modest CPU The query needs an index Wait type, wait resource, blocking chain
High CPU, few waits The server is undersized Plan shape, estimates, rows processed
Spikes at fixed times Somebody changed the code Scheduled jobs, file latency, memory grants

Lock waits require the complete blocking chain, not merely the blocked session. The head blocker often looks harmless because it sleeps between crimes.

Identify the Exact Statement

Start with the statement that users experience, not a similar batch copied from documentation. Capture its database, application, login, parameters, query hash, plan hash, and execution context. Those details separate one expensive pattern from thousands of harmless executions.

Query text alone can mislead. Different literals may trigger different cardinality estimates and plans. Session settings can also change plan selection. A normalized query signature groups related statements, while individual executions expose parameter-sensitive behavior.

Read the Actual Plan as Evidence

An estimated plan describes what the optimizer expected. An actual execution plan adds row counts and warnings. Compare estimated rows with actual rows at each operator. Large differences can expose stale statistics, skewed data, or parameter sensitivity.

Look for spills, excessive lookup repetitions, oversized memory grants, and unexpected scans. A scan is not automatically wrong, and a seek is not automatically efficient. Context decides whether an operator is expensive. The percentage printed on a plan is an estimate, not measured elapsed time.

Do not rerun a costly production statement to obtain an actual plan. Use a captured plan when possible, or reproduce the workload safely elsewhere. Evidence collection should not create a second incident.

Correlate Current Behavior with History

A snapshot explains one moment. History shows whether that moment is normal. Query Store preserves plans and aggregated duration, CPU, reads, and execution statistics under capture and retention. On SQL Server 2017 or later, enabled wait-statistics capture adds query-level waits.

The comparison window matters. Peak checkout traffic should not be compared with an overnight maintenance window. Match business cycles, data volume, execution frequency, and parameter mix. A lower average duration means little when easy executions dominate the sample.

SQL DM from IDERA can group queries by signature and collect performance details when Query Monitor is enabled. That history can connect a user complaint with the statement and resource pattern present then. Recorded evidence matters most after a transient problem disappears.

Follow the Server Context

The plan may be healthy while the environment is not. Check concurrent workload, blocking, memory grants, file latency, tempdb pressure, and recent configuration changes. A query can become slow because another process consumed the resource it normally receives.

Correlate timelines before assigning blame. A storage latency spike at 10:11 may explain several unrelated slow statements at 10:12. Shared pressure leaves evidence across many sessions.

When Focused Query Tuning Is Enough

Sometimes the query itself is inefficient, and broader investigation delays an obvious repair. Consistently high CPU, excessive reads, stable waits, and repeatable plan behavior can justify focused tuning. That case deserves prompt action.

Even then, test the proposed change against representative parameters and neighboring statements. An index can accelerate one lookup while increasing write cost elsewhere. A hint can stabilize today’s plan while hiding tomorrow’s data change. Fast local results do not guarantee healthy workload results.

Turn Evidence into a Decision

SQL DM from IDERA brings live metrics, query details, alerts, and historical context into one investigation path. The value is keeping enough context to test competing explanations quickly and safely.

Good diagnosis ends with a claim somebody could prove wrong. Name the resource, query, plan change, or transaction responsible. Record the supporting metrics and the expected result of the fix. Then measure again under comparable conditions.

The next time a query looks slow, pause before changing it. Ask whether it worked, waited, or changed since yesterday. The answer usually costs ten minutes and saves a wasted index.

A slow query is a symptom, while the root cause is the work, wait, or change behind it.

Reference: Pinal Dave (https://blog.sqlauthority.com/), X

First appeared on Finding the Root Cause of Slow Queries

Read the whole story
alvinashcraft
8 minutes ago
reply
Pennsylvania, USA
Share this story
Delete

Daily Reading List – September 1, 2026 (#858)

1 Share

I learned a lot today. How about you? My education usually comes from a mix of reading, talking to people, and trying things myself. It’s a good day when all three of those happen.

[article] The Job Doesn’t Change. The Agent Does. Consumers still want the right product at the right price with the least friction. Who is the consumer? That’s changing.

[blog] Try Google Pics: Easy image creation and editing in Google Workspace. I just tried this on an image in my Google Drive. It’s so simple to make targeted improvements to existing visuals.

[article] OpenClaw 2.0 is here, ushering in the era of ‘multiplayer’ AI coding: What it means for enterprises. Big release, and we’ve made it easy to use with Gemini, or even host in Cloud Run instances. More here.

[blog] Teamwork: When AI Becomes a Research Partner. If you have a problem worthy of the token spend, the “teamwork” feature is worth it. Check out what real problems it solved.

[blog] Antigravity Teamwork for long-running tasks. Prashanth does a great job explaining /teamwork in depth and how to use it.

[blog] Agency and Agents. Instead of dark factories where operate on their own (see /teamwork above), do we need “twilight factories” where humans are brought in at the right moments?

[article] How to turn your AI into a world-class designer. This should make existing designers better, while giving a big assist to those without access to designers.

[blog] Coding a database proxy for fun. Do you know how to intercept and process TCP packets in code? Alex shows an example.

[blog] TimesFM-3: A zero-shot foundation model for multivariate forecasting. Powerful, open time series foundation model. It’s high performing, and now capable of multivariate forecasting.

[article] Your agent context needs a development lifecycle. We need to see more exploration in areas like this. What about short term context (skills or rules)? Is there different rigor for shared versus local context? Is it the same cycle for all types of context?

[blog] How to Slash Token Costs with Context Caching in Agent Harnesses. Get good at concepts like this. Some models/platforms make it easier to turn on features like context caching.

[article] Anthropic’s new Fable release is cheaper, less restrictive. Looks great! Still seems to be expensive, but excellent results.

[blog] Introducing agentic video understanding with Gemini. This cuts token consumption by a massive amount, which in turn reduces costs a ton.

[article] Meet the Google Exec Trying to Convince a Skeptical Gaming Industry to Love AI. I get the wariness. It’s also clear that AI can help in how we build games, and how players get better in-game experiences.

Want to get this update sent to you every day? Subscribe to my RSS feed or subscribe via email below:



Read the whole story
alvinashcraft
9 minutes ago
reply
Pennsylvania, USA
Share this story
Delete

BenchMIRT: What are LLM benchmarks actually measuring?

1 Share
Read the whole story
alvinashcraft
9 minutes ago
reply
Pennsylvania, USA
Share this story
Delete

Claude Fable 5.1 made me a really nice animated pelican

1 Share

Today is Claude Fable (and Mythos) 5.1 day. Anthropic say that Fable 5.1 "sets a new standard for coding, knowledge work, and long-running problem-solving tasks". Their announcement spends a notable amount of time on scientific research, boasting of a 52.6% score on the brand new Terminal-Bench-Science 0.1 benchmark (first announced on August 27th), up from 24.7% for Fable 5, 29.0% for Opus 5 and 22.4% for GPT-5.6 Sol. Other benchmarks show slightly improved scores, but none as impressive as the Science one.

But how well can it pelican?

Back in July I wrote about how I was losing faith in the pelican benchmark - its connection to how good the models were at other tasks didn't seem to hold as strongly as it did back in 2025. The most interesting insights I get from it now are comparisons within model families, and particularly comparisons for the same prompt at different reasoning effort levels.

Fable 5.1 has five reasoning levels: low, medium, high, xhigh, max - and no option to turn off reasoning entirely.

I fixed an issue in llm-anthropic which caused reasoning traces not to be correctly recorded, then ran some prompts.

Here's the full set of pelicans for all of the reasoning levels, each with the full reasoning transcript. I'll replicate them here:

Low and medium, both without reasoning?

Next, a bit of a mystery. This is what I got for effort low:

Minimalist flat illustration of a white pelican with an orange beak riding a black bicycle to the left, its orange legs pedaling and wings gripping the handlebars, with motion lines behind on a light blue background.

The transcript doesn't show any summarized reasoning tokens, and the output token count is 1,998. With Claude that output token count includes reasoning tokens. It took 23.8 seconds and cost 10.017 cents.

I bumped that up to medium and got this:

Minimalist flat-style illustration of a white pelican with an orange beak riding a black bicycle to the right, with motion lines behind it, on a light blue background.

Weirdly, that one also shows no reasoning text and used 1,977 output tokens - 21 tokens less than low. It took 23 seconds and cost 9.912 cents.

So for this particular prompt ("Generate an SVG of a pelican riding a bicycle") Fable 5.1 appeared to skip reasoning entirely at both low and medium settings.

High

Here's high - 29.6 seconds, 2,612 output tokens, 13.087 cents:

Minimalist flat illustration of a white pelican with an orange beak riding a black bicycle, its orange legs pedaling, with motion lines behind it on a light blue background.

This one did do a bit of reasoning, summary here:

I'm planning the SVG layout for a pelican riding a bicycle, with a sky and ground background, a bicycle with two spoked wheels, frame, seat and handlebars, and a white-bodied pelican with a long neck and orange beak positioned on top.

Really not much difference from low and medium, though.

Extra High

At xhigh things got radically different. 36,767 output tokens, 7 minutes 51 seconds, $1.83!

Minimalist flat illustration of a white pelican with an orange beak riding a black bicycle to the left, its orange legs pedaling, with motion lines behind it on a light blue background.

The reasoning trace is pretty lengthy, and includes details like this:

Adding the eye, wings stretching down to the handlebar grip, orange legs reaching to the pedals, and a small tail feather, while keeping the pelican intentionally oversized compared to the bike for comic effect. [...]

I'll accept the slight thickness as charming rather than overengineering it.

Max

Setting effort to max gave me the best pelican I've seen from any of Anthropic's models. 65,927 output tokens, 13 minutes and 54 seconds, $3.30:

Minimalist flat illustration of a white pelican with an orange beak riding a black bicycle, its orange legs pedaling, with motion lines behind to indicate speed, on a light blue background.

There's a lot to like about this. The background is tasteful, the legs are clearly on either side of the frame, the feet are on the pedals, the wing is on the handlebars, the pelican has a cute blue hat and there's a basket with a fish.

It's still not showing nearly the same level of flair as Gemini 3.7 Flash, but I didn't ask for flair - I asked for an SVG, and that's what I got.

Some highlights from that reasoning trace:

Adding pedal shapes near both feet, with the far foot on the second leg partially visible behind the frame. I'm considering whether to add a small scarf or cap for extra character, but leaning toward keeping it simple to avoid clutter.

Now I'm debating a bicycle helmet on the head versus the pelican's signature crest—the beak and pouch already read clearly as "pelican," so a helmet could reinforce the bicycle theme without losing identity, though it might compete with the crest for visual space.

I realize the beak at (484,84) would overlap with the dome helmet, so I need to shrink the helmet so it only covers the top of the head, adjusting its arc endpoints to sit higher and narrower so the beak can attach cleanly at the front without collision. [...]

I'm adding a darker tip region to represent the primary feathers, then reconsidering the trailing edge to include scalloped feather curves instead of one smooth line for a more natural look. [...]

Now I'm checking the vent line placements on the helmet, making sure they sit far enough inside the helmet's edge given the stroke width and rounded caps, and confirming each vent stays within the helmet's circular boundary. [...]

I decide skipping a handlebar bell and tire highlights since they're unnecessary additions. Now I'm reconsidering the front fork's curve — the current control point pulls the shape backward when it should bow forward for a proper rake, so I need to shift the control point rightward to fix the fork's lean.

OK, let's animate it

On Hacker News, swalsh commented on that Max pelican:

Now that it's a solved benchmark, can we get the animated version?

I didn't want to spend another $3 so I took the Max pelican and piped it into the default thinking level of High:

llm logs -cx | llm -m claude-fable-5.1 -s 'animate this'

6,121 input, 26,201 output = $1.37. The result looked like this, exported here as video since some people have trouble viewing animated SVGs:

The wheels are rotating in the wrong direction, but other than that it's a very nice animation derived from that original SVG.

Tags: ai, generative-ai, llms, anthropic, claude, pelican-riding-a-bicycle, llm-reasoning, llm-release

Read the whole story
alvinashcraft
9 minutes ago
reply
Pennsylvania, USA
Share this story
Delete

Open AI’s Astra model is on the way—and very good at breaking into computer systems

1 Share
OpenAI previewed the precautions it is taking as it prepares to release Astra, its newest, cyber-critical LLM.
Read the whole story
alvinashcraft
6 hours ago
reply
Pennsylvania, USA
Share this story
Delete

Coffee and Open Source Conversation - Sam Basu

1 Share


Read the whole story
alvinashcraft
6 hours ago
reply
Pennsylvania, USA
Share this story
Delete
Next Page of Stories