~/talk

When to stop tuning a query

Talkat SQLBits 2024 · 2024-03-19..03-23· [databases]
links:none on file
slides:none on file

A single T‑SQL query against 100M/335M rows is tuned stepwise: forcing a nested loop join cuts elapsed time from ~11s to ~2s but exposes a 10 GB memory grant that cripples concurrency when simulated with 200 sessions using SQLQueryStress. Trickery with a table variable (and later table variable defer compilation or option hints) changes cardinality estimates to avoid bad joins. Increasing statistics sample rates to ~20–50% fixes the root cause and restores stable plans.

AI-written summary · about

  1. 0:00Query tuning session intro
  2. 1:09Database and query setup
  3. 3:14Starting query tuning
  4. 4:20Why tune SQL Server queries
  5. 6:07Join operators and workload
  6. 7:33Initial query metrics
  7. 8:22Nested loop join hint results
  8. 9:28When to stop tuning
  9. 10:31Memory grant and concurrency
  10. 11:33SQLQueryStress parallel tests
  11. 13:40Memory pressure decision
  12. 15:27Limit memory grant
  13. 16:37Eliminating unnecessary parallelism
  14. 17:41Final optimized query
  15. 18:45Override optimizer decisions
  16. 19:50Trick optimizer with table vars
  17. 25:16Table var deferred compilation
  18. 26:19Compatibility level impact
  19. 27:45Statistics estimation problems
  20. 34:15Stats for orders table
  21. 36:26Large table sample rate issues
  22. 39:15Fix stats with higher sample
  23. 41:00Eliminate root cause benefits
  24. 42:26Auto stats updates drawbacks
  25. 43:27PERSIST_SAMPLE_PERCENT
  26. 44:35Large tables special care
  27. 45:59Maintain statistics yourself
  28. 47:46Query tuning strategies
  29. 49:12Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.