Okay friends, this week's question: does it actually matter which AI model you ask? I built one hard SQL Server case with three real problems, gave the exact same case file to seven models, and then did the part none of them can do: I ran every fix they suggested in my lab and measured it.
Six models fixed the deadlock properly. The seventh fixed it too. No errors anymore. And 30 units of stock quietly disappeared. That one result is the reason I'll never deploy an AI fix I haven't run myself. Here's the setup, the test, the expected vs. measured numbers, and the scorecard.
1. The test environment, command by command
| Piece | What I used |
|---|---|
| Database | SQL Server 2022 Developer in Docker, on a 15 GB laptop |
| Cloud models | Claude Opus 5.5, Fable 5.2, Sonnet 5.5, Haiku 5.5 (Claude Code sub-agents); GPT-6.2-sol and GPT-5.6-luna (Codex CLI) |
| Local model | gemma3:4b in Ollama, CPU only (qwen3:4b and deepseek-r1:8b were stopped, see below) |
| Rule for every model | Same case file, answer only from the evidence, in English, full T-SQL fixes |
SQL Server, port on localhost only:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<a strong password>" -p 127.0.0.1:1433:1433 ^
--name sql1 --hostname sql1 -d mcr.microsoft.com/mssql/server:2022-latest
The case database, PharmaRx: a pharmacy app "migrated from 2019" and still on compatibility level 150. 1.2 million prescriptions, one hospital pharmacy owns 900,000 of them, the other 999 pharmacies have about 300 each. That skew is the whole point.
docker cp lab sql1:/tmp/lab
docker exec sql1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "<password>" -C -i /tmp/lab/01-pharmarx.sql
docker exec sql1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "<password>" -C -I -i /tmp/lab/02-evidence-sniffing.sql
docker exec sql1 /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "<password>" -C -I -i /tmp/lab/03-evidence-convert.sql
-- 04-night-batch-a.sql and -b.sql run at the same time in two windows, then 05-deadlock-xml.sql reads the graph
(-I turns on QUOTED_IDENTIFIER, which the XML queries on the system_health session need.)
Asking the models. All of them get case/case.md: schema, procedures, plans, stats, the batch output and the deadlock graph.
# Claude, from your own terminal (I used Claude Code sub-agents pinned to each model)
claude -p --model claude-sonnet-5-5 "$(Get-Content case\case.md -Raw)" > answers\sonnet.md
# OpenAI via Codex CLI: read-only sandbox, no saved session, final answer into a file
Get-Content case\case.md | codex exec -m gpt-6.2-sol -s read-only --ephemeral --skip-git-repo-check -o answers\gpt-6.2-sol.md -
# Local: a 20-line script, one POST to Ollama's /api/chat per model
python tools\run_ollama.py gemma3:4b
One small trap: Codex follows your ~/.codex/AGENTS.md. Mine says "reply in Turkish", so the first GPT answer came back in Turkish. The case file now says "Answer in English".
2. What we tested
| # | Complaint | Real cause in the lab | Evidence in the case file |
|---|---|---|---|
| 1 | Portal report is slow for the hospital | Parameter sniffing: plan compiled for pharmacy 517, run for pharmacy 1 | Estimated 107 rows, actual 98,010; 300,411 logical reads; ~2 s |
| 2 | Patient lookup is slow for one row | nvarchar parameter vs. varchar column (CONVERT_IMPLICIT) | Index scan, 3,582 reads, warning in the plan |
| 3 | Night batch fails | FillRx and CancelRx lock the same rows in opposite order | One deadlock (1205), then 29 × error 3930 |
3. What we expected vs. what we measured
Complaint 1, every proposed fix run against the plan cached for pharmacy 517:
| Fix | Who suggested it | What I expected | Logical reads | CPU |
|---|---|---|---|---|
| Original | 300,411 | 1,063 ms | ||
| OPTIMIZE FOR UNKNOWN | (tested as an option) | Some help | 300,412 | 873 ms |
| Compatibility level 160 (PSP) | (tested as an option) | Parameter Sensitive Plans kick in | 300,402 | 875 ms |
| OPTION (RECOMPILE) | GPT-6.2-sol (only fix) | Big win | 13,887 | 1,107 ms |
| Covering index | Opus, Fable, Sonnet, Haiku, Luna | Big win | 1,084 | 243 ms |
PSP didn't kick in for this query at all, which surprised me. RECOMPILE cut the reads but the CPU didn't move. Only the covering index really fixed the report.
Complaint 2: changing the parameter to varchar(20) took the lookup from 3,582 reads to 6. Sonnet kept nvarchar and converted into a varchar local variable, which also removes the conversion on the column.
Complaint 3, the one with the trap. GPT-6.2-sol said error 1205 had already rolled the transaction back. I checked right after the deadlock: XACT_STATE() = -1 and @@TRANCOUNT = 1. The transaction was still open and doomed, which is exactly why the next 29 calls failed with 3930. Then the fixes, 30 fills + 30 cancels at the same time:
| Fix | Errors | Stock (MET850, pharmacy 3) |
|---|---|---|
| Original procedures | 1 deadlock + 29 × 3930 | |
| Same lock order + XACT_ABORT + ROLLBACK in CATCH (Claude / GPT) | 0 | 500 → 500 |
| gemma3:4b: remove the Inventory update from CancelRx | 0 | 500 → 470 |
Zero errors, and 30 units of stock gone without a trace. That's the most dangerous answer of the whole test.
The scorecard
| Model | Time | 1 Sniffing | 2 CONVERT_IMPLICIT | 3 Deadlock + 3930 | Mistakes |
|---|---|---|---|---|---|
| Claude Opus 5.5 | ~106 s | ✓ covering index + sp_recompile | ✓ varchar(20) | ✓ same order, doomed tx explained | none found |
| Claude Fable 5.2 | ~107 s | ✓ covering index | ✓ varchar(20) | ✓ same order, doomed tx explained | none; noted ONLINE = ON needs Enterprise/Developer |
| Claude Sonnet 5.5 | ~101 s | ✓ covering index, RECOMPILE as stopgap | ✓ varchar local variable | ~ same order, unsure why tx stayed open | hedged on 3930 |
| Claude Haiku 5.5 | ~120 s | ✓ covering index + RECOMPILE | ✓ varchar(20) | ~ same order + retry | said 3930 hits at COMMIT (it's the first write) |
| GPT-6.2-sol | 103 s | ~ OPTION (RECOMPILE) only | ✓ varchar(20) | ~ same order | "1205 already rolled back" (lab: XACT_STATE = -1) |
| GPT-5.6-luna | 224 s | ✓ covering index + RECOMPILE | ✓ varchar(20) | ✓ same order (Prescriptions first), doomed tx | redundant INCLUDE column (harmless) |
| gemma3:4b (local) | 562 s | ✗ "full table scan", filtered index on a fixed date | ✗ LOWER() copy column | ✗ deletes the stock update | missed sniffing, silent data loss |
Claude times are sub-agent wall-clock times including reading the case file, so treat them as approximate.
4. Where it went wrong, and how it could be better
What really changes between models isn't who finds the problem. Every cloud model found the sniffing (compiled value 517, runtime value 1). The difference is how deep the fix goes: RECOMPILE and a covering index are both "correct", but only one fixed the report. Then precision on engine details, like what a deadlock does to your transaction. Then how much they hedge, and how fast they answer.
The local model is private, which matters for this kind of data, but on a laptop CPU a 4B model isn't ready for a case like this. Wrong on all three, and one fix that loses data.
My own mistakes: I tried to run qwen3:4b and deepseek-r1:8b too. While qwen3 was thinking, the laptop dropped to 0.2 GB of free memory and Docker stopped answering, so I stopped both. Next time: one local model at a time, Docker containers paused. And the Codex AGENTS.md language trap cost me a rerun. If you don't have a powerfull Windows, then a Mac with GPU would be preferable for 'local LLMs'. I will re-apply those tests on Mac too later.
How I'd use this at work: give every model the same evidence, not a vague question. Never deploy a fix you haven't run. Measure reads, CPU and the data itself, not only the error count (gemma's fix had zero errors). And production data stays inside: send a case file with lab data, never real patient rows.
5. What I'd take from this, and what would be worth testing later
My conclusion: for a case like this the big cloud models are close to each other, and the real difference is how deep the fix goes and how exact they are on engine details. The small local model isn't there yet on a laptop CPU. These would be worth testing later, because they'd answer the questions this test left open:
- A bigger local model on a machine with a GPU, to see if a private model can get close to the cloud ones.
- Asking each model a second time with "check your fix against the evidence", to see who changes their answer.
- A harder case where the sniffing fix needs Query Store hints instead of an index.
Which model do you use for SQL Server work, and has it ever given you a fix that "worked" but broke the data? I'd like to hear it.
Comments
Post a Comment