@culpritsql/plan-viewer 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +205 -2
- package/package.json +22 -4
- package/pkg/index.d.ts +1 -0
- package/pkg/index.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cristian Pufu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,206 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/hero-dark.png">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/hero-light.png">
|
|
6
|
+
<img alt="@culpritsql/plan-viewer" src="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/hero-light.png" width="100%">
|
|
7
|
+
</picture>
|
|
8
|
+
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/@culpritsql/plan-viewer)
|
|
12
|
+
[](https://react.dev)
|
|
13
|
+
[](https://github.com/culpritsql/culprit-sql-studio)
|
|
14
|
+
[](./LICENSE)
|
|
15
|
+
|
|
16
|
+
**Interactive execution plan diagrams, structural diffs, and deadlock cycle graphs for React.**
|
|
17
|
+
<br />
|
|
18
|
+
Extracted directly from [Culprit SQL Studio](https://github.com/culpritsql/culprit-sql-studio) and paired with [`@culpritsql/plans`](https://github.com/culpritsql/culprit-plans).
|
|
19
|
+
|
|
20
|
+
[Quickstart](#quickstart) · [PlanViewer](#planviewer) · [PlanDiffViewer](#plandiffviewer) · [DeadlockViewer](#deadlockviewer) · [Canvas & Primitives](#canvas-only--granular-primitives) · [Theming](#theming--css-isolation)
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npm install @culpritsql/plan-viewer @culpritsql/plans
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { init, parsePlan } from "@culpritsql/plans";
|
|
34
|
+
import { PlanViewer } from "@culpritsql/plan-viewer";
|
|
35
|
+
import "@culpritsql/plan-viewer/styles.css";
|
|
36
|
+
|
|
37
|
+
await init();
|
|
38
|
+
const plan = parsePlan(explainJsonOrXml);
|
|
39
|
+
|
|
40
|
+
export function QueryExplainPanel() {
|
|
41
|
+
return <PlanViewer plan={plan} title="Checkout Query" />;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## `PlanViewer`
|
|
48
|
+
|
|
49
|
+
Drop-in single-plan explorer with bottleneck insights, measured runtime strip, interactive layout switcher, and operator inspector.
|
|
50
|
+
|
|
51
|
+
<picture>
|
|
52
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-plan-dark.png">
|
|
53
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-plan-light.png">
|
|
54
|
+
<img alt="PlanViewer preview" src="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-plan-light.png" width="100%">
|
|
55
|
+
</picture>
|
|
56
|
+
|
|
57
|
+
- **Ranked insights**: Highlights high-impact bottlenecks with plain-language explanations and copyable SQL fixes.
|
|
58
|
+
- **Five synchronized views**: Switch between **Diagram**, **Tree**, **Operations**, **Tables** (per-table/index rollup), and **Raw** (`EXPLAIN` output).
|
|
59
|
+
- **Interactive canvas**: Drag to pan, `Ctrl`/`Cmd` + scroll to zoom around cursor, corner **Minimap**, **Metric lens** (`Time` · `Cost` · `Rows` · `Reads`), and live step search.
|
|
60
|
+
- **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.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<PlanViewer
|
|
64
|
+
plan={plan}
|
|
65
|
+
title="Recent Paid Orders"
|
|
66
|
+
defaultLook="diagram" // "diagram" | "tree" | "operations"
|
|
67
|
+
theme="system" // "light" | "dark" | "system"
|
|
68
|
+
/>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## `PlanDiffViewer`
|
|
74
|
+
|
|
75
|
+
Side-by-side execution plan comparison for before/after index changes, query rewrites, and regressions.
|
|
76
|
+
|
|
77
|
+
<picture>
|
|
78
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-diff-dark.png">
|
|
79
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-diff-light.png">
|
|
80
|
+
<img alt="PlanDiffViewer preview" src="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-diff-light.png" width="100%">
|
|
81
|
+
</picture>
|
|
82
|
+
|
|
83
|
+
- **Verdict banner**: Computes measured speedup or estimated cost ratio (`167x faster`, `3.2x costlier`).
|
|
84
|
+
- **Structural diff**: Marks access-path flips, operator swaps, and added or removed subtrees directly on cards.
|
|
85
|
+
- **Why it changed**: Surfaces index additions, cardinality shifts, parameter differences, and estimator changes.
|
|
86
|
+
- **Synchronized canvas**: Mirrors zoom and viewport scrolling across Plan A and Plan B.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { diffPlans } from "@culpritsql/plans";
|
|
90
|
+
import { PlanDiffViewer } from "@culpritsql/plan-viewer";
|
|
91
|
+
|
|
92
|
+
const diff = diffPlans(beforePlan, "Before", afterPlan, "After");
|
|
93
|
+
|
|
94
|
+
<PlanDiffViewer a={beforePlan} b={afterPlan} diff={diff} nameA="Before" nameB="After" />;
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## `DeadlockViewer`
|
|
100
|
+
|
|
101
|
+
Visual lock-cycle graph and root-cause breakdown for SQL Server XML deadlocks, PostgreSQL logs, and InnoDB status dumps.
|
|
102
|
+
|
|
103
|
+
<picture>
|
|
104
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-deadlock-dark.png">
|
|
105
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-deadlock-light.png">
|
|
106
|
+
<img alt="DeadlockViewer preview" src="https://raw.githubusercontent.com/culpritsql/culprit-plan-viewer/main/assets/preview-deadlock-light.png" width="100%">
|
|
107
|
+
</picture>
|
|
108
|
+
|
|
109
|
+
- **Cycle SVG graph**: Interactive `holds` and `wants` lock curves with hover focus and victim rollback badge.
|
|
110
|
+
- **Pattern badges**: Detects opposite lock ordering, key-lookup cycles, lock conversions, and escalations.
|
|
111
|
+
- **Actionable fixes**: Ordered remediation steps with syntax-highlighted SQL.
|
|
112
|
+
- **Session breakdown**: Displays application, login, isolation level, lock wait mode, and statement per participant.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { parseDeadlock } from "@culpritsql/plans";
|
|
116
|
+
import { DeadlockViewer } from "@culpritsql/plan-viewer";
|
|
117
|
+
|
|
118
|
+
const [deadlock] = parseDeadlock(serverDeadlockText);
|
|
119
|
+
|
|
120
|
+
<DeadlockViewer deadlock={deadlock} />;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Theming & CSS Isolation
|
|
126
|
+
|
|
127
|
+
`@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.
|
|
128
|
+
|
|
129
|
+
| Mode | Usage |
|
|
130
|
+
| --- | --- |
|
|
131
|
+
| **System (default)** | Follows `prefers-color-scheme: dark` automatically |
|
|
132
|
+
| **Component prop** | `<PlanViewer plan={plan} theme="dark" />` or `theme="light"` |
|
|
133
|
+
| **Ancestor attribute** | Set `data-theme="dark"` or `data-theme="light"` on `<html>`, `<body>`, or any wrapper |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Canvas-Only & Granular Primitives
|
|
138
|
+
|
|
139
|
+
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 />`):
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { useState } from "react";
|
|
143
|
+
import { PlanCanvas, NodeDetails } from "@culpritsql/plan-viewer";
|
|
144
|
+
import "@culpritsql/plan-viewer/styles.css";
|
|
145
|
+
|
|
146
|
+
export function CustomSplitExplain({ plan }) {
|
|
147
|
+
const [selectedId, setSelectedId] = useState<number | null>(plan.root.id);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<PlanCanvas
|
|
151
|
+
plan={plan}
|
|
152
|
+
lens="time" // "time" | "cost" | "rows" | "reads"
|
|
153
|
+
showInsights={false} // pure operator flow, no recommendation badges
|
|
154
|
+
height="100%" // fills your container; drag to pan, Ctrl/Cmd + scroll to zoom
|
|
155
|
+
selectedId={selectedId}
|
|
156
|
+
onSelect={setSelectedId}
|
|
157
|
+
theme="dark"
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Every building block is exported individually with full TypeScript definitions:
|
|
164
|
+
|
|
165
|
+
| Export | Purpose |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `PlanCanvas` | Pure interactive DAG flow canvas (pan, cursor zoom, minimap) with zero prose, headers, or drawers |
|
|
168
|
+
| `PlanTree` / `PlanView` | Collapsible operator tree (`showHeader`, `showActualSummary`, `showProps`, `showInsights` all optional) |
|
|
169
|
+
| `PlanOperations` | Searchable, keyboard-navigable (`j`/`k`), multi-column sortable operator table |
|
|
170
|
+
| `PlanObjects` | Per-table and per-index rollup of time, rows, buffer reads, and cache hit ratio |
|
|
171
|
+
| `PlanRaw` | Native XML, JSON, or text plan viewer with one-click copy |
|
|
172
|
+
| `NodeDetails` | Standalone operator property, cardinality, buffers/I/O, and parallelism inspector |
|
|
173
|
+
| `DeadlockGraph` | Pure interactive lock-cycle SVG figure (`showLegend={false}` for bare SVG) |
|
|
174
|
+
| `PlanDiagram` | Diagram panel with header bar, metric lens switcher, search, and optional inspector |
|
|
175
|
+
| `PlanSurface` | Combined insights, DocDB/type metadata, and active plan view without outer toolbar |
|
|
176
|
+
| `PlanInsights` | Standalone bottleneck cards with Markdown export |
|
|
177
|
+
| `ActualSummary` / `CostStrip` | Standalone runtime and cost distribution strips |
|
|
178
|
+
| `Sql` | Lightweight zero-dependency SQL tokenizer and formatter |
|
|
179
|
+
| `bindPlanViewerI18n` | Plug in a custom host localization catalog (ships English out of the box) |
|
|
180
|
+
| `bindPlanViewerClipboard` | Plug in a custom clipboard + toast notification handler |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Supported Engines
|
|
185
|
+
|
|
186
|
+
Pair with [`@culpritsql/plans`](https://www.npmjs.com/package/@culpritsql/plans) to parse native plans and deadlocks in the browser or Node.js:
|
|
187
|
+
|
|
188
|
+
| Engine | Plans | Deadlocks |
|
|
189
|
+
| --- | --- | --- |
|
|
190
|
+
| **SQL Server** | `.sqlplan` Showplan XML | XML deadlock graphs |
|
|
191
|
+
| **PostgreSQL** | `EXPLAIN (FORMAT JSON)`, `EXPLAIN (ANALYZE, BUFFERS)` text | Server log deadlock excerpts |
|
|
192
|
+
| **MySQL & MariaDB** | `EXPLAIN FORMAT=JSON`, `EXPLAIN ANALYZE` tree | `SHOW ENGINE INNODB STATUS` |
|
|
193
|
+
| **YugabyteDB** | `EXPLAIN (FORMAT JSON)` + DocDB RPC/storage metrics | PostgreSQL-compatible logs |
|
|
194
|
+
| **SQLite** | `EXPLAIN QUERY PLAN` | Not applicable |
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Security & Architecture
|
|
199
|
+
|
|
200
|
+
- **Text-only rendering**: Database identifiers, SQL literals, and plan properties are rendered strictly as React text nodes (never `dangerouslySetInnerHTML`).
|
|
201
|
+
- **Zero telemetry or network calls**: Pure client/SSR React components (`lucide-react` icons + peer `react`).
|
|
202
|
+
- **Single source of truth**: Synced automatically from [`culpritsql/culprit-sql-studio`](https://github.com/culpritsql/culprit-sql-studio) (`packages/culprit-plan-viewer`).
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
MIT. Third-party notices are distributed in `pkg/THIRD-PARTY-LICENSES.txt`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@culpritsql/plan-viewer",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Interactive React execution plan diagram, structural plan diff, and deadlock cycle graph components for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"pkg"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./pkg/index.d.ts",
|
|
13
|
+
"import": "./pkg/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/culpritsql/culprit-plan-viewer.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://culpritsql.com",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/culpritsql/culprit-plan-viewer/issues"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/pkg/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/pkg/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|