← Files SQL CopilotARCHIVED FILE

references/performance-diagnosis.md

1.25 KB · Nov 27, 2026 · 19:07 UTC

↓ Download file

See the change to this file →

# Evidence-first SQL performance

First establish correctness and workload context. Slow for one user may result from resource queueing or a different parameter distribution. Record plan/profile, scanned and returned rows, bytes, sort/spill, shuffle, estimated vs actual cardinality, concurrency, cold/warm cache and total cost where available.

## Prioritize low-risk reductions of work
1. Project only required columns and keep filters prune-friendly where semantics allow.
2. Diagnose high-cardinality joins and pre-aggregate when result grain permits.
3. Inspect data movement, skew, inaccurate statistics and expensive sort/window operators.
4. Consider indexes, distributions, clustering/partitioning, materialized summaries, caching or sizing based on measured benefits and overhead.

A CTE is for clarity unless documented optimizer/materialization semantics justify a performance claim. A LIMIT can trim output while still scanning large volumes; BigQuery explicitly warns `LIMIT` on `SELECT *` doesn't reduce bytes scanned.

## Verification
Compare identical parameters and output measures before/after. Use several runs under comparable conditions, respecting budget and production impact. Cite actual plan differences; no promises about percent speedups without data.

SHA-256: 82b7e1d208d7af83a33b45c9811d8bd2d1b603b71d120521753a06b943339572