AGENTIC POSTGRESQL OPTIMIZER & DETERMINISTIC VERIFIER
SQL DOCTOR // LAB
GITHUB REPO ->
01 // CLOSED-LOOP VERIFICATION WALKTHROUGH Step 1/5: LLM proposes rewrite
01. PROPOSE
LLM suggests rewrite + index
02. ADVERSARY
Tests 246 enum + fuzz DBs
03. MINIMIZE
Delta-debug shrinks to 1 row
04. FEEDBACK
Counterexample sent to LLM
05. RECEIPT
Verified + receipt.sql emitted
02 // INTERACTIVE TRAP & PASS EXPLORER
ORIGINAL SQL

        
CANDIDATE SQL

        
*** PROOF RECEIPT *** REJECTED
03 // CHECKED-IN BENCHMARK & ABLATION RESULTS (`eval/results/`) 129/129 TESTS PASSING
Evaluator / AblationSuiteCasesFalse AcceptsAccuracy
SQL Doctor (Full)Trap Suite v2500100.0%
LLM-as-judge (Gemini)Trap Suite v250394.0%
Ablation: No EnumerationTrap Suite v250394.0%
Ablation: No FuzzingTrap Suite v2501374.0%
SQL Doctor (Full)Good Suite v2300 (0 False Rejects)100.0%
04 // SYSTEM ARCHITECTURE (PROPOSE VS. DETERMINISTIC JUDGE)
INPUT SPECIMEN Slow SQL / DDL pg_stat_statements LLM AGENT Rewrite + Indexes SHA-256 Disk Cache DETERMINISTIC JUDGE 1. Small-Scope Enum 2. Seeded Constraint Fuzz 3. sqlglot AST Mutants 4. Bag EXCEPT ALL Check PG 17 + HYPOPG shared_buffers Virtual Indexes ARTIFACTS receipt.sql report.html DELTA-MINIMIZED 1-ROW COUNTEREXAMPLE FEEDBACK
05 // WHAT IS BUILT (CORE MODULES & CAPABILITIES)
sqld verify
Adversarial Equivalence Engine

Synthesizes boundary tuples ($c \pm 1$, NULLs, empty tables) + 200 constraint-aware fuzz DBs, checks multiset equality, and minimizes failures via delta-debugging.

sqld diagnose
Closed-Loop LLM Optimizer

Proposes SQL rewrites and covering indexes with SHA-256 disk prompt caching ($0.0000 replay) and counterexample-guided self-correction.

sqld bench & replay
Buffer Metrics & Receipts

Measures shared_buffers (hit + read) across scales and emits standalone receipt.sql files replayable in plain psql.

sqld mcp
Model Context Protocol Server

Exposes verify_rewrite, diagnose_query, and replay_receipt over stdio/SSE so Cursor, Claude, and Antigravity verify SQL before shipping.

sqld workload
Workload Mode + HypoPG

Ranks pg_stat_statements exports under a global USD budget, consolidates redundant indexes, and verifies plan costs live in PG17 + HypoPG.

sqld ui & CI
Local Lab UI & PR Verifier

FastAPI workbench for live demos plus a GitHub Action PR verifier and CI matrix across PostgreSQL 16, 17, and 18.

06 // PRIMARY USE CASES
  • Safe AI-Assisted SQL Tuning: Let LLMs rewrite slow legacy joins without risking silent NULL, LEFT JOIN, or duplicate-row corruption.
  • Automated PR Guardrail: Block broken SQL refactors in GitHub Actions with an exact 1-row counterexample proof.
  • Workload Index Consolidation: Test covering indexes across your top-$N$ pg_stat_statements queries using HypoPG without building real indexes on disk.
LOCAL QUICKSTART (CONDA + DOCKER PG17)
git clone https://github.com/Sanidhyavijay24/sqlD.git
cd sqlD
pip install -r requirements.txt && pip install -e .
sqld up   # Optional: boots PG17 + HypoPG
sqld ui   # Launches live local lab UI
Apache-2.0 License · Built by Sanidhya Vijay