@culpritsql/plan-viewer 0.0.0-stage → 0.5.6
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 +57 -4
- package/pkg/ActualSummary.d.ts +10 -0
- package/pkg/ActualSummary.js +72 -0
- package/pkg/DeadlockGraph.d.ts +9 -0
- package/pkg/DeadlockGraph.js +135 -0
- package/pkg/DeadlockViewer.d.ts +20 -0
- package/pkg/DeadlockViewer.js +62 -0
- package/pkg/DocdbWork.d.ts +7 -0
- package/pkg/DocdbWork.js +37 -0
- package/pkg/NodeDetails.d.ts +15 -0
- package/pkg/NodeDetails.js +161 -0
- package/pkg/OpIcon.d.ts +9 -0
- package/pkg/OpIcon.js +54 -0
- package/pkg/PlanAssessmentNotes.d.ts +3 -0
- package/pkg/PlanAssessmentNotes.js +8 -0
- package/pkg/PlanCanvas.d.ts +47 -0
- package/pkg/PlanCanvas.js +9 -0
- package/pkg/PlanDiagram.d.ts +47 -0
- package/pkg/PlanDiagram.js +534 -0
- package/pkg/PlanDiffViewer.d.ts +31 -0
- package/pkg/PlanDiffViewer.js +317 -0
- package/pkg/PlanInsights.d.ts +6 -0
- package/pkg/PlanInsights.js +100 -0
- package/pkg/PlanObjects.d.ts +7 -0
- package/pkg/PlanObjects.js +138 -0
- package/pkg/PlanOperations.d.ts +8 -0
- package/pkg/PlanOperations.js +114 -0
- package/pkg/PlanRaw.d.ts +4 -0
- package/pkg/PlanRaw.js +35 -0
- package/pkg/PlanSurface.d.ts +21 -0
- package/pkg/PlanSurface.js +66 -0
- package/pkg/PlanTypeSchema.d.ts +5 -0
- package/pkg/PlanTypeSchema.js +62 -0
- package/pkg/PlanView.d.ts +27 -0
- package/pkg/PlanView.js +160 -0
- package/pkg/PlanViewer.d.ts +30 -0
- package/pkg/PlanViewer.js +19 -0
- package/pkg/Prose.d.ts +4 -0
- package/pkg/Prose.js +6 -0
- package/pkg/Sql.d.ts +5 -0
- package/pkg/Sql.js +7 -0
- package/pkg/THIRD-PARTY-LICENSES.txt +9021 -0
- package/pkg/build-report.json +907 -0
- package/pkg/defaults.d.ts +29 -0
- package/pkg/defaults.js +438 -0
- package/pkg/host.d.ts +118 -0
- package/pkg/host.js +593 -0
- package/pkg/index.d.ts +22 -0
- package/pkg/index.js +21 -0
- package/pkg/models/Ability.d.ts +6 -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/CleanupEvidence.d.ts +6 -0
- package/pkg/models/CollectionTarget.d.ts +5 -0
- package/pkg/models/CompilationMemory.d.ts +3 -0
- package/pkg/models/CompileHistory.d.ts +13 -0
- package/pkg/models/Connect.d.ts +22 -0
- package/pkg/models/ConnectionSecurityMode.d.ts +3 -0
- package/pkg/models/ConnectionSecuritySpec.d.ts +4 -0
- package/pkg/models/ConstraintValidation.d.ts +6 -0
- package/pkg/models/DatabaseIdentity.d.ts +5 -0
- package/pkg/models/DatabaseLocation.d.ts +3 -0
- package/pkg/models/DatabaseProduct.d.ts +6 -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/DistributionPopulation.d.ts +3 -0
- package/pkg/models/DocdbMetrics.d.ts +7 -0
- package/pkg/models/Engine.d.ts +3 -0
- package/pkg/models/EngineAbilities.d.ts +46 -0
- package/pkg/models/EngineFacts.d.ts +28 -0
- package/pkg/models/EvidencePresentation.d.ts +4 -0
- package/pkg/models/ExecutionProtection.d.ts +3 -0
- package/pkg/models/Guess.d.ts +6 -0
- package/pkg/models/InsightArea.d.ts +6 -0
- package/pkg/models/LocalizedText.d.ts +4 -0
- package/pkg/models/LockHolder.d.ts +3 -0
- package/pkg/models/LogRateGovernanceReason.d.ts +7 -0
- package/pkg/models/Message.d.ts +4 -0
- package/pkg/models/MessageValue.d.ts +4 -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/PageServerReadAvailability.d.ts +3 -0
- package/pkg/models/PageServerReadStatistics.d.ts +8 -0
- package/pkg/models/PageServerReadSummary.d.ts +19 -0
- package/pkg/models/PartitionTail.d.ts +6 -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/PlanHistory.d.ts +6 -0
- package/pkg/models/PlanHistoryKind.d.ts +3 -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/PlanVariant.d.ts +23 -0
- package/pkg/models/PlanView.d.ts +9 -0
- package/pkg/models/PlanWarning.d.ts +3 -0
- package/pkg/models/PlanningStep.d.ts +7 -0
- package/pkg/models/ProductFacts.d.ts +11 -0
- package/pkg/models/QueryCosts.d.ts +62 -0
- package/pkg/models/QueryStat.d.ts +69 -0
- package/pkg/models/QueryTrend.d.ts +7 -0
- package/pkg/models/QueryVariantFamily.d.ts +9 -0
- package/pkg/models/QueryWaitCoverage.d.ts +8 -0
- package/pkg/models/ReadUnit.d.ts +7 -0
- package/pkg/models/Refusal.d.ts +7 -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/RequestEvidence.d.ts +7 -0
- package/pkg/models/RetainedPlanProvenance.d.ts +11 -0
- package/pkg/models/RuntimeDistribution.d.ts +16 -0
- package/pkg/models/RuntimeDistributionIssue.d.ts +3 -0
- package/pkg/models/RuntimeDistributionOrigin.d.ts +3 -0
- package/pkg/models/RuntimeDuration.d.ts +3 -0
- package/pkg/models/RuntimeHistogramBucket.d.ts +8 -0
- package/pkg/models/RuntimeQuantile.d.ts +4 -0
- package/pkg/models/Scenario.d.ts +11 -0
- package/pkg/models/ScenarioKind.d.ts +3 -0
- package/pkg/models/SessionAction.d.ts +6 -0
- package/pkg/models/SessionIdFormat.d.ts +6 -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/Spread.d.ts +18 -0
- package/pkg/models/SqlSyntax.d.ts +6 -0
- package/pkg/models/StatementMetrics.d.ts +32 -0
- package/pkg/models/StatementOrigin.d.ts +6 -0
- package/pkg/models/StatementTemporaryWork.d.ts +3 -0
- package/pkg/models/StatisticsFreshness.d.ts +3 -0
- package/pkg/models/TriggerTiming.d.ts +3 -0
- package/pkg/models/Unit.d.ts +3 -0
- package/pkg/models/WaitClass.d.ts +3 -0
- package/pkg/models/WaitMechanism.d.ts +4 -0
- package/pkg/models/WaitSampling.d.ts +3 -0
- package/pkg/models/WaitStat.d.ts +4 -0
- package/pkg/models/WorkerSkew.d.ts +3 -0
- package/pkg/models/WriteLog.d.ts +7 -0
- package/pkg/models/WriteRows.d.ts +7 -0
- package/pkg/styles.css +3273 -0
- package/pkg/types.d.ts +29 -0
- package/pkg/types.js +1 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowDown, ArrowUp, Search } from "lucide-react";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { allNodes, canPlanEstimates, duration, estRowsForRuns, findingNoShareReason, insightsByNode, misestimate, noShareReason, operatorRuns, percent, planShares, rows, shortPredicate, t, } from "./host.js";
|
|
5
|
+
import { OpIcon } from "./OpIcon.js";
|
|
6
|
+
const COLUMNS = [
|
|
7
|
+
{ key: "cost", label: () => t("ui.plan_operations.column.self"), title: () => t("ui.plan_operations.column.self_title") },
|
|
8
|
+
{ key: "subtree", label: () => t("ui.plan_operations.column.subtree"), title: () => t("ui.plan_operations.column.subtree_title") },
|
|
9
|
+
{ key: "est", label: () => t("ui.plan_operations.column.est"), title: () => t("ui.plan_operations.column.est_title") },
|
|
10
|
+
{ key: "act", label: () => t("ui.plan_operations.column.act"), title: () => t("ui.plan_operations.column.act_title"), actual: true },
|
|
11
|
+
{ key: "error", label: () => t("ui.plan_operations.column.error"), title: () => t("ui.plan_operations.column.error_title"), actual: true },
|
|
12
|
+
{ key: "runs", label: () => t("common.metric.runs"), title: () => t("ui.plan_operations.column.runs_title") },
|
|
13
|
+
{ key: "read", label: () => t("ui.plan_operations.column.read"), title: () => t("ui.plan_operations.column.read_title") },
|
|
14
|
+
{ key: "time", label: () => t("ui.plan_operations.column.time"), title: () => t("ui.plan_operations.column.time_title"), actual: true },
|
|
15
|
+
{ key: "issues", label: () => t("ui.plan_operations.column.issues"), title: () => t("ui.plan_operations.column.issues_title") },
|
|
16
|
+
];
|
|
17
|
+
export function PlanOperations({ plan, query: statement, focus, selectedId, onSelect, }) {
|
|
18
|
+
const [sort, setSort] = useState({ key: "cost", desc: true });
|
|
19
|
+
const [query, setQuery] = useState("");
|
|
20
|
+
const [issuesOnly, setIssuesOnly] = useState(false);
|
|
21
|
+
const body = useRef(null);
|
|
22
|
+
const shares = useMemo(() => planShares(plan, statement), [plan, statement]);
|
|
23
|
+
const actual = allNodes(plan.root).some((n) => n.act_rows != null);
|
|
24
|
+
const timed = allNodes(plan.root).some((n) => n.act_time_ms != null);
|
|
25
|
+
const flagged = useMemo(() => insightsByNode(plan), [plan]);
|
|
26
|
+
const all = useMemo(() => {
|
|
27
|
+
const out = [];
|
|
28
|
+
const visit = (n, depth) => {
|
|
29
|
+
const list = flagged.get(n.id) ?? [];
|
|
30
|
+
const err = misestimate(plan, n);
|
|
31
|
+
out.push({
|
|
32
|
+
node: n,
|
|
33
|
+
depth,
|
|
34
|
+
self: shares.stated.get(n.id) ?? null,
|
|
35
|
+
subtree: shares.statedSubtree.get(n.id) ?? null,
|
|
36
|
+
error: err != null ? Math.abs(err) : 0,
|
|
37
|
+
issues: list.length + n.warnings.length,
|
|
38
|
+
worst: list[0]?.severity ?? (n.warnings.length ? "low" : null),
|
|
39
|
+
});
|
|
40
|
+
n.children.forEach((c) => visit(c, depth + 1));
|
|
41
|
+
};
|
|
42
|
+
visit(plan.root, 0);
|
|
43
|
+
return out;
|
|
44
|
+
}, [plan, shares, flagged]);
|
|
45
|
+
const visible = useMemo(() => {
|
|
46
|
+
const q = query.trim().toLowerCase();
|
|
47
|
+
const value = (r) => {
|
|
48
|
+
switch (sort.key) {
|
|
49
|
+
case "cost":
|
|
50
|
+
return r.self ?? -1;
|
|
51
|
+
case "subtree":
|
|
52
|
+
return r.subtree ?? -1;
|
|
53
|
+
case "est":
|
|
54
|
+
return estRowsForRuns(plan, r.node) ?? -1;
|
|
55
|
+
case "act":
|
|
56
|
+
return r.node.act_rows ?? -1;
|
|
57
|
+
case "error":
|
|
58
|
+
return r.error;
|
|
59
|
+
case "runs":
|
|
60
|
+
return operatorRuns(plan, r.node) ?? -1;
|
|
61
|
+
case "read":
|
|
62
|
+
return r.node.rows_read ?? -1;
|
|
63
|
+
case "time":
|
|
64
|
+
return r.node.act_time_ms ?? -1;
|
|
65
|
+
case "issues":
|
|
66
|
+
return r.issues * 10 + (r.worst === "high" ? 3 : r.worst === "medium" ? 2 : r.worst ? 1 : 0);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return all
|
|
70
|
+
.filter((r) => !issuesOnly || r.issues > 0)
|
|
71
|
+
.filter((r) => !q || `${r.node.op} ${r.node.object ?? ""} ${r.node.index ?? ""} ${r.node.predicate ?? ""}`.toLowerCase().includes(q))
|
|
72
|
+
.sort((a, b) => (sort.desc ? value(b) - value(a) : value(a) - value(b)));
|
|
73
|
+
}, [all, plan, sort, query, issuesOnly]);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
body.current?.querySelector("tr.sel")?.scrollIntoView({ block: "nearest" });
|
|
76
|
+
}, [selectedId]);
|
|
77
|
+
const hasRead = all.some((r) => r.node.rows_read != null);
|
|
78
|
+
const hasRuns = all.some((r) => (r.node.act_executions ?? r.node.est_executions) > 1);
|
|
79
|
+
const hasIssues = all.some((r) => r.issues > 0);
|
|
80
|
+
const weighed = canPlanEstimates(plan.engine) || actual;
|
|
81
|
+
const columns = COLUMNS.filter((c) => (!c.actual || actual) &&
|
|
82
|
+
(weighed || (c.key !== "cost" && c.key !== "subtree" && c.key !== "est")) &&
|
|
83
|
+
(c.key !== "time" || timed) &&
|
|
84
|
+
(c.key !== "read" || hasRead) &&
|
|
85
|
+
(c.key !== "runs" || hasRuns) &&
|
|
86
|
+
(c.key !== "issues" || hasIssues));
|
|
87
|
+
const move = (delta) => {
|
|
88
|
+
const index = visible.findIndex((r) => r.node.id === selectedId);
|
|
89
|
+
const next = visible[Math.min(visible.length - 1, Math.max(0, index + delta))];
|
|
90
|
+
if (next)
|
|
91
|
+
onSelect(next.node.id);
|
|
92
|
+
};
|
|
93
|
+
return (_jsxs("div", { className: "culprit-pv ops", children: [_jsxs("div", { className: "ops-tools", children: [_jsxs("label", { className: "search ops-search", children: [_jsx(Search, { size: 12 }), _jsx("input", { value: query, placeholder: t("ui.plan_operations.filter"), onChange: (e) => setQuery(e.target.value) })] }), _jsxs("label", { className: "ops-toggle", children: [_jsx("input", { type: "checkbox", checked: issuesOnly, onChange: (e) => setIssuesOnly(e.target.checked) }), t("ui.plan_operations.issues_only")] }), _jsx("span", { className: "spacer" }), _jsx("span", { className: "muted", children: t("ui.plan_operations.shown", { shown: visible.length, count: all.length }) })] }), _jsxs("div", { className: "ops-scroll",
|
|
94
|
+
// biome-ignore lint/a11y/noNoninteractiveTabindex: arrow keys and j/k move the selected operation from here
|
|
95
|
+
tabIndex: 0, onKeyDown: (e) => {
|
|
96
|
+
if (e.key === "ArrowDown" || e.key === "j") {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
move(1);
|
|
99
|
+
}
|
|
100
|
+
else if (e.key === "ArrowUp" || e.key === "k") {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
move(-1);
|
|
103
|
+
}
|
|
104
|
+
}, children: [_jsxs("table", { className: "ops-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { className: "ops-op", children: t("ui.plan_operations.operator") }), columns.map((c) => (_jsxs("th", { className: `r sortable col-${c.key}`, title: c.title(), "aria-sort": sort.key === c.key ? (sort.desc ? "descending" : "ascending") : "none", onClick: () => setSort((s) => (s.key === c.key ? { key: c.key, desc: !s.desc } : { key: c.key, desc: true })), children: [c.key === "read" && plan.kind !== "actual" ? t("ui.plan_operations.column.est_read") : c.label(), sort.key === c.key && (sort.desc ? _jsx(ArrowDown, { size: 11 }) : _jsx(ArrowUp, { size: 11 }))] }, c.key)))] }) }), _jsx("tbody", { ref: body, children: visible.map((r) => {
|
|
105
|
+
const n = r.node;
|
|
106
|
+
const err = misestimate(plan, n);
|
|
107
|
+
const runs = operatorRuns(plan, n);
|
|
108
|
+
return (_jsxs("tr", { className: `${n.id === selectedId ? "sel" : ""}`, onClick: () => onSelect(n.id), children: [_jsx("td", { className: "ops-op", children: _jsxs("span", { className: "ops-name", children: [_jsx("span", { className: "ops-icon", children: _jsx(OpIcon, { node: n, size: 13 }) }), _jsxs("span", { className: "ops-text", children: [_jsx("b", { children: n.op }), (n.object || n.index) && (_jsxs("span", { className: "mono muted", children: [" ", n.object?.split(".").pop(), n.index ? ` · ${n.index}` : ""] })), (n.seek_predicate || n.predicate) && _jsx("span", { className: "ops-pred mono", children: shortPredicate(n.seek_predicate ?? n.predicate ?? "") })] })] }) }), columns.map((c) => (_jsxs("td", { className: `r num col-${c.key}`, children: [c.key === "cost" &&
|
|
109
|
+
(r.self != null ? (_jsxs("span", { className: "ops-cost", children: [_jsx("span", { className: "ops-cost-bar", children: _jsx("span", { style: { width: `${Math.min(100, r.self * 100)}%` } }) }), percent(r.self)] })) : (_jsx("span", { className: "muted", title: shares.basis === "cost"
|
|
110
|
+
? (focus === n.id ? findingNoShareReason(plan, n, statement) : noShareReason(plan, n, statement)) ?? undefined
|
|
111
|
+
: undefined, children: "\u2014" }))), c.key === "subtree" && (r.subtree != null ? percent(r.subtree) : _jsx("span", { className: "muted", children: "\u2014" })), c.key === "est" && rows(estRowsForRuns(plan, n)), c.key === "act" && (n.act_rows != null ? rows(n.act_rows) : "—"), c.key === "error" &&
|
|
112
|
+
(err != null && Math.abs(err) >= 2 ? (_jsx("span", { className: `ops-err ${n.warnings.includes("misestimate") ? "bad" : ""}`, children: err > 0 ? t("ui.plan_operations.more", { times: rows(Math.abs(err)) }) : t("ui.plan_operations.fewer", { times: rows(Math.abs(err)) }) })) : (_jsx("span", { className: "muted", children: "\u2014" }))), c.key === "runs" && (runs == null ? "—" : runs > 1 ? rows(runs) : _jsx("span", { className: "muted", children: rows(runs) })), c.key === "read" && (n.rows_read != null ? rows(n.rows_read) : _jsx("span", { className: "muted", children: "\u2014" })), c.key === "time" && (n.act_time_ms != null ? duration(n.act_time_ms) : _jsx("span", { className: "muted", children: "\u2014" })), c.key === "issues" && (r.issues > 0 ? _jsx("span", { className: `ops-issues ${r.worst ?? ""}`, children: r.issues }) : _jsx("span", { className: "muted", children: "\u2014" }))] }, c.key)))] }, n.id));
|
|
113
|
+
}) })] }), visible.length === 0 && _jsx("div", { className: "empty", style: { padding: 24 }, children: t("ui.plan_operations.none") })] })] }));
|
|
114
|
+
}
|
package/pkg/PlanRaw.d.ts
ADDED
package/pkg/PlanRaw.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Copy, FileCode } from "lucide-react";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { copyAndTell, exact, planEngineName, t } from "./host.js";
|
|
5
|
+
import { Sql } from "./Sql.js";
|
|
6
|
+
function rawFormatLabel(raw) {
|
|
7
|
+
const trimmed = raw.trimStart();
|
|
8
|
+
if (trimmed.startsWith("<"))
|
|
9
|
+
return "XML";
|
|
10
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("["))
|
|
11
|
+
return "JSON";
|
|
12
|
+
return "TEXT";
|
|
13
|
+
}
|
|
14
|
+
export function PlanRaw({ plan }) {
|
|
15
|
+
const raw = plan.raw;
|
|
16
|
+
const formatted = useMemo(() => {
|
|
17
|
+
if (!raw)
|
|
18
|
+
return null;
|
|
19
|
+
const trimmed = raw.trim();
|
|
20
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(JSON.parse(trimmed), null, 2);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return raw;
|
|
29
|
+
}, [raw]);
|
|
30
|
+
if (!formatted) {
|
|
31
|
+
return (_jsxs("div", { className: "culprit-pv plan plan-raw", children: [_jsxs("div", { className: "plan-head", children: [_jsx(FileCode, { size: 13, className: "muted" }), _jsx("span", { className: "tag", children: planEngineName(plan) }), _jsx("span", { className: "muted", children: t("ui.plan_raw.unavailable") })] }), plan.statement && (_jsx("div", { className: "plan-raw-sql", children: _jsx(Sql, { text: plan.statement }) }))] }));
|
|
32
|
+
}
|
|
33
|
+
const lineCount = formatted.split("\n").length;
|
|
34
|
+
return (_jsxs("div", { className: "culprit-pv plan plan-raw", children: [_jsxs("div", { className: "plan-head", children: [_jsx("span", { className: "tag", children: rawFormatLabel(formatted) }), _jsxs("span", { className: "muted", children: [planEngineName(plan), " \u00B7 ", t("ui.plan_raw.lines", { n: lineCount, count: exact(lineCount) })] }), _jsx("span", { className: "spacer" }), _jsxs("button", { type: "button", className: "btn ghost small", onClick: () => copyAndTell(formatted, t("ui.plan_raw.copied")), children: [_jsx(Copy, { size: 12 }), " ", t("ui.plan_raw.copy")] })] }), _jsx("pre", { className: "plan-raw-code selectable", children: formatted })] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Plan, QueryStat } from "./types.js";
|
|
2
|
+
export type PlanLook = "diagram" | "tree" | "operations" | "objects" | "raw";
|
|
3
|
+
export declare function rememberedLook(): PlanLook;
|
|
4
|
+
export declare function rememberLook(look: PlanLook): void;
|
|
5
|
+
/** Diagram · Tree · Operations · Tables · Raw. */
|
|
6
|
+
export declare function LookToggle({ look, onChange, hasRaw, }: {
|
|
7
|
+
look: PlanLook;
|
|
8
|
+
onChange: (look: PlanLook) => void;
|
|
9
|
+
hasRaw?: boolean;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
/**
|
|
12
|
+
* A plan with everything Culprit knows about it: the insights first (what's wrong, how to fix it), then the plan in the
|
|
13
|
+
* chosen view. Picking an insight selects its operator in whichever view is showing, and back.
|
|
14
|
+
*/
|
|
15
|
+
export declare function PlanSurface({ plan, query, focus, look, badge, }: {
|
|
16
|
+
plan: Plan;
|
|
17
|
+
query?: QueryStat | null;
|
|
18
|
+
focus?: number | null;
|
|
19
|
+
look: PlanLook;
|
|
20
|
+
badge?: string;
|
|
21
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Database, FileCode, GitBranch, ListTree, Network, TableProperties } from "lucide-react";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { DocdbWork } from "./DocdbWork.js";
|
|
5
|
+
import { allNodes, canPlanEstimates, cost, findingNoShareReason, genericPlanContextKey, insightsByNode, noShareReason, planKindLabel, planShares, remember, rememberedChoice, t, tabListKeys, } from "./host.js";
|
|
6
|
+
import { NodeDetails } from "./NodeDetails.js";
|
|
7
|
+
import { PlanAssessmentNotes } from "./PlanAssessmentNotes.js";
|
|
8
|
+
import { PlanDiagram } from "./PlanDiagram.js";
|
|
9
|
+
import { PlanInsights } from "./PlanInsights.js";
|
|
10
|
+
import { PlanObjects } from "./PlanObjects.js";
|
|
11
|
+
import { PlanOperations } from "./PlanOperations.js";
|
|
12
|
+
import { PlanRaw } from "./PlanRaw.js";
|
|
13
|
+
import { PlanTypeSchema } from "./PlanTypeSchema.js";
|
|
14
|
+
import { PlanView } from "./PlanView.js";
|
|
15
|
+
const LOOK_KEY = "culprit.plan.look";
|
|
16
|
+
const ALL_LOOKS = ["diagram", "tree", "operations", "objects", "raw"];
|
|
17
|
+
export function rememberedLook() {
|
|
18
|
+
return rememberedChoice(LOOK_KEY, "diagram", ALL_LOOKS);
|
|
19
|
+
}
|
|
20
|
+
export function rememberLook(look) {
|
|
21
|
+
remember(LOOK_KEY, look);
|
|
22
|
+
}
|
|
23
|
+
const LOOKS = [
|
|
24
|
+
{ look: "diagram", label: () => t("ui.plan_surface.diagram"), icon: Network, hint: () => t("ui.plan_surface.diagram_hint") },
|
|
25
|
+
{ look: "tree", label: () => t("ui.plan_surface.tree"), icon: ListTree, hint: () => t("ui.plan_surface.tree_hint") },
|
|
26
|
+
{ look: "operations", label: () => t("ui.plan_surface.operations"), icon: TableProperties, hint: () => t("ui.plan_surface.operations_hint") },
|
|
27
|
+
{ look: "objects", label: () => t("ui.plan_surface.objects"), icon: Database, hint: () => t("ui.plan_surface.objects_hint") },
|
|
28
|
+
{ look: "raw", label: () => t("ui.plan_surface.raw"), icon: FileCode, hint: () => t("ui.plan_surface.raw_hint") },
|
|
29
|
+
];
|
|
30
|
+
/** Diagram · Tree · Operations · Tables · Raw. */
|
|
31
|
+
export function LookToggle({ look, onChange, hasRaw = true, }) {
|
|
32
|
+
const visibleLooks = hasRaw ? LOOKS : LOOKS.filter((item) => item.look !== "raw");
|
|
33
|
+
return (_jsx("span", { className: "seg look-toggle", role: "tablist", "aria-label": t("ui.plan_surface.label"), onKeyDown: tabListKeys, children: visibleLooks.map((l) => {
|
|
34
|
+
const Icon = l.icon;
|
|
35
|
+
return (_jsxs("button", { type: "button", role: "tab", "aria-selected": look === l.look, tabIndex: look === l.look ? 0 : -1, className: look === l.look ? "on" : "", title: l.hint(), onClick: () => onChange(l.look), children: [_jsx(Icon, { size: 12 }), l.label()] }, l.look));
|
|
36
|
+
}) }));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A plan with everything Culprit knows about it: the insights first (what's wrong, how to fix it), then the plan in the
|
|
40
|
+
* chosen view. Picking an insight selects its operator in whichever view is showing, and back.
|
|
41
|
+
*/
|
|
42
|
+
export function PlanSurface({ plan, query, focus, look, badge, }) {
|
|
43
|
+
const [selected, setSelected] = useState(null);
|
|
44
|
+
return (_jsxs("div", { className: "culprit-pv plan-surface", children: [plan.facts.constants_redacted && _jsx("p", { className: "notice", children: t("ui.plan_surface.redacted") }), !plan.insights?.note && plan.kind === "generic" && (_jsx(PlanAssessmentNotes, { note: [t("ui.plan_surface.generic"), t(genericPlanContextKey(plan.engine)), t("ui.plan_surface.generic_history")].filter(Boolean).join(" ") })), _jsx(PlanInsights, { plan: plan, selectedNode: selected, onSelectNode: setSelected }), _jsx(DocdbWork, { metrics: plan.facts.docdb, basis: "execution" }), _jsx(PlanTypeSchema, { plan: plan }), look === "diagram" && _jsx(PlanDiagram, { plan: plan, query: query, focus: focus, selectedId: selected, onSelect: setSelected, badge: badge }), look === "tree" && _jsx(PlanView, { plan: plan, query: query, focus: focus, selectedId: selected, onSelect: setSelected }), look === "operations" && _jsx(OperationsPanel, { plan: plan, query: query, focus: focus, selected: selected ?? focus ?? null, onSelect: setSelected }), look === "objects" && _jsx(ObjectsPanel, { plan: plan, query: query, focus: focus, selected: selected ?? focus ?? null, onSelect: setSelected }), look === "raw" && _jsx(PlanRaw, { plan: plan })] }));
|
|
45
|
+
}
|
|
46
|
+
function OperationsPanel({ plan, query, focus, selected, onSelect, }) {
|
|
47
|
+
const shares = useMemo(() => planShares(plan, query), [plan, query]);
|
|
48
|
+
const nodes = useMemo(() => allNodes(plan.root), [plan]);
|
|
49
|
+
const flagged = useMemo(() => insightsByNode(plan), [plan]);
|
|
50
|
+
const shareOf = (id) => shares.stated.get(id) ?? null;
|
|
51
|
+
const start = shares.hottest ?? plan.root;
|
|
52
|
+
const current = nodes.find((n) => n.id === (selected ?? start.id)) ?? null;
|
|
53
|
+
return (_jsxs("div", { className: "plan", children: [_jsxs("div", { className: "plan-head", children: [_jsx("span", { className: "tag", children: planKindLabel(plan) }), _jsxs("span", { children: [t("ui.common.plan_operators", { count: nodes.length }), canPlanEstimates(plan.engine) &&
|
|
54
|
+
` · ${plan.facts.estimated_cost_unavailable
|
|
55
|
+
? t("ui.common.plan_cost_unavailable")
|
|
56
|
+
: t("ui.common.plan_cost", { cost: cost(plan.total_cost || plan.root.subtree_cost) })}`] }), _jsx("span", { className: "spacer" }), _jsx(GitBranch, { size: 12, className: "muted" }), _jsx("span", { className: "muted", children: t("ui.plan_surface.click_row") })] }), _jsx(PlanOperations, { plan: plan, query: query, focus: focus, selectedId: current?.id ?? null, onSelect: onSelect }), current && (_jsx(NodeDetails, { plan: plan, estimates: canPlanEstimates(plan.engine), actual: plan.kind === "actual", node: current, share: shareOf(current.id), subtreeShare: shares.statedSubtree.get(current.id) ?? null, noShare: shares.basis === "cost" ? (current.id === focus ? findingNoShareReason(plan, current, query) : noShareReason(plan, current, query)) : null, insights: flagged.get(current.id) }))] }));
|
|
57
|
+
}
|
|
58
|
+
function ObjectsPanel({ plan, query, focus, selected, onSelect, }) {
|
|
59
|
+
const shares = useMemo(() => planShares(plan, query), [plan, query]);
|
|
60
|
+
const nodes = useMemo(() => allNodes(plan.root), [plan]);
|
|
61
|
+
const flagged = useMemo(() => insightsByNode(plan), [plan]);
|
|
62
|
+
const shareOf = (id) => shares.stated.get(id) ?? null;
|
|
63
|
+
const firstWithObject = nodes.find((n) => n.object != null) ?? shares.hottest ?? plan.root;
|
|
64
|
+
const current = nodes.find((n) => n.id === (selected ?? firstWithObject.id)) ?? null;
|
|
65
|
+
return (_jsxs("div", { className: "plan", children: [_jsxs("div", { className: "plan-head", children: [_jsx("span", { className: "tag", children: planKindLabel(plan) }), _jsx("span", { children: t("ui.plan_surface.objects_hint") }), _jsx("span", { className: "spacer" }), _jsx(GitBranch, { size: 12, className: "muted" }), _jsx("span", { className: "muted", children: t("ui.plan_surface.click_row") })] }), _jsx(PlanObjects, { plan: plan, query: query, selectedId: current?.id ?? null, onSelect: onSelect }), current && (_jsx(NodeDetails, { plan: plan, estimates: canPlanEstimates(plan.engine), actual: plan.kind === "actual", node: current, share: shareOf(current.id), subtreeShare: shares.statedSubtree.get(current.id) ?? null, noShare: shares.basis === "cost" ? (current.id === focus ? findingNoShareReason(plan, current, query) : noShareReason(plan, current, query)) : null, insights: flagged.get(current.id) }))] }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown, TableProperties } from "lucide-react";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { digits, t } from "./host.js";
|
|
5
|
+
const MAX_TYPES = 8;
|
|
6
|
+
const MAX_PARAMETERS = 16;
|
|
7
|
+
const MAX_COLUMNS = 64;
|
|
8
|
+
const MAX_INDEXES = 8;
|
|
9
|
+
const MAX_INDEX_COLUMNS = 64;
|
|
10
|
+
const MAX_LIMITATIONS = 4;
|
|
11
|
+
const MAX_NATIVE_TEXT = 256;
|
|
12
|
+
/** The backend owns association and wording; these are separately timed current catalog fields. */
|
|
13
|
+
export function PlanTypeSchema({ plan }) {
|
|
14
|
+
const id = useId();
|
|
15
|
+
const schema = plan.facts.current_type_schema;
|
|
16
|
+
const view = plan.view?.current_type_schema;
|
|
17
|
+
if (!schema || !view)
|
|
18
|
+
return null;
|
|
19
|
+
const types = schema.types.slice(0, MAX_TYPES);
|
|
20
|
+
const parameters = schema.parameters.slice(0, MAX_PARAMETERS);
|
|
21
|
+
const available = schema.status === "available";
|
|
22
|
+
const limited = schema.types.length > MAX_TYPES ||
|
|
23
|
+
schema.parameters.length > MAX_PARAMETERS ||
|
|
24
|
+
types.some((type) => type.columns.length > MAX_COLUMNS ||
|
|
25
|
+
type.indexes.length > MAX_INDEXES ||
|
|
26
|
+
type.indexes.reduce((acc, index) => acc + index.columns.length, 0) > MAX_INDEX_COLUMNS);
|
|
27
|
+
return (_jsxs("details", { className: "ins-context plan-type-schema", children: [_jsxs("summary", { children: [_jsx(TableProperties, { size: 13 }), view.title, _jsx(ChevronDown, { size: 13, className: "ins-context-chevron" })] }), _jsxs("div", { className: "plan-type-schema-body", children: [_jsx("p", { children: view.summary }), view.limitations.slice(0, MAX_LIMITATIONS).map((limitation, index) => (_jsx("p", { className: "muted", children: limitation }, index))), available && (_jsxs(_Fragment, { children: [schema.module && (_jsxs("dl", { children: [_jsx("dt", { children: t("ui.plan_type_schema.module") }), _jsx("dd", { children: _jsx("code", { children: qualified(schema.module) }) })] })), parameters.length > 0 && (_jsx(TableRegion, { label: t("ui.plan_type_schema.parameters"), children: _jsxs("table", { children: [_jsx("caption", { children: t("ui.plan_type_schema.parameters") }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: t("ui.plan_type_schema.parameter") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.table_type") })] }) }), _jsx("tbody", { children: parameters.map((parameter, position) => {
|
|
28
|
+
const matches = types.map((type, index) => ({ type, index })).filter(({ type }) => type.user_type_id === parameter.user_type_id);
|
|
29
|
+
const match = matches.length === 1 ? matches[0] : null;
|
|
30
|
+
return (_jsxs("tr", { children: [_jsx("td", { children: _jsx("code", { children: nativeText(parameter.name) }) }), _jsx("td", { children: match ? _jsx("a", { href: `#${id}-type-${match.index}`, children: qualified(match.type) }) : t("ui.common.unknown") })] }, `${parameter.parameter_id}:${position}`));
|
|
31
|
+
}) })] }) })), types.map((type, index) => (_jsx(TypeSchema, { type: type, id: `${id}-type-${index}` }, `${type.user_type_id}:${index}`)))] })), limited && _jsx("p", { className: "muted", children: t("ui.plan_type_schema.limited") })] })] }, `${schema.observed_at}:${schema.status}:${schema.module?.identity.object_id}`));
|
|
32
|
+
}
|
|
33
|
+
function TypeSchema({ type, id }) {
|
|
34
|
+
const columns = type.columns.slice(0, MAX_COLUMNS);
|
|
35
|
+
let remaining = MAX_INDEX_COLUMNS;
|
|
36
|
+
const indexes = type.indexes.slice(0, MAX_INDEXES).map((index) => {
|
|
37
|
+
const links = index.columns.slice(0, remaining);
|
|
38
|
+
remaining -= links.length;
|
|
39
|
+
return { index, links };
|
|
40
|
+
});
|
|
41
|
+
return (_jsxs("section", { className: "plan-type-schema-type", id: id, children: [_jsx("h4", { children: _jsx("code", { children: qualified(type) }) }), _jsxs("dl", { children: [_jsx("dt", { children: t("ui.plan_type_schema.memory_optimized") }), _jsx("dd", { children: yesNo(type.memory_optimized) })] }), _jsx(TableRegion, { label: t("ui.plan_type_schema.columns"), children: _jsxs("table", { className: "plan-type-schema-columns", children: [_jsx("caption", { children: t("ui.plan_type_schema.columns") }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: t("ui.plan_type_schema.column") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.data_type") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.length_bytes") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.precision") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.scale") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.nullable") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.collation") })] }) }), _jsx("tbody", { children: columns.map((column, index) => (_jsxs("tr", { children: [_jsx("td", { children: _jsx("code", { children: nativeText(column.name) }) }), _jsx("td", { children: _jsx("code", { children: qualified({ schema: column.type_schema, name: column.type_name }) }) }), _jsx("td", { children: digits(String(column.max_length)) }), _jsx("td", { children: digits(String(column.precision)) }), _jsx("td", { children: digits(String(column.scale)) }), _jsx("td", { children: yesNo(column.nullable) }), _jsx("td", { children: column.collation == null ? t("ui.common.unknown") : nativeText(column.collation) })] }, `${column.column_id}:${index}`))) })] }) }), indexes.length > 0 && (_jsx(TableRegion, { label: t("ui.plan_type_schema.indexes"), children: _jsxs("table", { className: "plan-type-schema-indexes", children: [_jsx("caption", { children: t("ui.plan_type_schema.indexes") }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: t("ui.plan_type_schema.index") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.native_kind") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.unique") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.column") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.key_ordinal") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.descending") }), _jsx("th", { scope: "col", children: t("ui.plan_type_schema.included") })] }) }), _jsx("tbody", { children: indexes.flatMap(({ index, links }, position) => (links.length ? links : [null]).map((column, ordinal) => (_jsxs("tr", { children: [ordinal === 0 && (_jsxs(_Fragment, { children: [_jsx("td", { rowSpan: Math.max(links.length, 1), children: _jsx("code", { children: nativeText(index.name) }) }), _jsx("td", { rowSpan: Math.max(links.length, 1), children: nativeText(index.native_type) }), _jsx("td", { rowSpan: Math.max(links.length, 1), children: yesNo(index.unique) })] })), column ? (_jsxs(_Fragment, { children: [_jsx("td", { children: _jsx("code", { children: nativeText(column.name) }) }), _jsx("td", { children: digits(String(column.key_ordinal)) }), _jsx("td", { children: yesNo(column.descending) }), _jsx("td", { children: yesNo(column.included) })] })) : (_jsx("td", { colSpan: 4, children: t("ui.common.unknown") }))] }, `${index.index_id}:${position}:${ordinal}`)))) })] }) }))] }));
|
|
42
|
+
}
|
|
43
|
+
function TableRegion({ label, children }) {
|
|
44
|
+
return (_jsx("div", { className: "plan-type-schema-scroll", role: "region", "aria-label": label, tabIndex: 0, children: children }));
|
|
45
|
+
}
|
|
46
|
+
function yesNo(value) {
|
|
47
|
+
return t(value ? "ui.common.yes" : "ui.common.no");
|
|
48
|
+
}
|
|
49
|
+
function qualified(value) {
|
|
50
|
+
return `${nativeText(value.schema)}.${nativeText(value.name)}`;
|
|
51
|
+
}
|
|
52
|
+
function nativeText(value) {
|
|
53
|
+
let text = "";
|
|
54
|
+
let characters = 0;
|
|
55
|
+
for (const character of value) {
|
|
56
|
+
if (characters === MAX_NATIVE_TEXT)
|
|
57
|
+
return `${text}…`;
|
|
58
|
+
text += character;
|
|
59
|
+
characters++;
|
|
60
|
+
}
|
|
61
|
+
return text;
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { planKindLabel, predicateLabel, shortPredicate } from "./host.js";
|
|
2
|
+
import type { PlanViewerTheme } from "./PlanViewer.js";
|
|
3
|
+
import type { Plan, PlanInsight, PlanNode, QueryStat } from "./types.js";
|
|
4
|
+
export { planKindLabel, predicateLabel, shortPredicate };
|
|
5
|
+
type Props = {
|
|
6
|
+
plan: Plan;
|
|
7
|
+
query?: QueryStat | null;
|
|
8
|
+
focus?: number | null;
|
|
9
|
+
compact?: boolean;
|
|
10
|
+
selectedId?: number | null;
|
|
11
|
+
onSelect?: (id: number) => void;
|
|
12
|
+
showHeader?: boolean;
|
|
13
|
+
showActualSummary?: boolean;
|
|
14
|
+
showProps?: boolean;
|
|
15
|
+
showInsights?: boolean;
|
|
16
|
+
theme?: PlanViewerTheme;
|
|
17
|
+
className?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function PlanView({ plan, query, focus, compact, selectedId, onSelect, showHeader, showActualSummary, showProps, showInsights, theme, className, }: Props): import("react").JSX.Element;
|
|
20
|
+
/** Alias of PlanView for ergonomic granular imports alongside PlanCanvas. */
|
|
21
|
+
export declare const PlanTree: typeof PlanView;
|
|
22
|
+
/** The operator detail panel; kept under this name for existing callers. */
|
|
23
|
+
export declare function NodeProps({ node, share, insights }: {
|
|
24
|
+
node: PlanNode;
|
|
25
|
+
share: number | null;
|
|
26
|
+
insights?: PlanInsight[];
|
|
27
|
+
}): import("react").JSX.Element;
|
package/pkg/PlanView.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown, ChevronRight, ChevronUp, Flame, Search, TriangleAlert, X } from "lucide-react";
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { ActualSummary } from "./ActualSummary.js";
|
|
5
|
+
import { canPlanEstimates, count, estRows, estRowsForRuns, findingNoShareReason, insightsByNode, misestimate, noShareReason, percent, planKindLabel, planShares, predicateLabel, rows as rowsText, shortPredicate, t, } from "./host.js";
|
|
6
|
+
import { NodeDetails } from "./NodeDetails.js";
|
|
7
|
+
import { OpIcon } from "./OpIcon.js";
|
|
8
|
+
export { planKindLabel, predicateLabel, shortPredicate };
|
|
9
|
+
const WARNING_LABEL = {
|
|
10
|
+
"implicit-conversion": () => t("ui.plan_view.warning.implicit_conversion"),
|
|
11
|
+
spill: () => t("ui.plan_view.warning.spill"),
|
|
12
|
+
"no-join-predicate": () => t("ui.plan_view.warning.no_join_predicate"),
|
|
13
|
+
"missing-statistics": () => t("ui.plan_view.warning.missing_statistics"),
|
|
14
|
+
"memory-grant": () => t("ui.plan_view.warning.memory_grant"),
|
|
15
|
+
misestimate: () => t("ui.plan_view.warning.misestimate"),
|
|
16
|
+
"residual-predicate": () => t("ui.plan_view.warning.residual_predicate"),
|
|
17
|
+
};
|
|
18
|
+
const warningLabel = (w) => WARNING_LABEL[w]?.() ?? w;
|
|
19
|
+
function walk(node, out = []) {
|
|
20
|
+
out.push(node);
|
|
21
|
+
node.children.forEach((c) => walk(c, out));
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function pathTo(node, id) {
|
|
25
|
+
if (node.id === id)
|
|
26
|
+
return [node.id];
|
|
27
|
+
for (const child of node.children) {
|
|
28
|
+
const path = pathTo(child, id);
|
|
29
|
+
if (path)
|
|
30
|
+
return [node.id, ...path];
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function heatVar(share) {
|
|
35
|
+
if (share >= 0.3)
|
|
36
|
+
return "var(--heat-4)";
|
|
37
|
+
if (share >= 0.15)
|
|
38
|
+
return "var(--heat-3)";
|
|
39
|
+
if (share >= 0.05)
|
|
40
|
+
return "var(--heat-2)";
|
|
41
|
+
if (share >= 0.01)
|
|
42
|
+
return "var(--heat-1)";
|
|
43
|
+
return "var(--heat-0)";
|
|
44
|
+
}
|
|
45
|
+
export function PlanView({ plan, query, focus, compact, selectedId, onSelect, showHeader = true, showActualSummary = true, showProps = true, showInsights = true, theme, className, }) {
|
|
46
|
+
const nodes = useMemo(() => walk(plan.root), [plan]);
|
|
47
|
+
const flagged = useMemo(() => (showInsights ? insightsByNode(plan) : new Map()), [plan, showInsights]);
|
|
48
|
+
const shares = useMemo(() => planShares(plan, query), [plan, query]);
|
|
49
|
+
const reason = (n) => (focus === n.id ? findingNoShareReason(plan, n, query) : noShareReason(plan, n, query));
|
|
50
|
+
const focused = nodes.find((n) => n.id === focus);
|
|
51
|
+
const note = shares.basis === "cost" && focused ? reason(focused) ?? shares.note : shares.note;
|
|
52
|
+
const shareOf = (n) => shares.stated.get(n.id) ?? null;
|
|
53
|
+
const hottest = shares.hottest;
|
|
54
|
+
const target = focus ?? hottest?.id ?? plan.root.id;
|
|
55
|
+
const hotPath = useMemo(() => new Set(pathTo(plan.root, target) ?? []), [plan.root, target]);
|
|
56
|
+
const [expanded, setExpanded] = useState(() => {
|
|
57
|
+
const open = new Set(hotPath);
|
|
58
|
+
nodes.forEach((n) => {
|
|
59
|
+
if ((shares.subtree.get(n.id) ?? 0) >= 0.05)
|
|
60
|
+
open.add(n.id);
|
|
61
|
+
});
|
|
62
|
+
return open;
|
|
63
|
+
});
|
|
64
|
+
const [selected, setSelected] = useState(selectedId ?? target);
|
|
65
|
+
const [searchText, setSearchText] = useState("");
|
|
66
|
+
const [matchCursor, setMatchCursor] = useState(0);
|
|
67
|
+
const trimmedSearch = searchText.trim().toLowerCase();
|
|
68
|
+
const matchedIds = useMemo(() => {
|
|
69
|
+
if (!trimmedSearch)
|
|
70
|
+
return [];
|
|
71
|
+
return nodes
|
|
72
|
+
.filter((n) => `${n.op} ${n.object ?? ""} ${n.index ?? ""} ${n.predicate ?? ""} ${n.seek_predicate ?? ""}`.toLowerCase().includes(trimmedSearch))
|
|
73
|
+
.map((n) => n.id);
|
|
74
|
+
}, [nodes, trimmedSearch]);
|
|
75
|
+
const matchedSet = useMemo(() => new Set(matchedIds), [matchedIds]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (matchedIds.length === 0)
|
|
78
|
+
return;
|
|
79
|
+
setMatchCursor(0);
|
|
80
|
+
setExpanded((prev) => {
|
|
81
|
+
const next = new Set(prev);
|
|
82
|
+
matchedIds.forEach((id) => (pathTo(plan.root, id) ?? []).forEach((anc) => next.add(anc)));
|
|
83
|
+
return next;
|
|
84
|
+
});
|
|
85
|
+
}, [matchedIds, plan.root]);
|
|
86
|
+
const selectedNode = nodes.find((n) => n.id === selected) ?? null;
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (selectedId == null)
|
|
89
|
+
return;
|
|
90
|
+
setSelected(selectedId);
|
|
91
|
+
const path = pathTo(plan.root, selectedId) ?? [];
|
|
92
|
+
setExpanded((prev) => new Set([...prev, ...path]));
|
|
93
|
+
}, [selectedId, plan.root]);
|
|
94
|
+
const hasActuals = nodes.some((n) => n.act_rows != null);
|
|
95
|
+
const weighed = canPlanEstimates(plan.engine) || hasActuals;
|
|
96
|
+
const toggle = (id) => setExpanded((prev) => {
|
|
97
|
+
const next = new Set(prev);
|
|
98
|
+
if (next.has(id))
|
|
99
|
+
next.delete(id);
|
|
100
|
+
else
|
|
101
|
+
next.add(id);
|
|
102
|
+
return next;
|
|
103
|
+
});
|
|
104
|
+
const stepMatch = (delta) => {
|
|
105
|
+
if (matchedIds.length === 0)
|
|
106
|
+
return;
|
|
107
|
+
const nextIdx = (matchCursor + delta + matchedIds.length) % matchedIds.length;
|
|
108
|
+
setMatchCursor(nextIdx);
|
|
109
|
+
const id = matchedIds[nextIdx];
|
|
110
|
+
if (id != null) {
|
|
111
|
+
setSelected(id);
|
|
112
|
+
onSelect?.(id);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const rows = [];
|
|
116
|
+
const visit = (node, depth) => {
|
|
117
|
+
rows.push({ node, depth });
|
|
118
|
+
if (expanded.has(node.id))
|
|
119
|
+
node.children.forEach((c) => visit(c, depth + 1));
|
|
120
|
+
};
|
|
121
|
+
visit(plan.root, 0);
|
|
122
|
+
return (_jsxs("div", { className: `culprit-pv plan ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [showHeader && (_jsxs("div", { className: "plan-head", children: [_jsx("span", { className: "tag", children: planKindLabel(plan) }), _jsxs("span", { children: [t("ui.common.plan_operators", { count: nodes.length }), weighed &&
|
|
123
|
+
` · ${plan.facts.estimated_cost_unavailable
|
|
124
|
+
? t("ui.common.plan_cost_unavailable")
|
|
125
|
+
: t("ui.common.plan_cost", { cost: (plan.total_cost || plan.root.subtree_cost).toFixed((plan.total_cost || plan.root.subtree_cost) < 10 ? 3 : 1) })}`] }), plan.warnings.length > 0 && (_jsxs("span", { className: "warn-chip", children: [_jsx(TriangleAlert, { size: 11 }), plan.warnings.map(warningLabel).join(", ")] })), _jsx("span", { className: "spacer" }), !compact && (_jsxs("div", { className: "search plan-search", children: [_jsx(Search, { size: 12 }), _jsx("input", { value: searchText, placeholder: t("ui.plan_diagram.search_placeholder"), onChange: (e) => setSearchText(e.target.value), onKeyDown: (e) => {
|
|
126
|
+
if (e.key === "Enter") {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
stepMatch(e.shiftKey ? -1 : 1);
|
|
129
|
+
}
|
|
130
|
+
else if (e.key === "Escape" && searchText) {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
setSearchText("");
|
|
133
|
+
}
|
|
134
|
+
} }), trimmedSearch && (_jsxs(_Fragment, { children: [_jsx("span", { className: "plan-search-count num", children: matchedIds.length > 0
|
|
135
|
+
? t("ui.plan_diagram.search_matches", { current: String(matchCursor + 1), total: String(matchedIds.length) })
|
|
136
|
+
: t("ui.plan_diagram.search_none") }), matchedIds.length > 1 && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "plan-search-btn", title: t("ui.plan_diagram.search_prev"), onClick: () => stepMatch(-1), children: _jsx(ChevronUp, { size: 12 }) }), _jsx("button", { type: "button", className: "plan-search-btn", title: t("ui.plan_diagram.search_next"), onClick: () => stepMatch(1), children: _jsx(ChevronDown, { size: 12 }) })] })), _jsx("button", { type: "button", className: "plan-search-btn", title: t("ui.plan_diagram.search_clear"), onClick: () => setSearchText(""), children: _jsx(X, { size: 12 }) })] }))] }))] })), showActualSummary && plan.kind === "actual" && _jsx(ActualSummary, { plan: plan, onPick: setSelected }), _jsxs("div", { className: "plan-cols", children: [_jsx("span", { children: t("ui.plan_view.operator") }), _jsx("span", { children: hasActuals ? t("ui.plan_view.rows_est_actual") : weighed ? t("ui.plan_view.est_rows") : "" }), _jsx("span", { children: shares.basis === "time" ? t("ui.plan_view.own_time") : weighed ? t("ui.plan_view.self_cost") : "" })] }), _jsx("div", { style: compact ? { maxHeight: 340, overflowY: "auto" } : undefined, children: rows.map(({ node, depth }) => {
|
|
137
|
+
const share = shareOf(node);
|
|
138
|
+
const mis = node.warnings.includes("misestimate") ? misestimate(plan, node) : null;
|
|
139
|
+
return (_jsxs("button", { type: "button", className: `pnode ${selected === node.id ? "sel" : ""} ${hotPath.has(node.id) ? "hot" : ""} ${matchedSet.has(node.id) ? "match" : ""}`, onClick: () => {
|
|
140
|
+
setSelected(node.id);
|
|
141
|
+
onSelect?.(node.id);
|
|
142
|
+
}, onDoubleClick: () => toggle(node.id), "aria-expanded": node.children.length > 0 ? expanded.has(node.id) : undefined, onKeyDown: (e) => {
|
|
143
|
+
const open = expanded.has(node.id);
|
|
144
|
+
if (node.children.length > 0 && ((e.key === "ArrowRight" && !open) || (e.key === "ArrowLeft" && open))) {
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
toggle(node.id);
|
|
147
|
+
}
|
|
148
|
+
}, children: [_jsxs("span", { className: "label", children: [_jsx("span", { className: "indent", style: { width: Math.min(depth, 12) * 12 } }), _jsx("span", { className: "twisty", "aria-hidden": true, onClick: (e) => {
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
toggle(node.id);
|
|
151
|
+
}, children: node.children.length > 0 ? expanded.has(node.id) ? _jsx(ChevronDown, { size: 14 }) : _jsx(ChevronRight, { size: 14 }) : null }), _jsxs("span", { className: "lines", children: [_jsxs("span", { className: "line1", children: [_jsx("span", { className: "op-icon", children: _jsx(OpIcon, { node: node, size: 13 }) }), node.id === hottest?.id && (share ?? 0) >= 0.05 && _jsx(Flame, { size: 13, color: "var(--heat-4)", className: "flame" }), _jsx("span", { className: "opname", children: node.op }), flagged.get(node.id)?.[0] && (_jsx("span", { className: `tree-flag ${flagged.get(node.id)[0].severity}`, title: flagged.get(node.id).map((i) => i.title).join("\n"), children: flagged.get(node.id).length })), node.object && (_jsxs("span", { className: "obj", children: [node.object, node.index ? ` · ${node.index}` : ""] }))] }), (node.warnings.length > 0 || node.predicate || node.seek_predicate) && (_jsxs("span", { className: "line2", children: [node.warnings.map((w) => (_jsx("span", { className: "warn-chip", children: warningLabel(w) }, w))), (node.seek_predicate || node.predicate) && (_jsx("span", { className: "pred", children: node.seek_predicate ? predicateLabel("seek", node.seek_predicate) : predicateLabel("filter", node.predicate ?? "") }))] }))] })] }), _jsx("span", { className: "rows", children: node.act_rows != null ? (_jsxs(_Fragment, { children: [rowsText(estRowsForRuns(plan, node)), " ", _jsx("span", { className: "arrow", children: "\u2192" }), " ", rowsText(node.act_rows), mis != null && (_jsx("span", { className: "mis", children: mis < 0 ? t("ui.plan_view.over", { times: count(Math.abs(mis)) }) : t("ui.plan_view.under", { times: count(Math.abs(mis)) }) }))] })) : (weighed && rowsText(estRows(plan, node))) }), _jsx("span", { className: "cost", children: weighed &&
|
|
152
|
+
(share != null ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "num", children: percent(share) }), _jsx("span", { className: "heat", children: _jsx("span", { style: { width: `${Math.max(2, Math.min(100, share * 100))}%`, background: heatVar(share) } }) })] })) : (_jsx("span", { className: "num muted", title: reason(node) ?? undefined, children: "-" }))) })] }, node.id));
|
|
153
|
+
}) }), weighed && note && _jsx("div", { className: "muted", style: { fontSize: 12, padding: "6px 10px" }, children: note }), selectedNode && showProps && (_jsx(NodeDetails, { plan: plan, estimates: weighed, actual: plan.kind === "actual", node: selectedNode, share: shareOf(selectedNode), subtreeShare: shares.statedSubtree.get(selectedNode.id) ?? null, noShare: shares.basis === "cost" ? reason(selectedNode) : null, insights: flagged.get(selectedNode.id) }))] }));
|
|
154
|
+
}
|
|
155
|
+
/** Alias of PlanView for ergonomic granular imports alongside PlanCanvas. */
|
|
156
|
+
export const PlanTree = PlanView;
|
|
157
|
+
/** The operator detail panel; kept under this name for existing callers. */
|
|
158
|
+
export function NodeProps({ node, share, insights }) {
|
|
159
|
+
return _jsx(NodeDetails, { node: node, share: share, insights: insights });
|
|
160
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type PlanLook } from "./PlanSurface.js";
|
|
3
|
+
import type { Plan, QueryStat } from "./types.js";
|
|
4
|
+
export type PlanViewerTheme = "light" | "dark" | "system";
|
|
5
|
+
export type PlanViewerProps = {
|
|
6
|
+
plan: Plan;
|
|
7
|
+
query?: QueryStat | null;
|
|
8
|
+
focus?: number | null;
|
|
9
|
+
/** Controlled view mode ("diagram" | "tree" | "operations"). */
|
|
10
|
+
look?: PlanLook;
|
|
11
|
+
/** Initial view mode when uncontrolled. Defaults to "diagram". */
|
|
12
|
+
defaultLook?: PlanLook;
|
|
13
|
+
onLookChange?: (look: PlanLook) => void;
|
|
14
|
+
/** Render the built-in header bar with engine/kind metadata and the Diagram · Tree · Operations switcher. Defaults to true. */
|
|
15
|
+
showToolbar?: boolean;
|
|
16
|
+
/** Show the parsed SQL statement above the plan when available. Defaults to true. */
|
|
17
|
+
showStatement?: boolean;
|
|
18
|
+
/** Optional title displayed in the toolbar. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Optional slot rendered at the end of the toolbar (for export/share buttons). */
|
|
21
|
+
toolbarActions?: ReactNode;
|
|
22
|
+
/** Optional explicit color theme ("light" | "dark" | "system"). */
|
|
23
|
+
theme?: PlanViewerTheme;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Drop-in execution plan viewer: bottleneck insights, measured-run summary, cost/time strip,
|
|
28
|
+
* interactive Diagram / Tree / Operations views, and operator property inspector.
|
|
29
|
+
*/
|
|
30
|
+
export declare function PlanViewer({ plan, query, focus, look: controlledLook, defaultLook, onLookChange, showToolbar, showStatement, title, toolbarActions, theme, className, }: PlanViewerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { planEngineName, planKindLabel } from "./host.js";
|
|
4
|
+
import { LookToggle, PlanSurface } from "./PlanSurface.js";
|
|
5
|
+
import { Sql } from "./Sql.js";
|
|
6
|
+
/**
|
|
7
|
+
* Drop-in execution plan viewer: bottleneck insights, measured-run summary, cost/time strip,
|
|
8
|
+
* interactive Diagram / Tree / Operations views, and operator property inspector.
|
|
9
|
+
*/
|
|
10
|
+
export function PlanViewer({ plan, query, focus, look: controlledLook, defaultLook = "diagram", onLookChange, showToolbar = true, showStatement = true, title, toolbarActions, theme, className, }) {
|
|
11
|
+
const [internalLook, setInternalLook] = useState(defaultLook);
|
|
12
|
+
const [sqlOpen, setSqlOpen] = useState(false);
|
|
13
|
+
const look = controlledLook ?? internalLook;
|
|
14
|
+
const handleLookChange = (next) => {
|
|
15
|
+
setInternalLook(next);
|
|
16
|
+
onLookChange?.(next);
|
|
17
|
+
};
|
|
18
|
+
return (_jsxs("div", { className: `culprit-pv pv-root ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [showToolbar && (_jsxs("div", { className: "pv-toolbar", children: [_jsxs("div", { className: "pv-meta", children: [title && _jsx("strong", { className: "pv-title", children: title }), _jsx("span", { className: "tag", children: planEngineName(plan) }), _jsx("span", { className: "muted", children: planKindLabel(plan) })] }), _jsx("span", { className: "spacer" }), _jsx(LookToggle, { look: look, onChange: handleLookChange, hasRaw: Boolean(plan.raw) }), toolbarActions] })), showStatement && plan.statement && (_jsx("div", { className: `plans-sql ${sqlOpen ? "open" : ""}`, onClick: () => setSqlOpen((v) => !v), title: sqlOpen ? "Click to collapse SQL" : "Click to expand SQL", children: _jsx(Sql, { text: plan.statement }) })), _jsx(PlanSurface, { plan: plan, query: query, focus: focus, look: look })] }));
|
|
19
|
+
}
|
package/pkg/Prose.d.ts
ADDED
package/pkg/Prose.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** Plain text with `inline code` spans, as the checks write it. Never renders HTML from the database. */
|
|
3
|
+
export function Prose({ text }) {
|
|
4
|
+
const parts = text.split("`");
|
|
5
|
+
return (_jsx(_Fragment, { children: parts.map((part, i) => i % 2 === 1 ? (_jsx("code", { className: "inline-code", children: part }, i)) : (part)) }));
|
|
6
|
+
}
|
package/pkg/Sql.d.ts
ADDED
package/pkg/Sql.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { prettySql, tokenizeSql } from "./host.js";
|
|
4
|
+
export function Sql({ text, pretty = true, className }) {
|
|
5
|
+
const tokens = useMemo(() => tokenizeSql(pretty ? prettySql(text) : text), [text, pretty]);
|
|
6
|
+
return (_jsx("pre", { dir: "ltr", className: `sql ${className ?? ""}`, children: tokens.map((tok, i) => (tok.kind === "t" ? tok.text : _jsx("span", { className: tok.kind, children: tok.text }, i))) }));
|
|
7
|
+
}
|