Skip to content

About

Interactive React execution plan diagrams, structural diffs, and deadlock cycle graphs for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

@culpritsql/plan-viewer

npm React 18 | 19 TypeScript License: MIT

Interactive execution plan diagrams, structural diffs, and deadlock cycle graphs for React.
Extracted directly from Culprit SQL Studio and paired with @culpritsql/plans.

Quickstart · PlanViewer · PlanDiffViewer · DeadlockViewer · Canvas & Primitives · Theming


Quickstart

npm install @culpritsql/plan-viewer @culpritsql/plans
import { init, parsePlan } from "@culpritsql/plans";
import { PlanViewer } from "@culpritsql/plan-viewer";
import "@culpritsql/plan-viewer/styles.css";

await init();
const plan = parsePlan(explainJsonOrXml);

export function QueryExplainPanel() {
  return <PlanViewer plan={plan} title="Checkout Query" />;
}

PlanViewer

Drop-in single-plan explorer with bottleneck insights, measured runtime strip, interactive layout switcher, and operator inspector.

PlanViewer preview
  • Ranked insights: Highlights high-impact bottlenecks with plain-language explanations and copyable SQL fixes.
  • Five synchronized views: Switch between Diagram, Tree, Operations, Tables (per-table/index rollup), and Raw (EXPLAIN output).
  • Interactive canvas: Drag to pan, Ctrl/Cmd + scroll to zoom around cursor, corner Minimap, Metric lens (Time · Cost · Rows · Reads), and live step search.
  • Buffers, I/O & parallelism: Dedicated cache-hit vs disk-read bar (8 KB pages/MB), temp spills, WAL volume, and per-worker row skew bars.
<PlanViewer
  plan={plan}
  title="Recent Paid Orders"
  defaultLook="diagram" // "diagram" | "tree" | "operations"
  theme="system"        // "light" | "dark" | "system"
/>

PlanDiffViewer

Side-by-side execution plan comparison for before/after index changes, query rewrites, and regressions.

PlanDiffViewer preview
  • Verdict banner: Computes measured speedup or estimated cost ratio (167x faster, 3.2x costlier).
  • Structural diff: Marks access-path flips, operator swaps, and added or removed subtrees directly on cards.
  • Why it changed: Surfaces index additions, cardinality shifts, parameter differences, and estimator changes.
  • Synchronized canvas: Mirrors zoom and viewport scrolling across Plan A and Plan B.
import { diffPlans } from "@culpritsql/plans";
import { PlanDiffViewer } from "@culpritsql/plan-viewer";

const diff = diffPlans(beforePlan, "Before", afterPlan, "After");

<PlanDiffViewer a={beforePlan} b={afterPlan} diff={diff} nameA="Before" nameB="After" />;

DeadlockViewer

Visual lock-cycle graph and root-cause breakdown for SQL Server XML deadlocks, PostgreSQL logs, and InnoDB status dumps.

DeadlockViewer preview
  • Cycle SVG graph: Interactive holds and wants lock curves with hover focus and victim rollback badge.
  • Pattern badges: Detects opposite lock ordering, key-lookup cycles, lock conversions, and escalations.
  • Actionable fixes: Ordered remediation steps with syntax-highlighted SQL.
  • Session breakdown: Displays application, login, isolation level, lock wait mode, and statement per participant.
import { parseDeadlock } from "@culpritsql/plans";
import { DeadlockViewer } from "@culpritsql/plan-viewer";

const [deadlock] = parseDeadlock(serverDeadlockText);

<DeadlockViewer deadlock={deadlock} />;

Theming & CSS Isolation

@culpritsql/plan-viewer/styles.css scopes every token, reset, and selector inside .culprit-pv. Importing it never alters your application's html, body, scrollbars, or global <button> styles.

Mode Usage
System (default) Follows prefers-color-scheme: dark automatically
Component prop <PlanViewer plan={plan} theme="dark" /> or theme="light"
Ancestor attribute Set data-theme="dark" or data-theme="light" on <html>, <body>, or any wrapper

Canvas-Only & Granular Primitives

Want only the interactive flow canvas (or lock-cycle SVG) inside your own IDE, query runner, or split-pane layout, with zero recommendations, prose banners, or built-in drawers? Import <PlanCanvas /> and wire onSelect to your own UI (or <NodeDetails />):

import { useState } from "react";
import { PlanCanvas, NodeDetails } from "@culpritsql/plan-viewer";
import "@culpritsql/plan-viewer/styles.css";

export function CustomSplitExplain({ plan }) {
  const [selectedId, setSelectedId] = useState<number | null>(plan.root.id);

  return (
    <PlanCanvas
      plan={plan}
      lens="time"          // "time" | "cost" | "rows" | "reads"
      showInsights={false} // pure operator flow, no recommendation badges
      height="100%"        // fills your container; drag to pan, Ctrl/Cmd + scroll to zoom
      selectedId={selectedId}
      onSelect={setSelectedId}
      theme="dark"
    />
  );
}

Every building block is exported individually with full TypeScript definitions:

Export Purpose
PlanCanvas Pure interactive DAG flow canvas (pan, cursor zoom, minimap) with zero prose, headers, or drawers
PlanTree / PlanView Collapsible operator tree (showHeader, showActualSummary, showProps, showInsights all optional)
PlanOperations Searchable, keyboard-navigable (j/k), multi-column sortable operator table
PlanObjects Per-table and per-index rollup of time, rows, buffer reads, and cache hit ratio
PlanRaw Native XML, JSON, or text plan viewer with one-click copy
NodeDetails Standalone operator property, cardinality, buffers/I/O, and parallelism inspector
DeadlockGraph Pure interactive lock-cycle SVG figure (showLegend={false} for bare SVG)
PlanDiagram Diagram panel with header bar, metric lens switcher, search, and optional inspector
PlanSurface Combined insights, DocDB/type metadata, and active plan view without outer toolbar
PlanInsights Standalone bottleneck cards with Markdown export
ActualSummary / CostStrip Standalone runtime and cost distribution strips
Sql Lightweight zero-dependency SQL tokenizer and formatter
bindPlanViewerI18n Plug in a custom host localization catalog (ships English out of the box)
bindPlanViewerClipboard Plug in a custom clipboard + toast notification handler

Supported Engines

Pair with @culpritsql/plans to parse native plans and deadlocks in the browser or Node.js:

Engine 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 SHOW ENGINE INNODB STATUS
YugabyteDB EXPLAIN (FORMAT JSON) + DocDB RPC/storage metrics PostgreSQL-compatible logs
SQLite EXPLAIN QUERY PLAN Not applicable

Security & Architecture

  • Text-only rendering: Database identifiers, SQL literals, and plan properties are rendered strictly as React text nodes (never dangerouslySetInnerHTML).
  • Zero telemetry or network calls: Pure client/SSR React components (lucide-react icons + peer react).
  • Single source of truth: Synced automatically from culpritsql/culprit-sql-studio (packages/culprit-plan-viewer).

License

MIT. Third-party notices are distributed in pkg/THIRD-PARTY-LICENSES.txt.

About

Interactive React execution plan diagrams, structural diffs, and deadlock cycle graphs for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages