@culpritsql/plans 0.0.0-stage → 0.5.7
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 +153 -2
- package/package.json +46 -4
- package/pkg/THIRD-PARTY-LICENSES.txt +9021 -0
- package/pkg/build-report.json +588 -0
- package/pkg/index.d.ts +26 -0
- package/pkg/index.js +37 -0
- package/pkg/models/ActualSummary.d.ts +16 -0
- package/pkg/models/CachedStatementContext.d.ts +9 -0
- package/pkg/models/CachedStatementIdentity.d.ts +7 -0
- package/pkg/models/ChangeKind.d.ts +3 -0
- package/pkg/models/CollectionStop.d.ts +3 -0
- package/pkg/models/CollectionTarget.d.ts +6 -0
- package/pkg/models/CompareContext.d.ts +12 -0
- package/pkg/models/ConfiguredConnectionIdentity.d.ts +7 -0
- package/pkg/models/DatabaseIdentity.d.ts +5 -0
- package/pkg/models/DatabaseLocation.d.ts +3 -0
- package/pkg/models/Deadlock.d.ts +23 -0
- package/pkg/models/DeadlockFix.d.ts +16 -0
- package/pkg/models/DeadlockFixKind.d.ts +6 -0
- package/pkg/models/DeadlockPattern.d.ts +3 -0
- package/pkg/models/DeadlockProcess.d.ts +23 -0
- package/pkg/models/DeadlockResource.d.ts +12 -0
- package/pkg/models/DeliveryProblem.d.ts +3 -0
- package/pkg/models/DocdbMetrics.d.ts +7 -0
- package/pkg/models/Engine.d.ts +3 -0
- package/pkg/models/Error.d.ts +5 -0
- package/pkg/models/ErrorCode.d.ts +3 -0
- package/pkg/models/ErrorDetail.d.ts +10 -0
- package/pkg/models/ExecutionProtection.d.ts +3 -0
- package/pkg/models/ExportFile.d.ts +7 -0
- package/pkg/models/ExportFormat.d.ts +3 -0
- package/pkg/models/ExportNote.d.ts +11 -0
- package/pkg/models/ExportOptions.d.ts +12 -0
- package/pkg/models/Guess.d.ts +6 -0
- package/pkg/models/InsightArea.d.ts +6 -0
- package/pkg/models/LexError.d.ts +6 -0
- package/pkg/models/LockHolder.d.ts +3 -0
- package/pkg/models/Metric.d.ts +10 -0
- package/pkg/models/MssqlCatalogIndexColumn.d.ts +3 -0
- package/pkg/models/MssqlCurrentTableType.d.ts +10 -0
- package/pkg/models/MssqlCurrentTypeColumn.d.ts +7 -0
- package/pkg/models/MssqlCurrentTypeIndex.d.ts +4 -0
- package/pkg/models/MssqlCurrentTypeModule.d.ts +4 -0
- package/pkg/models/MssqlCurrentTypeParameter.d.ts +3 -0
- package/pkg/models/MssqlCurrentTypeSchema.d.ts +11 -0
- package/pkg/models/MssqlCurrentTypeSchemaStatus.d.ts +3 -0
- package/pkg/models/MssqlIndexParentKind.d.ts +3 -0
- package/pkg/models/MssqlObjectIdentity.d.ts +7 -0
- package/pkg/models/NativeIdentity.d.ts +3 -0
- package/pkg/models/NativePlanIdentity.d.ts +4 -0
- package/pkg/models/NativeQueryIdentity.d.ts +3 -0
- package/pkg/models/NativeReadContext.d.ts +13 -0
- package/pkg/models/NodeKind.d.ts +3 -0
- package/pkg/models/NodeMatch.d.ts +3 -0
- package/pkg/models/NodeRuntime.d.ts +28 -0
- package/pkg/models/OutboxProblem.d.ts +3 -0
- package/pkg/models/Plan.d.ts +11 -0
- package/pkg/models/PlanAccessRows.d.ts +13 -0
- package/pkg/models/PlanAutomaticIndex.d.ts +3 -0
- package/pkg/models/PlanChange.d.ts +17 -0
- package/pkg/models/PlanChangedColumn.d.ts +3 -0
- package/pkg/models/PlanConversion.d.ts +4 -0
- package/pkg/models/PlanConversionIssue.d.ts +3 -0
- package/pkg/models/PlanCurrentTypeSchemaView.d.ts +6 -0
- package/pkg/models/PlanDiff.d.ts +13 -0
- package/pkg/models/PlanExecutionMode.d.ts +3 -0
- package/pkg/models/PlanFacts.d.ts +36 -0
- package/pkg/models/PlanIndexColumns.d.ts +3 -0
- package/pkg/models/PlanIndexHint.d.ts +3 -0
- package/pkg/models/PlanInsight.d.ts +44 -0
- package/pkg/models/PlanInsightShare.d.ts +3 -0
- package/pkg/models/PlanInsights.d.ts +8 -0
- package/pkg/models/PlanKind.d.ts +3 -0
- package/pkg/models/PlanMeasurementRef.d.ts +3 -0
- package/pkg/models/PlanMemoryGrantFeedback.d.ts +15 -0
- package/pkg/models/PlanMemoryGrantFeedbackIssue.d.ts +3 -0
- package/pkg/models/PlanMemoryGrantFeedbackState.d.ts +3 -0
- package/pkg/models/PlanNode.d.ts +7 -0
- package/pkg/models/PlanNodeFacts.d.ts +63 -0
- package/pkg/models/PlanOperatorView.d.ts +5 -0
- package/pkg/models/PlanPageServerIo.d.ts +16 -0
- package/pkg/models/PlanPageServerIoIssue.d.ts +4 -0
- package/pkg/models/PlanPageServerIoView.d.ts +7 -0
- package/pkg/models/PlanPageServerMetric.d.ts +3 -0
- package/pkg/models/PlanParameter.d.ts +10 -0
- package/pkg/models/PlanParameterComparison.d.ts +3 -0
- package/pkg/models/PlanParameterContext.d.ts +15 -0
- package/pkg/models/PlanParameterIssue.d.ts +3 -0
- package/pkg/models/PlanParameterUse.d.ts +4 -0
- package/pkg/models/PlanParameterUseKind.d.ts +3 -0
- package/pkg/models/PlanParameterValueState.d.ts +3 -0
- package/pkg/models/PlanParentRelationship.d.ts +3 -0
- package/pkg/models/PlanRegion.d.ts +7 -0
- package/pkg/models/PlanSampleSource.d.ts +6 -0
- package/pkg/models/PlanScanCompletion.d.ts +8 -0
- package/pkg/models/PlanScanThread.d.ts +3 -0
- package/pkg/models/PlanTemporaryTableUse.d.ts +7 -0
- package/pkg/models/PlanView.d.ts +9 -0
- package/pkg/models/PlanWarning.d.ts +3 -0
- package/pkg/models/RelationalInput.d.ts +5 -0
- package/pkg/models/RelationalInputKind.d.ts +3 -0
- package/pkg/models/RelationalInputProvenance.d.ts +3 -0
- package/pkg/models/RetainedPlanProvenance.d.ts +11 -0
- package/pkg/models/Scenario.d.ts +11 -0
- package/pkg/models/ScenarioKind.d.ts +3 -0
- package/pkg/models/Severity.d.ts +3 -0
- package/pkg/models/SharedResourceIdentity.d.ts +11 -0
- package/pkg/models/SharedResourceKind.d.ts +3 -0
- package/pkg/models/SourcePartition.d.ts +8 -0
- package/pkg/models/StatementOrigin.d.ts +6 -0
- package/pkg/models/StatementProblem.d.ts +4 -0
- package/pkg/models/StatisticsInfo.d.ts +3 -0
- package/pkg/models/TriggerTiming.d.ts +3 -0
- package/pkg/models/Unit.d.ts +3 -0
- package/pkg/models/WorkerSkew.d.ts +3 -0
- package/pkg/native/culprit_wasm.d.ts +49 -0
- package/pkg/native/culprit_wasm.js +378 -0
- package/pkg/native/culprit_wasm_bg.wasm +0 -0
- package/pkg/native/culprit_wasm_bg.wasm.d.ts +11 -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,154 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-dark.png">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-light.png">
|
|
6
|
+
<img alt="@culpritsql/plans" src="https://raw.githubusercontent.com/culpritsql/culprit-plans/main/assets/hero-light.png" width="100%">
|
|
7
|
+
</picture>
|
|
8
|
+
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/@culpritsql/plans)
|
|
12
|
+
[](https://webassembly.org)
|
|
13
|
+
[](https://www.npmjs.com/package/@culpritsql/plans?activeTab=dependencies)
|
|
14
|
+
[](https://github.com/culpritsql/culprit-sql-studio)
|
|
15
|
+
[](./LICENSE)
|
|
16
|
+
|
|
17
|
+
**Portable WebAssembly execution plan parser, structural differ, deadlock parser, and exporter.**
|
|
18
|
+
<br />
|
|
19
|
+
Compiled directly from [Culprit SQL Studio](https://github.com/culpritsql/culprit-sql-studio) and paired with [`@culpritsql/plan-viewer`](https://github.com/culpritsql/culprit-plan-viewer).
|
|
20
|
+
|
|
21
|
+
[Quickstart](#quickstart) · [Supported Engines](#supported-engines) · [API Reference](#api-reference) · [Node.js & Bundlers](#nodejs--bundlers) · [Security & Limits](#security--limits)
|
|
22
|
+
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Quickstart
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install @culpritsql/plans
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Initialize the WebAssembly module once, then call the synchronous parser, comparison, deadlock, and export operations:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import {
|
|
37
|
+
init,
|
|
38
|
+
parsePlan,
|
|
39
|
+
diffPlans,
|
|
40
|
+
parseDeadlock,
|
|
41
|
+
exportPlan,
|
|
42
|
+
} from "@culpritsql/plans";
|
|
43
|
+
|
|
44
|
+
await init();
|
|
45
|
+
|
|
46
|
+
const before = parsePlan(beforePlanText);
|
|
47
|
+
const after = parsePlan(afterPlanText, "postgres");
|
|
48
|
+
const diff = diffPlans(before, "Before", after, "After");
|
|
49
|
+
|
|
50
|
+
const deadlocks = parseDeadlock(deadlockLogText);
|
|
51
|
+
const exported = exportPlan(after, "checkout-query", "markdown", {
|
|
52
|
+
redact: true,
|
|
53
|
+
notes: [],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
> Rendering in React? Pass `Plan`, `PlanDiff`, and `Deadlock` directly to [`@culpritsql/plan-viewer`](https://www.npmjs.com/package/@culpritsql/plan-viewer). Both packages share the exact same generated `ts-rs` model types.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Supported Engines
|
|
62
|
+
|
|
63
|
+
| Engine | Execution Plans | Deadlocks |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| **SQL Server** | `.sqlplan` Showplan XML | XML deadlock graphs |
|
|
66
|
+
| **PostgreSQL** | `EXPLAIN (FORMAT JSON)`, `EXPLAIN (ANALYZE, BUFFERS)` text | Server log deadlock excerpts |
|
|
67
|
+
| **MySQL & MariaDB** | `EXPLAIN FORMAT=JSON`, `EXPLAIN ANALYZE` tree text | `SHOW ENGINE INNODB STATUS` |
|
|
68
|
+
| **YugabyteDB** | `EXPLAIN (FORMAT JSON)` + DocDB RPC/storage metrics | PostgreSQL-compatible logs |
|
|
69
|
+
| **SQLite** | `EXPLAIN QUERY PLAN` text | Not applicable |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## API Reference
|
|
74
|
+
|
|
75
|
+
| Export | Signature | Description |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `init` | `init(input?): Promise<void>` | Instantiates the Wasm module once; subsequent calls reuse the live instance |
|
|
78
|
+
| `parsePlan` | `parsePlan(input: string, engine?: Engine): Plan` | Auto-detects format or validates strictly against `"mssql" \| "postgres" \| "mysql" \| "yugabyte" \| "sqlite"` |
|
|
79
|
+
| `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 |
|
|
80
|
+
| `parseDeadlock` | `parseDeadlock(input: string): Deadlock[]` | Extracts victim selection, participant sessions, held/waited locks, and original timestamps |
|
|
81
|
+
| `exportPlan` | `exportPlan(plan: Plan, title: string, format: ExportFormat, options: ExportOptions): ExportFile` | Exports `"markdown"`, `"html"`, or `"native"` with optional SQL literal redaction |
|
|
82
|
+
| `ParserError` | `class ParserError extends Error` | Structured refusal error (`error.error` carries `{ code, message, hint, detail }`) instead of Wasm traps |
|
|
83
|
+
|
|
84
|
+
### Redacted Exports
|
|
85
|
+
|
|
86
|
+
Setting `redact: true` scrubs SQL string and numeric literals from statements, filter predicates, and native Showplan XML parameter lists before returning the file:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const file = exportPlan(plan, "Order Lookup", "html", {
|
|
90
|
+
redact: true,
|
|
91
|
+
notes: [],
|
|
92
|
+
});
|
|
93
|
+
// file => { name: "order-lookup.html", format: "html", contents: "<!doctype html>..." }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Structured Error Handling
|
|
97
|
+
|
|
98
|
+
Malformed XML/JSON, mismatched engine hints, DTD attempts, or over-depth trees throw `ParserError` cleanly without corrupting the Wasm instance:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { parsePlan, ParserError } from "@culpritsql/plans";
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
const plan = parsePlan(untrustedInput, "postgres");
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (err instanceof ParserError) {
|
|
107
|
+
console.error(err.error.code, err.error.message, err.error.hint);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Node.js & Bundlers
|
|
115
|
+
|
|
116
|
+
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:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { readFile } from "node:fs/promises";
|
|
120
|
+
import { init, parsePlan } from "@culpritsql/plans";
|
|
121
|
+
|
|
122
|
+
const wasmBytes = await readFile(
|
|
123
|
+
new URL(
|
|
124
|
+
"./node_modules/@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm",
|
|
125
|
+
import.meta.url,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
await init({ module_or_path: wasmBytes });
|
|
129
|
+
|
|
130
|
+
const plan = parsePlan("QUERY PLAN\n`--SCAN orders", "sqlite");
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
With **Vite** or **Next.js** static asset URLs:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import wasmUrl from "@culpritsql/plans/pkg/native/culprit_wasm_bg.wasm?url";
|
|
137
|
+
import { init } from "@culpritsql/plans";
|
|
138
|
+
|
|
139
|
+
await init({ module_or_path: wasmUrl });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Security & Limits
|
|
145
|
+
|
|
146
|
+
- **Zero runtime dependencies**: Pure Rust compiled to `wasm32-unknown-unknown` with zero npm dependencies, no database drivers, and no network calls.
|
|
147
|
+
- **Hardened XML & JSON bounds**: Rejects XML `<!DOCTYPE>` / entity expansion (`XXE`) and enforces deterministic depth ceilings (`1,024` XML elements, `56` plan operator levels) on a dedicated 32 MiB Wasm linear stack.
|
|
148
|
+
- **HTML-safe exports**: HTML plan exports escape every identifier, predicate, and title string.
|
|
149
|
+
- **CSP compatibility**: Serve `.wasm` assets with `Content-Type: application/wasm` and include `'wasm-unsafe-eval'` in `script-src` under strict Content Security Policies.
|
|
150
|
+
- **Single source of truth**: Synced automatically from [`culpritsql/culprit-sql-studio`](https://github.com/culpritsql/culprit-sql-studio) (`crates/culprit-plans`, `crates/culprit-wasm`, `packages/culprit-wasm`).
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT. Third-party Rust crate notices are distributed in `pkg/THIRD-PARTY-LICENSES.txt`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@culpritsql/plans",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.7",
|
|
4
|
+
"description": "Portable WebAssembly execution plan parser, comparator, deadlock parser, and exporter for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"pkg"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./pkg/index.d.ts",
|
|
14
|
+
"import": "./pkg/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/culpritsql/culprit-plans.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://culpritsql.com",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/culpritsql/culprit-plans/issues"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"provenance": true
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"sql",
|
|
31
|
+
"execution-plan",
|
|
32
|
+
"query-plan",
|
|
33
|
+
"explain",
|
|
34
|
+
"showplan",
|
|
35
|
+
"sqlplan",
|
|
36
|
+
"deadlock",
|
|
37
|
+
"wasm",
|
|
38
|
+
"webassembly",
|
|
39
|
+
"postgres",
|
|
40
|
+
"postgresql",
|
|
41
|
+
"mssql",
|
|
42
|
+
"sql-server",
|
|
43
|
+
"mysql",
|
|
44
|
+
"mariadb",
|
|
45
|
+
"yugabytedb",
|
|
46
|
+
"sqlite"
|
|
47
|
+
]
|
|
48
|
+
}
|