QueryAutopsy
X-Ray your PostgreSQL, MySQL 8+, and SQLite queries inside your editor, AI assistant, and CI pipeline.
Why Teams Adopt QueryAutopsyA query over 20 local seed rows finishes in 1 ms even with no index — then stalls production APIs when the table hits 500,000 rows. Meanwhile, ORMs silently fire 60 identical queries per HTTP request (N+1 bursts) that look "fast" individually. QueryAutopsy solves both using one shared engine across 4 touchpoints:
Get Started in 5 MinutesStep 1 — Inspect & Simulate Queries Directly in Your Editor
Supported languages & ORMs for inline CodeLens:
Step 2 — Catch N+1 Bursts Automatically (Dev-Only Trace Bridges)Plug a lightweight bridge into your local/dev/test app to stream sanitized query events into Node.js / TypeScript (
|
| Tool | What the AI Can Do | Built-In Guardrail |
|---|---|---|
autopsy_check_sql |
Static SQL safety & DDL/multi-statement check | 100% offline, zero DB connection |
autopsy_explain |
Inspect plan bottlenecks (estimate by default) |
Never returns table rows; scrubs PII literals; ANALYZE requires --allow-analyze + non-prod + ROLLBACK |
autopsy_simulate_index |
Test a CREATE INDEX CONCURRENTLY via HypoPG |
Virtual in-memory only; zero disk writes or locks |
autopsy_list_slow_queries |
Inspect Top slowest pg_stat_statements / performance_schema entries |
Fingerprints only, PII redacted |
autopsy_analyze_traces |
Detect N_PLUS_ONE_BURST & SLOW_TRACE_QUERY in .query-autopsy/traces.jsonl |
Strictly workspace-confined .jsonl/.ndjson; anti-symlink; raw bindings stripped |
Prompts Your Team Can Use Immediately
- "Run
autopsy_analyze_traceson.query-autopsy/traces.jsonl, pinpoint theN_PLUS_ONE_BURSTcallers in our controllers/views, and fix them." - "Check this query's plan with
autopsy_explain, then prove which composite index lowers the cost usingautopsy_simulate_indexbefore I write the migration." - "Use
autopsy_list_slow_queriesto find the top 5 time-consuming queries and prioritize what to fix this sprint."
Step 4 — Block SQL & N+1 Regressions in CI/CD (@query-autopsy/cli)
Run the same rules headless in GitHub Actions, GitLab CI, or pre-merge checks:
# 1. Static SQL safety & anti-pattern check (no database required)
npx @query-autopsy/cli check --dir ./src --fail-on critical
# 2. Plan inspection across source files + SARIF 2.1.0 upload to GitHub Code Scanning
npx @query-autopsy/cli ci --dir ./src --uri "$QUERY_AUTOPSY_URI" --format sarif --fail-on warning
# 3. Fail the build if integration tests trigger N+1 bursts in .query-autopsy/traces.jsonl
npx @query-autopsy/cli trace --file .query-autopsy/traces.jsonl --fail-on warning --explain-top 3
Security & Safety Guarantees
| Surface | Protection |
|---|---|
PostgreSQL EXPLAIN ANALYZE |
Runs inside BEGIN READ ONLY + SET LOCAL statement_timeout + unconditional ROLLBACK in finally; rejects DDL & multi-statement strings before touching PostgreSQL. |
| MySQL 8+ / MariaDB | Executes inside START TRANSACTION + ROLLBACK; supports EXPLAIN ANALYZE (FORMAT=TREE) and EXPLAIN FORMAT=JSON. |
SQLite (.sqlite / .db) |
Runs EXPLAIN QUERY PLAN via pure-JS WASM (sql.js) on an isolated in-memory copy — zero native binaries, zero writes to .db files. |
| Credentials | Stored in VS Code encrypted SecretStorage; never logged or written into workspace files. |
| Dev Trace Bridges | Disabled in production/prod by default; '...' literals replaced with '[REDACTED]'; bindings: [] stripped; .query-autopsy/.gitignore created; symlink paths rejected. |
| MCP AI Firewall | Strict argument allowlisting, read-only annotations, estimate-only default, no arbitrary SQL execution, workspace-realpath confinement on trace files. |
Diagnostics & Understanding Your Autopsy Report
- PostgreSQL (
EXPLAINrules):SEQ_SCAN_LARGE_TABLE, ESR Composite Index (WHEREEquality →ORDER BYSort → Range, includingBitmap Heap Scan), non-SARGable predicates (lower(col), casts), correlatedSubPlans, lossy bitmap heap blocks, external disk spills, buffer misses, row misestimates, and high-loopNested Loops. - MySQL & SQLite: Full Table Scan (
ALL/SCAN),Using filesort,Using temporary,USE TEMP B-TREE, transient automatic indexes, and row misestimates — paired with copyableCREATE INDEXSQL. - Runtime Traces:
N_PLUS_ONE_BURST(per-requestIdnormalized SQL burst) andSLOW_TRACE_QUERY.
| Metric | What It Means |
|---|---|
| Execution Time | Real DB runtime (ms) in EXPLAIN ANALYZE (N/A in Estimate Only mode because the query never runs). |
| Total Cost | Optimizer work score (unitless). Compare Before vs After in HypoPG diff. |
| Buffer Cache Hit | % of PostgreSQL pages read from RAM (Hit) vs disk (Read). Aim for > 95%. |
| I/O & Temp Spill | Disk pages read or temp spill blocks when ORDER BY / Hash Join overflows work_mem. |
Parameters ($1, ?) |
Enter sample values when prompted so EXPLAIN ANALYZE runs safely without editing source SQL. |
Contributing & Local Extension Development
If you want to hack on QueryAutopsy itself or run the local Docker playground:
- Install dependencies and build:
npm install npm run build - Start the seeded PostgreSQL 16 (and optional MySQL 8.4) playground:
# PostgreSQL 16 (10,000 users + 150,000 orders with missing indexes) docker compose -f docker/docker-compose.yml up -d # Optional: also start MySQL 8.4 docker compose -f docker/docker-compose.yml --profile mysql up -d - Launch the Extension Development Host:
- Press
F5(Fn + F5on macOS, or Run and Debug →Run QueryAutopsy Extension). - Open
docker/sample_queries.sqland click▶ Inspect Plan (ANALYZE)above any query.
- Press
npm run check-types # Build workspace packages + strict tsc checks (host + webview)
npm run lint # ESLint across extension, packages, scripts, and tests
npm run test # Vitest suite (125 tests across 30 files, offline)
npm run test:e2e # Live E2E suite against Docker PostgreSQL 16 & MySQL 8.4
npm run build # Bundle extension, webview, and sql-wasm.wasm with esbuild
npm run package:vsix # Build universal VSIX installer
python3 -m unittest discover -s packages/python/tests -v # Python bridge unit tests (7 tests)
Documentation & Engineering Specs
- AGENTS.md — Hexagonal architectural boundaries, safety invariants, and contributor rules
- PRD-001 — Product Requirements
- Master Roadmap (v0.2 → v1.0) — Delivery roadmap across all 4 sprints
- Universal Ecosystem & Security Roadmap (v1.1 → v2.0) — Core extraction, MCP Firewall, JSONL Traces & Bridges
- Hexagonal Architecture — Ports & Adapters blueprint
- ADRs — Architecture Decision Records (
0001–0006) - Technical Specifications — Classifier, Executor, Parser, Diagnostics, and Webview/CodeLens specs
- CONTRIBUTING.md — Branch naming conventions & PR checklist
