Portable WebAssembly execution plan parser, structural differ, deadlock parser, and exporter.
Compiled directly from Culprit SQL Studio and paired with @culpritsql/plan-viewer.
Quickstart · Supported Engines · API Reference · Node.js & Bundlers · Security & Limits
npm install @culpritsql/plansInitialize the WebAssembly module once, then call the synchronous parser, comparison, deadlock, and export operations:
import {
init,
parsePlan,
diffPlans,
parseDeadlock,
exportPlan,
} from "@culpritsql/plans";
await init();
const before = parsePlan(beforePlanText);
const after = parsePlan(afterPlanText, "postgres");
const diff = diffPlans(before, "Before", after, "After");
const deadlocks = parseDeadlock(deadlockLogText);
const exported = exportPlan(after, "checkout-query", "markdown", {
redact: true,
notes: [],
});Rendering in React? Pass
Plan,PlanDiff, andDeadlockdirectly to@culpritsql/plan-viewer. Both packages share the exact same generatedts-rsmodel types.
| Engine | Execution Plans | Deadlocks |
|---|---|---|
| SQL Server | .sqlplan Showplan XML |
XML deadlock graphs |
| PostgreSQL | EXPLAIN (FORMAT JSON), EXPLAIN (ANALYZE, BUFFERS) text |
Server log deadlock excerpts |
| MySQL & MariaDB | EXPLAIN FORMAT=JSON, EXPLAIN ANALYZE tree text |
SHOW ENGINE INNODB STATUS |
| YugabyteDB | EXPLAIN (FORMAT JSON) + DocDB RPC/storage metrics |
PostgreSQL-compatible logs |
| SQLite | EXPLAIN QUERY PLAN text |
Not applicable |
| Export | Signature | Description |
|---|---|---|
init |
init(input?): Promise<void> |
Instantiates the Wasm module once; subsequent calls reuse the live instance |
parsePlan |
parsePlan(input: string, engine?: Engine): Plan |
Auto-detects format or validates strictly against "mssql" | "postgres" | "mysql" | "yugabyte" | "sqlite" |
diffPlans |
diffPlans(a: Plan, nameA: string, b: Plan, nameB: string, context?: CompareContext): PlanDiff |
Computes structural operator changes, access-path flips, cardinality shifts, and speedup/cost verdicts |
parseDeadlock |
parseDeadlock(input: string): Deadlock[] |
Extracts victim selection, participant sessions, held/waited locks, and original timestamps |
exportPlan |
exportPlan(plan: Plan, title: string, format: ExportFormat, options: ExportOptions): ExportFile |
Exports "markdown", "html", or "native" with optional SQL literal redaction |
ParserError |
class ParserError extends Error |
Structured refusal error (error.error carries { code, message, hint, detail }) instead of Wasm traps |
Setting redact: true scrubs SQL string and numeric literals from statements, filter predicates, and native Showplan XML parameter lists before returning the file:
const file = exportPlan(plan, "Order Lookup", "html", {
redact: true,
notes: [],
});
// file => { name: "order-lookup.html", format: "html", contents: "<!doctype html>..." }Malformed XML/JSON, mismatched engine hints, DTD attempts, or over-depth trees throw ParserError cleanly without corrupting the Wasm instance:
import { parsePlan, ParserError } from "@culpritsql/plans";
try {
const plan = parsePlan(untrustedInput, "postgres");
} catch (err) {
if (err instanceof ParserError) {
console.error(err.error.code, err.error.message, err.error.hint);
}
}In browsers, init() resolves culprit_wasm_bg.wasm relative to import.meta.url via fetch. In Node.js or custom bundler setups, pass module_or_path explicitly:
import { readFile } from "node:fs/promises";
import { init, parsePlan } from "@culpritsql/plans";
const wasmBytes = await readFile(
new URL(
"./node_modules/@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm",
import.meta.url,
),
);
await init({ module_or_path: wasmBytes });
const plan = parsePlan("QUERY PLAN\n`--SCAN orders", "sqlite");With Vite or Next.js static asset URLs:
import wasmUrl from "@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm?url";
import { init } from "@culpritsql/plans";
await init({ module_or_path: wasmUrl });- Zero runtime dependencies: Pure Rust compiled to
wasm32-unknown-unknownwith zero npm dependencies, no database drivers, and no network calls. - Hardened XML & JSON bounds: Rejects XML
<!DOCTYPE>/ entity expansion (XXE) and enforces deterministic depth ceilings (1,024XML elements,56plan operator levels) on a dedicated 32 MiB Wasm linear stack. - HTML-safe exports: HTML plan exports escape every identifier, predicate, and title string.
- CSP compatibility: Serve
.wasmassets withContent-Type: application/wasmand include'wasm-unsafe-eval'inscript-srcunder strict Content Security Policies. - Single source of truth: Synced automatically from
culpritsql/culprit-sql-studio(crates/culprit-plans,crates/culprit-wasm,packages/culprit-wasm).
MIT. Third-party Rust crate notices are distributed in pkg/THIRD-PARTY-LICENSES.txt.