@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,534 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronDown, ChevronUp, Flame, Map as MapIcon, Maximize2, Minus, Plus, Scan, Search, TriangleAlert, X } from "lucide-react";
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { ActualSummary } from "./ActualSummary.js";
|
|
5
|
+
import { allNodes, costBasis as basis, canPlanEstimates, cost, duration, estRows, estRowsForRuns, findingNoShareReason, insightsByNode, isWrapper, misestimate, noShareReason, operatorView, percent, planKindLabel, planShares, predicateLabel, rows, rowsOut, serverName, t, uncostedSteps, } from "./host.js";
|
|
6
|
+
import { NodeDetails } from "./NodeDetails.js";
|
|
7
|
+
import { OpIcon } from "./OpIcon.js";
|
|
8
|
+
const CARD_W = 196;
|
|
9
|
+
export function compactOp(op) {
|
|
10
|
+
return op
|
|
11
|
+
.replace(/^(Clustered|Nonclustered|Columnstore|Clustered Columnstore) Index (?=\S)/i, "$1 ")
|
|
12
|
+
.replace(/^(Unique|Subquery) index lookup$/i, "$1 lookup")
|
|
13
|
+
.replace(/^Table-valued function$/i, "Table function");
|
|
14
|
+
}
|
|
15
|
+
const CARD_H = 74;
|
|
16
|
+
const GAP_X = 28;
|
|
17
|
+
const GAP_Y = 62;
|
|
18
|
+
const PAD = 26;
|
|
19
|
+
const CHEAP_SHARE = 0.005;
|
|
20
|
+
const MIN_FIT = 0.45;
|
|
21
|
+
const MIN_ZOOM = 0.25;
|
|
22
|
+
const MAX_ZOOM = 1.8;
|
|
23
|
+
const MARK_LABEL = {
|
|
24
|
+
changed: () => t("ui.plan_diagram.mark_changed"),
|
|
25
|
+
added: () => t("ui.plan_diagram.mark_only_here"),
|
|
26
|
+
removed: () => t("ui.plan_diagram.mark_only_here"),
|
|
27
|
+
};
|
|
28
|
+
export const costBasis = basis;
|
|
29
|
+
function subtreeSize(n) {
|
|
30
|
+
return 1 + n.children.reduce((s, c) => s + subtreeSize(c), 0);
|
|
31
|
+
}
|
|
32
|
+
function heat(share) {
|
|
33
|
+
if (share >= 0.3)
|
|
34
|
+
return "var(--heat-4)";
|
|
35
|
+
if (share >= 0.15)
|
|
36
|
+
return "var(--heat-3)";
|
|
37
|
+
if (share >= 0.05)
|
|
38
|
+
return "var(--heat-2)";
|
|
39
|
+
if (share >= 0.01)
|
|
40
|
+
return "var(--heat-1)";
|
|
41
|
+
return "transparent";
|
|
42
|
+
}
|
|
43
|
+
function pathTo(node, id) {
|
|
44
|
+
const walk = (n) => {
|
|
45
|
+
if (n.id === id)
|
|
46
|
+
return [n.id];
|
|
47
|
+
for (const c of n.children) {
|
|
48
|
+
const p = walk(c);
|
|
49
|
+
if (p)
|
|
50
|
+
return [n.id, ...p];
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
};
|
|
54
|
+
return new Set(walk(node) ?? []);
|
|
55
|
+
}
|
|
56
|
+
function drawn(n, total, keep) {
|
|
57
|
+
const via = [];
|
|
58
|
+
let cur = n;
|
|
59
|
+
while (isWrapper(cur, total) && !keep.has(cur.id) && cur.children[0]) {
|
|
60
|
+
via.push(cur.op);
|
|
61
|
+
cur = cur.children[0];
|
|
62
|
+
}
|
|
63
|
+
return { node: cur, via };
|
|
64
|
+
}
|
|
65
|
+
function layout(root, total, expanded, keep, weighed, subtreeShare) {
|
|
66
|
+
const boxes = [];
|
|
67
|
+
const folds = [];
|
|
68
|
+
const parentOf = new Map();
|
|
69
|
+
let slot = 0;
|
|
70
|
+
const place = (n, via, depth) => {
|
|
71
|
+
const kids = n.children.map((c) => drawn(c, total, keep));
|
|
72
|
+
const visible = kids.filter((k) => !weighed || expanded.has(k.node.id) || keep.has(k.node.id) || k.node.subtree_cost / total >= CHEAP_SHARE);
|
|
73
|
+
const hidden = kids.filter((k) => !visible.includes(k));
|
|
74
|
+
const xs = visible.map((k) => {
|
|
75
|
+
parentOf.set(k.node.id, n.id);
|
|
76
|
+
return place(k.node, k.via, depth + 1);
|
|
77
|
+
});
|
|
78
|
+
if (hidden.length > 0) {
|
|
79
|
+
const fx = slot++;
|
|
80
|
+
const shares = hidden.map((k) => subtreeShare(k.node));
|
|
81
|
+
folds.push({
|
|
82
|
+
id: `fold-${n.id}`,
|
|
83
|
+
parent: n.id,
|
|
84
|
+
count: hidden.reduce((s, k) => s + subtreeSize(k.node) + k.via.length, 0),
|
|
85
|
+
share: shares.every((v) => v != null) ? shares.reduce((s, v) => s + (v ?? 0), 0) : null,
|
|
86
|
+
x: fx,
|
|
87
|
+
y: depth + 1,
|
|
88
|
+
});
|
|
89
|
+
xs.push(fx);
|
|
90
|
+
}
|
|
91
|
+
const x = xs.length ? (Math.min(...xs) + Math.max(...xs)) / 2 : slot++;
|
|
92
|
+
boxes.push({ node: n, x, y: depth, via });
|
|
93
|
+
return x;
|
|
94
|
+
};
|
|
95
|
+
const top = drawn(root, total, keep);
|
|
96
|
+
place(top.node, top.via, 0);
|
|
97
|
+
const maxX = Math.max(0, ...boxes.map((b) => b.x), ...folds.map((f) => f.x));
|
|
98
|
+
const maxY = Math.max(0, ...boxes.map((b) => b.y), ...folds.map((f) => f.y));
|
|
99
|
+
return {
|
|
100
|
+
boxes,
|
|
101
|
+
folds,
|
|
102
|
+
parentOf,
|
|
103
|
+
rootVia: top.via,
|
|
104
|
+
width: PAD * 2 + (maxX + 1) * CARD_W + maxX * GAP_X,
|
|
105
|
+
height: PAD * 2 + 24 + (maxY + 1) * CARD_H + maxY * GAP_Y,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const px = (x) => PAD + x * (CARD_W + GAP_X);
|
|
109
|
+
const py = (y) => PAD + 24 + y * (CARD_H + GAP_Y);
|
|
110
|
+
function nodeMatchesQuery(n, q) {
|
|
111
|
+
const hay = `${n.op} ${n.object ?? ""} ${n.index ?? ""} ${n.detail ?? ""} ${n.predicate ?? ""} ${n.seek_predicate ?? ""}`.toLowerCase();
|
|
112
|
+
return hay.includes(q);
|
|
113
|
+
}
|
|
114
|
+
function nodeReadsValue(n) {
|
|
115
|
+
return n.runtime?.logical_reads ?? n.rows_read ?? null;
|
|
116
|
+
}
|
|
117
|
+
export function CostStrip({ plan, query, focus, onPick }) {
|
|
118
|
+
const shares = useMemo(() => planShares(plan, query), [plan, query]);
|
|
119
|
+
const focused = allNodes(plan.root).find((n) => n.id === focus);
|
|
120
|
+
const note = shares.basis === "cost" && focused ? findingNoShareReason(plan, focused, query) ?? shares.note : shares.note;
|
|
121
|
+
if (shares.basis !== "time" && !canPlanEstimates(plan.engine)) {
|
|
122
|
+
return (_jsx("div", { className: "cost-strip", children: _jsx("div", { className: "eyebrow", children: t("ui.plan_diagram.access_path_only", { engine: serverName(plan.engine) }) }) }));
|
|
123
|
+
}
|
|
124
|
+
const own = (n) => shares.stated.get(n.id) ?? 0;
|
|
125
|
+
const top = allNodes(plan.root)
|
|
126
|
+
.filter((n) => own(n) > 0)
|
|
127
|
+
.sort((a, b) => own(b) - own(a))
|
|
128
|
+
.slice(0, 4);
|
|
129
|
+
if (top.length === 0 && note) {
|
|
130
|
+
return (_jsx("div", { className: "cost-strip", children: _jsx("div", { className: "eyebrow", children: t("ui.plan_diagram.cost_goes_note", { note }) }) }));
|
|
131
|
+
}
|
|
132
|
+
const rest = Math.max(0, 1 - top.reduce((s, n) => s + own(n), 0));
|
|
133
|
+
return (_jsxs("div", { className: "cost-strip", children: [_jsx("div", { className: "eyebrow", children: shares.basis === "time" ? t("ui.plan_diagram.time_went", { time: duration(shares.total) }) : t("ui.plan_diagram.cost_goes") }), _jsxs("div", { className: "cost-bar", children: [top.map((n) => (_jsx("button", { type: "button", className: n.id === shares.hottest?.id ? "hottest" : "", style: { flex: own(n), background: heat(own(n)) === "transparent" ? "var(--sunken)" : heat(own(n)) }, title: `${n.op} ${percent(own(n))}`, onClick: () => onPick(n.id) }, n.id))), rest > 0.005 && _jsx("span", { style: { flex: rest, background: "var(--sunken)" }, title: t("ui.plan_diagram.everything_else", { share: percent(rest) }) })] }), _jsx("div", { className: "cost-legend", children: top.map((n) => (_jsxs("button", { type: "button", onClick: () => onPick(n.id), children: [_jsx(OpIcon, { node: n, size: 12 }), _jsx("b", { children: percent(own(n)) }), " ", n.op, n.object && _jsxs("span", { className: "mono muted", children: [" ", n.object.split(".").pop()] }), n.kind === "parallelism" && _jsxs("span", { className: "muted", children: [" \u00B7 ", t("ui.plan_diagram.passing_rows")] })] }, n.id))) }), shares.note && _jsx("div", { className: "muted", style: { fontSize: 12, marginTop: 4 }, children: shares.note })] }));
|
|
134
|
+
}
|
|
135
|
+
export function PlanDiagram(props) {
|
|
136
|
+
const { plan, query, focus, marks, selectedId, onSelect, initialZoom, badge, bare, tints, onZoomChange, overlay, kindLabel, showHeader = !bare, showActualSummary = !bare, showCostStrip = !bare, showInsights = true, showControls = true, height: customHeight, theme, className, } = props;
|
|
137
|
+
const reason = (n) => (focus === n.id ? findingNoShareReason(plan, n, query) : noShareReason(plan, n, query));
|
|
138
|
+
const total = basis(plan);
|
|
139
|
+
const shares = useMemo(() => planShares(plan, query), [plan, query]);
|
|
140
|
+
const shareOf = (n) => shares.stated.get(n.id) ?? null;
|
|
141
|
+
const planCost = plan.total_cost || plan.root.subtree_cost;
|
|
142
|
+
const estimates = canPlanEstimates(plan.engine) || shares.basis === "time";
|
|
143
|
+
const nodes = useMemo(() => allNodes(plan.root), [plan]);
|
|
144
|
+
const flagged = useMemo(() => (showInsights ? insightsByNode(plan) : new Map()), [plan, showInsights]);
|
|
145
|
+
const hottest = shares.hottest;
|
|
146
|
+
const target = selectedId ?? focus ?? hottest?.id ?? plan.root.id;
|
|
147
|
+
// Available metric lenses for coloring cards
|
|
148
|
+
const availableLenses = useMemo(() => {
|
|
149
|
+
const out = [];
|
|
150
|
+
if (shares.basis === "time")
|
|
151
|
+
out.push("time");
|
|
152
|
+
if (canPlanEstimates(plan.engine) && !plan.facts.estimated_cost_unavailable)
|
|
153
|
+
out.push("cost");
|
|
154
|
+
if (nodes.some((n) => (rowsOut(plan, n) ?? 0) > 0))
|
|
155
|
+
out.push("rows");
|
|
156
|
+
if (nodes.some((n) => (nodeReadsValue(n) ?? 0) > 0))
|
|
157
|
+
out.push("reads");
|
|
158
|
+
return out;
|
|
159
|
+
}, [plan, nodes, shares.basis]);
|
|
160
|
+
const fallbackLens = props.defaultLens && availableLenses.includes(props.defaultLens)
|
|
161
|
+
? props.defaultLens
|
|
162
|
+
: shares.basis === "time"
|
|
163
|
+
? "time"
|
|
164
|
+
: availableLenses[0] ?? "cost";
|
|
165
|
+
const [ownLens, setOwnLens] = useState(fallbackLens);
|
|
166
|
+
const lens = props.lens && availableLenses.includes(props.lens) ? props.lens : ownLens;
|
|
167
|
+
const setLens = setOwnLens;
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!props.lens && !availableLenses.includes(ownLens))
|
|
170
|
+
setOwnLens(fallbackLens);
|
|
171
|
+
}, [availableLenses, ownLens, fallbackLens, props.lens]);
|
|
172
|
+
// Search & match navigation across the diagram
|
|
173
|
+
const [searchText, setSearchText] = useState("");
|
|
174
|
+
const [matchCursor, setMatchCursor] = useState(0);
|
|
175
|
+
const trimmedSearch = searchText.trim().toLowerCase();
|
|
176
|
+
const matchedIds = useMemo(() => {
|
|
177
|
+
if (!trimmedSearch)
|
|
178
|
+
return [];
|
|
179
|
+
return nodes.filter((n) => nodeMatchesQuery(n, trimmedSearch)).map((n) => n.id);
|
|
180
|
+
}, [nodes, trimmedSearch]);
|
|
181
|
+
const matchedSet = useMemo(() => new Set(matchedIds), [matchedIds]);
|
|
182
|
+
const keep = useMemo(() => new Set([...(marks?.keys() ?? []), ...flagged.keys(), ...uncostedSteps(plan).map((n) => n.id), ...matchedIds]), [marks, flagged, plan, matchedIds]);
|
|
183
|
+
const [expanded, setExpanded] = useState(() => {
|
|
184
|
+
const open = pathTo(plan.root, target);
|
|
185
|
+
keep.forEach((id) => pathTo(plan.root, id).forEach((n) => open.add(n)));
|
|
186
|
+
return open;
|
|
187
|
+
});
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (matchedIds.length === 0)
|
|
190
|
+
return;
|
|
191
|
+
setMatchCursor(0);
|
|
192
|
+
setExpanded((prev) => {
|
|
193
|
+
const next = new Set(prev);
|
|
194
|
+
matchedIds.forEach((id) => pathTo(plan.root, id).forEach((anc) => next.add(anc)));
|
|
195
|
+
return next;
|
|
196
|
+
});
|
|
197
|
+
}, [matchedIds, plan.root]);
|
|
198
|
+
const [selected, setSelected] = useState(target);
|
|
199
|
+
const [ownZoom, setOwnZoom] = useState(initialZoom ?? 1);
|
|
200
|
+
const zoom = props.zoom ?? ownZoom;
|
|
201
|
+
const zoomRef = useRef(zoom);
|
|
202
|
+
zoomRef.current = zoom;
|
|
203
|
+
const setZoom = useCallback((next) => {
|
|
204
|
+
const value = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, typeof next === "function" ? next(zoomRef.current) : next));
|
|
205
|
+
setOwnZoom(value);
|
|
206
|
+
onZoomChange?.(value);
|
|
207
|
+
}, [onZoomChange]);
|
|
208
|
+
const [fitted, setFitted] = useState(initialZoom != null || props.zoom != null);
|
|
209
|
+
const scroller = useRef(null);
|
|
210
|
+
const [isPanning, setIsPanning] = useState(false);
|
|
211
|
+
const panState = useRef({
|
|
212
|
+
active: false,
|
|
213
|
+
moved: false,
|
|
214
|
+
startX: 0,
|
|
215
|
+
startY: 0,
|
|
216
|
+
scrollLeft: 0,
|
|
217
|
+
scrollTop: 0,
|
|
218
|
+
});
|
|
219
|
+
const suppressClick = useRef(false);
|
|
220
|
+
const hot = useMemo(() => pathTo(plan.root, target), [plan.root, target]);
|
|
221
|
+
const { boxes, folds, parentOf, rootVia, width, height } = useMemo(() => layout(plan.root, total, expanded, keep, estimates, (n) => shares.statedSubtree.get(n.id) ?? null), [plan.root, total, expanded, keep, estimates, shares]);
|
|
222
|
+
const [minimapPref, setMinimapPref] = useState(null);
|
|
223
|
+
const autoMinimap = props.showMinimap ?? (!bare && boxes.length >= 6);
|
|
224
|
+
const showMinimap = minimapPref ?? autoMinimap;
|
|
225
|
+
const [viewport, setViewport] = useState({ left: 0, top: 0, clientW: 0, clientH: 0 });
|
|
226
|
+
const byId = new Map(boxes.map((b) => [b.node.id, b]));
|
|
227
|
+
const maxRows = Math.max(1, ...nodes.map((node) => rowsOut(plan, node) ?? 0));
|
|
228
|
+
const maxReads = Math.max(1, ...nodes.map((node) => nodeReadsValue(node) ?? 0));
|
|
229
|
+
const stroke = (r) => 1.5 + 4.5 * (Math.log10(r + 1) / Math.log10(maxRows + 1));
|
|
230
|
+
const selectedNode = nodes.find((n) => n.id === selected) ?? null;
|
|
231
|
+
// Lens metric projection per card
|
|
232
|
+
const lensValue = useCallback((n) => {
|
|
233
|
+
if (lens === "time") {
|
|
234
|
+
const s = shares.stated.get(n.id) ?? null;
|
|
235
|
+
return { ratio: s, text: s != null ? percent(s) : null };
|
|
236
|
+
}
|
|
237
|
+
if (lens === "cost") {
|
|
238
|
+
const s = operatorView(plan, n)?.cost_share ?? (total > 0 ? n.self_cost / total : null);
|
|
239
|
+
return { ratio: s, text: s != null ? percent(s) : null };
|
|
240
|
+
}
|
|
241
|
+
if (lens === "rows") {
|
|
242
|
+
const r = rowsOut(plan, n);
|
|
243
|
+
return { ratio: r != null ? r / maxRows : null, text: r != null ? rows(r) : null };
|
|
244
|
+
}
|
|
245
|
+
const rd = nodeReadsValue(n);
|
|
246
|
+
return { ratio: rd != null ? rd / maxReads : null, text: rd != null ? rows(rd) : null };
|
|
247
|
+
}, [lens, shares.stated, plan, total, maxRows, maxReads]);
|
|
248
|
+
const syncViewport = useCallback(() => {
|
|
249
|
+
const el = scroller.current;
|
|
250
|
+
if (!el)
|
|
251
|
+
return;
|
|
252
|
+
setViewport({ left: el.scrollLeft, top: el.scrollTop, clientW: el.clientWidth, clientH: el.clientHeight });
|
|
253
|
+
}, []);
|
|
254
|
+
const fit = useCallback(() => {
|
|
255
|
+
const box = scroller.current?.getBoundingClientRect();
|
|
256
|
+
if (!box || box.width === 0)
|
|
257
|
+
return;
|
|
258
|
+
setZoom(Math.max(MIN_FIT, Math.min(1, (box.width - 8) / width)));
|
|
259
|
+
}, [width, setZoom]);
|
|
260
|
+
useLayoutEffect(() => {
|
|
261
|
+
if (fitted)
|
|
262
|
+
return;
|
|
263
|
+
fit();
|
|
264
|
+
setFitted(true);
|
|
265
|
+
}, [fit, fitted]);
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
syncViewport();
|
|
268
|
+
const el = scroller.current;
|
|
269
|
+
if (!el)
|
|
270
|
+
return;
|
|
271
|
+
el.addEventListener("scroll", syncViewport, { passive: true });
|
|
272
|
+
const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(syncViewport) : null;
|
|
273
|
+
ro?.observe(el);
|
|
274
|
+
return () => {
|
|
275
|
+
el.removeEventListener("scroll", syncViewport);
|
|
276
|
+
ro?.disconnect();
|
|
277
|
+
};
|
|
278
|
+
}, [syncViewport, zoom, width, height]);
|
|
279
|
+
// Ctrl/Cmd + wheel / trackpad pinch zoom anchored at cursor
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
const el = scroller.current;
|
|
282
|
+
if (!el)
|
|
283
|
+
return;
|
|
284
|
+
const onWheel = (e) => {
|
|
285
|
+
if (!e.ctrlKey && !e.metaKey)
|
|
286
|
+
return;
|
|
287
|
+
e.preventDefault();
|
|
288
|
+
const prevZoom = zoomRef.current;
|
|
289
|
+
const factor = Math.exp(-e.deltaY * 0.0025);
|
|
290
|
+
const nextZoom = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, +(prevZoom * factor).toFixed(3)));
|
|
291
|
+
if (nextZoom === prevZoom)
|
|
292
|
+
return;
|
|
293
|
+
const rect = el.getBoundingClientRect();
|
|
294
|
+
const cursorX = e.clientX - rect.left;
|
|
295
|
+
const cursorY = e.clientY - rect.top;
|
|
296
|
+
const worldX = (el.scrollLeft + cursorX) / prevZoom;
|
|
297
|
+
const worldY = (el.scrollTop + cursorY) / prevZoom;
|
|
298
|
+
setZoom(nextZoom);
|
|
299
|
+
requestAnimationFrame(() => {
|
|
300
|
+
el.scrollLeft = Math.max(0, worldX * nextZoom - cursorX);
|
|
301
|
+
el.scrollTop = Math.max(0, worldY * nextZoom - cursorY);
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
305
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
306
|
+
}, [setZoom]);
|
|
307
|
+
// Compatible across React 18 and React 19 (replaces React 19.2-only useEffectEvent).
|
|
308
|
+
const followSelectionRef = useRef(() => { });
|
|
309
|
+
followSelectionRef.current = (id) => {
|
|
310
|
+
if (!nodes.some((n) => n.id === id))
|
|
311
|
+
return;
|
|
312
|
+
const node = nodes.find((n) => n.id === id);
|
|
313
|
+
const visibleId = byId.has(id) || !node ? id : drawn(node, total, keep).node.id;
|
|
314
|
+
setSelected(visibleId);
|
|
315
|
+
setExpanded((prev) => new Set([...prev, ...pathTo(plan.root, visibleId)]));
|
|
316
|
+
};
|
|
317
|
+
useEffect(() => {
|
|
318
|
+
if (selectedId != null)
|
|
319
|
+
followSelectionRef.current(selectedId);
|
|
320
|
+
}, [selectedId]);
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
const canvas = scroller.current;
|
|
323
|
+
const el = canvas?.querySelector(`[data-node="${selected}"]`);
|
|
324
|
+
if (!canvas || !el)
|
|
325
|
+
return;
|
|
326
|
+
const c = canvas.getBoundingClientRect();
|
|
327
|
+
const e = el.getBoundingClientRect();
|
|
328
|
+
if (e.top < c.top || e.bottom > c.bottom)
|
|
329
|
+
canvas.scrollTop += e.top - c.top - (c.height - e.height) / 2;
|
|
330
|
+
if (e.left < c.left || e.right > c.right)
|
|
331
|
+
canvas.scrollLeft += e.left - c.left - (c.width - e.width) / 2;
|
|
332
|
+
}, [selected, zoom]);
|
|
333
|
+
const edges = [];
|
|
334
|
+
boxes.forEach((b) => {
|
|
335
|
+
const parent = parentOf.get(b.node.id);
|
|
336
|
+
const to = parent != null ? byId.get(parent) : undefined;
|
|
337
|
+
if (to) {
|
|
338
|
+
edges.push({
|
|
339
|
+
from: b,
|
|
340
|
+
to,
|
|
341
|
+
rows: rowsOut(plan, b.node) ?? 0,
|
|
342
|
+
hot: hot.has(b.node.id) && hot.has(to.node.id),
|
|
343
|
+
key: `${to.node.id}-${b.node.id}`,
|
|
344
|
+
via: b.via,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
folds.forEach((f) => {
|
|
349
|
+
const parent = byId.get(f.parent);
|
|
350
|
+
if (parent)
|
|
351
|
+
edges.push({ from: f, to: parent, rows: 0, hot: false, key: f.id, via: [] });
|
|
352
|
+
});
|
|
353
|
+
const select = (id) => {
|
|
354
|
+
setSelected(id);
|
|
355
|
+
onSelect?.(id);
|
|
356
|
+
};
|
|
357
|
+
const stepMatch = (delta) => {
|
|
358
|
+
if (matchedIds.length === 0)
|
|
359
|
+
return;
|
|
360
|
+
const nextIdx = (matchCursor + delta + matchedIds.length) % matchedIds.length;
|
|
361
|
+
setMatchCursor(nextIdx);
|
|
362
|
+
const id = matchedIds[nextIdx];
|
|
363
|
+
if (id != null)
|
|
364
|
+
select(id);
|
|
365
|
+
};
|
|
366
|
+
const handlePointerDown = (e) => {
|
|
367
|
+
if (e.button !== 0 || !scroller.current)
|
|
368
|
+
return;
|
|
369
|
+
panState.current = {
|
|
370
|
+
active: true,
|
|
371
|
+
moved: false,
|
|
372
|
+
startX: e.clientX,
|
|
373
|
+
startY: e.clientY,
|
|
374
|
+
scrollLeft: scroller.current.scrollLeft,
|
|
375
|
+
scrollTop: scroller.current.scrollTop,
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
const handlePointerMove = (e) => {
|
|
379
|
+
const st = panState.current;
|
|
380
|
+
const el = scroller.current;
|
|
381
|
+
if (!st.active || !el)
|
|
382
|
+
return;
|
|
383
|
+
const dx = e.clientX - st.startX;
|
|
384
|
+
const dy = e.clientY - st.startY;
|
|
385
|
+
if (!st.moved && Math.hypot(dx, dy) > 5) {
|
|
386
|
+
st.moved = true;
|
|
387
|
+
suppressClick.current = true;
|
|
388
|
+
setIsPanning(true);
|
|
389
|
+
}
|
|
390
|
+
if (st.moved) {
|
|
391
|
+
el.scrollLeft = st.scrollLeft - dx;
|
|
392
|
+
el.scrollTop = st.scrollTop - dy;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const endPan = () => {
|
|
396
|
+
if (!panState.current.active)
|
|
397
|
+
return;
|
|
398
|
+
panState.current.active = false;
|
|
399
|
+
setIsPanning(false);
|
|
400
|
+
if (suppressClick.current) {
|
|
401
|
+
setTimeout(() => {
|
|
402
|
+
suppressClick.current = false;
|
|
403
|
+
}, 0);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
const lensLabel = (l) => {
|
|
407
|
+
switch (l) {
|
|
408
|
+
case "time":
|
|
409
|
+
return t("ui.plan_diagram.lens.time");
|
|
410
|
+
case "cost":
|
|
411
|
+
return t("ui.plan_diagram.lens.cost");
|
|
412
|
+
case "rows":
|
|
413
|
+
return t("ui.plan_diagram.lens.rows");
|
|
414
|
+
case "reads":
|
|
415
|
+
return t("ui.plan_diagram.lens.reads");
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
// Minimap geometry
|
|
419
|
+
const mmMaxW = 152;
|
|
420
|
+
const mmMaxH = 104;
|
|
421
|
+
const mmScale = Math.min(mmMaxW / Math.max(1, width), mmMaxH / Math.max(1, height));
|
|
422
|
+
const mmW = Math.max(64, Math.round(width * mmScale));
|
|
423
|
+
const mmH = Math.max(44, Math.round(height * mmScale));
|
|
424
|
+
const panFromMinimap = (e) => {
|
|
425
|
+
const el = scroller.current;
|
|
426
|
+
if (!el)
|
|
427
|
+
return;
|
|
428
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
429
|
+
const worldX = (e.clientX - rect.left) / mmScale;
|
|
430
|
+
const worldY = (e.clientY - rect.top) / mmScale;
|
|
431
|
+
el.scrollLeft = Math.max(0, worldX * zoom - el.clientWidth / 2);
|
|
432
|
+
el.scrollTop = Math.max(0, worldY * zoom - el.clientHeight / 2);
|
|
433
|
+
};
|
|
434
|
+
const scrollStyle = customHeight != null
|
|
435
|
+
? { height: typeof customHeight === "number" ? `${customHeight}px` : customHeight, maxHeight: "none" }
|
|
436
|
+
: undefined;
|
|
437
|
+
return (_jsxs("div", { className: `culprit-pv plan ${bare ? "bare" : ""} ${customHeight != null ? "has-height" : ""} ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [showHeader && (_jsxs("div", { className: "plan-head", children: [badge && _jsx("span", { className: "side-badge", children: badge }), _jsx("span", { className: "tag", children: kindLabel ?? planKindLabel(plan) }), _jsxs("span", { children: [t("ui.common.plan_operators", { count: nodes.length }), estimates && ` · ${plan.facts.estimated_cost_unavailable ? t("ui.common.plan_cost_unavailable") : t("ui.common.plan_cost", { cost: cost(planCost) })}`] }), plan.warnings.length > 0 && (_jsxs("span", { className: "warn-chip", children: [_jsx(TriangleAlert, { size: 11 }), " ", t("ui.plan_diagram.plan_warnings", { count: plan.warnings.length })] })), _jsx("span", { className: "spacer" }), availableLenses.length > 1 && (_jsx("span", { className: "seg plan-lens", role: "group", "aria-label": t("ui.plan_diagram.lens.label"), children: availableLenses.map((item) => (_jsx("button", { type: "button", className: lens === item ? "on" : "", onClick: () => setLens(item), children: lensLabel(item) }, item))) })), _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) => {
|
|
438
|
+
if (e.key === "Enter") {
|
|
439
|
+
e.preventDefault();
|
|
440
|
+
stepMatch(e.shiftKey ? -1 : 1);
|
|
441
|
+
}
|
|
442
|
+
else if (e.key === "Escape" && searchText) {
|
|
443
|
+
e.preventDefault();
|
|
444
|
+
setSearchText("");
|
|
445
|
+
}
|
|
446
|
+
} }), trimmedSearch && (_jsxs(_Fragment, { children: [_jsx("span", { className: "plan-search-count num", children: matchedIds.length > 0
|
|
447
|
+
? t("ui.plan_diagram.search_matches", { current: String(matchCursor + 1), total: String(matchedIds.length) })
|
|
448
|
+
: 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 }) })] }))] }), showControls && (_jsx(ZoomControls, { zoom: zoom, setZoom: setZoom, fit: fit, showMinimap: showMinimap, onToggleMinimap: () => setMinimapPref((prev) => !(prev ?? autoMinimap)) }))] })), showActualSummary && plan.kind === "actual" && _jsx(ActualSummary, { plan: plan, onPick: select }), showCostStrip && _jsx(CostStrip, { plan: plan, query: query, focus: focus, onPick: select }), _jsxs("div", { className: "diagram-wrap", onKeyDown: (e) => {
|
|
449
|
+
if (e.target?.tagName === "INPUT")
|
|
450
|
+
return;
|
|
451
|
+
if (e.key === "+" || e.key === "=") {
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
setZoom((z) => +(z + 0.15).toFixed(2));
|
|
454
|
+
}
|
|
455
|
+
else if (e.key === "-") {
|
|
456
|
+
e.preventDefault();
|
|
457
|
+
setZoom((z) => +(z - 0.15).toFixed(2));
|
|
458
|
+
}
|
|
459
|
+
else if (e.key === "0") {
|
|
460
|
+
e.preventDefault();
|
|
461
|
+
fit();
|
|
462
|
+
}
|
|
463
|
+
}, children: [!showHeader && showControls && (_jsx("div", { className: "diagram-float", children: _jsx(ZoomControls, { zoom: zoom, setZoom: setZoom, fit: fit, showMinimap: showMinimap, onToggleMinimap: () => setMinimapPref((prev) => !(prev ?? autoMinimap)) }) })), _jsx("div", { className: `diagram-scroll can-pan ${isPanning ? "is-panning" : ""}`, style: scrollStyle, ref: scroller, title: isPanning ? undefined : t("ui.plan_diagram.pan_hint"), onPointerDown: handlePointerDown, onPointerMove: handlePointerMove, onPointerUp: endPan, onPointerCancel: endPan, onPointerLeave: endPan, onClickCapture: (e) => {
|
|
464
|
+
if (suppressClick.current) {
|
|
465
|
+
e.stopPropagation();
|
|
466
|
+
e.preventDefault();
|
|
467
|
+
suppressClick.current = false;
|
|
468
|
+
}
|
|
469
|
+
}, children: _jsx("div", { className: `diagram ${trimmedSearch ? "has-search" : ""}`, style: { width: width * zoom, height: height * zoom }, children: _jsxs("div", { style: { width, height, transform: `scale(${zoom})`, transformOrigin: "0 0", position: "relative" }, children: [_jsxs("svg", { width: width, height: height, className: "diagram-edges", "aria-hidden": "true", children: [_jsxs("defs", { children: [_jsx("marker", { id: "pd-arrow", viewBox: "0 0 8 8", refX: "7", refY: "4", markerWidth: "8", markerHeight: "8", markerUnits: "userSpaceOnUse", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0 L8,4 L0,8 z", className: "pd-arrow" }) }), _jsx("marker", { id: "pd-arrow-hot", viewBox: "0 0 8 8", refX: "7", refY: "4", markerWidth: "8", markerHeight: "8", markerUnits: "userSpaceOnUse", orient: "auto-start-reverse", children: _jsx("path", { d: "M0,0 L8,4 L0,8 z", className: "pd-arrow hot" }) })] }), edges.map((e) => {
|
|
470
|
+
const x1 = px(e.from.x) + CARD_W / 2;
|
|
471
|
+
const y1 = py(e.from.y);
|
|
472
|
+
const x2 = px(e.to.x) + CARD_W / 2;
|
|
473
|
+
const y2 = py(e.to.y) + CARD_H + 3;
|
|
474
|
+
const mid = (y1 + y2) / 2;
|
|
475
|
+
const label = e.rows > 0 ? t("ui.plan_diagram.edge_rows", { n: rows(e.rows) === "1" ? 1 : e.rows, rows: rows(e.rows) }) : "";
|
|
476
|
+
const via = e.via.length ? t("ui.plan_diagram.via", { operators: e.via.join(", ") }) : "";
|
|
477
|
+
const text = [label, via].filter(Boolean).join(" · ");
|
|
478
|
+
const w = text.length * 5.9 + 12;
|
|
479
|
+
const lx = (x1 + x2) / 2 + (x1 <= x2 ? -w - 8 : 8);
|
|
480
|
+
return (_jsxs("g", { children: [_jsx("path", { d: `M ${x1} ${y1} C ${x1} ${mid}, ${x2} ${mid}, ${x2} ${y2}`, fill: "none", className: `pd-edge ${e.hot ? "hot" : ""}`, strokeWidth: e.rows ? stroke(e.rows) : 1.5, strokeDasharray: e.rows ? undefined : "4 4", markerEnd: `url(#${e.hot ? "pd-arrow-hot" : "pd-arrow"})` }), text && (_jsxs("g", { transform: `translate(${lx} ${mid - 9})`, className: "edge-pill", children: [_jsx("rect", { width: w, height: 18, rx: 9 }), _jsx("text", { x: w / 2, y: 12.5, textAnchor: "middle", children: text })] }))] }, e.key));
|
|
481
|
+
})] }), _jsxs("div", { className: "diagram-result", style: { left: px(boxes.find((b) => !parentOf.has(b.node.id))?.x ?? 0), top: PAD - 4, width: CARD_W }, children: [t("ui.plan_diagram.result"), rootVia.length ? ` · ${t("ui.plan_diagram.via", { operators: rootVia.join(", ") })}` : ""] }), boxes.map((b) => {
|
|
482
|
+
const lv = lensValue(b.node);
|
|
483
|
+
return (_jsx(PlanCard, { plan: plan, estimates: estimates || lens === "rows" || lens === "reads", node: b.node, share: lv.ratio, badgeText: lv.text, ownMs: shares.ms.get(b.node.id), x: px(b.x), y: py(b.y), hot: hot.has(b.node.id), hottest: b.node.id === hottest?.id && (shareOf(b.node) ?? 0) >= 0.05, matched: matchedSet.has(b.node.id), noShare: shares.basis === "cost" ? reason(b.node) : null, selected: b.node.id === selected, mark: marks?.get(b.node.id), tint: tints?.get(b.node.id), insights: flagged.get(b.node.id), onSelect: () => select(b.node.id) }, b.node.id));
|
|
484
|
+
}), overlay && boxes.map((b) => _jsx("span", { children: overlay(b.node, { x: px(b.x), y: py(b.y), w: CARD_W, h: CARD_H }) }, `overlay-${b.node.id}`)), folds.map((f) => (_jsxs("button", { type: "button", className: "fold-pill", style: { left: px(f.x) + CARD_W / 2 - 78, top: py(f.y) + CARD_H / 2 - 14 }, title: t("ui.plan_diagram.fold_title"), onClick: () => {
|
|
485
|
+
const parent = nodes.find((n) => n.id === f.parent);
|
|
486
|
+
if (parent)
|
|
487
|
+
setExpanded((prev) => new Set([...prev, ...parent.children.map((c) => drawn(c, total, keep).node.id)]));
|
|
488
|
+
}, children: [t("ui.plan_diagram.cheap_operators", { count: f.count }), f.share != null && ` · ${percent(f.share)}`] }, f.id)))] }) }) }), showMinimap && (_jsx("div", { className: "diagram-minimap", "aria-label": t("ui.plan_diagram.minimap_label"), children: _jsxs("svg", { width: mmW, height: mmH, viewBox: `0 0 ${mmW} ${mmH}`, onPointerDown: (e) => {
|
|
489
|
+
e.stopPropagation();
|
|
490
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
491
|
+
panFromMinimap(e);
|
|
492
|
+
}, onPointerMove: (e) => {
|
|
493
|
+
if (e.buttons === 1)
|
|
494
|
+
panFromMinimap(e);
|
|
495
|
+
}, children: [boxes.map((b) => {
|
|
496
|
+
const lv = lensValue(b.node).ratio ?? 0;
|
|
497
|
+
const fill = heat(lv) === "transparent" ? "var(--border-strong)" : heat(lv);
|
|
498
|
+
const isSel = b.node.id === selected;
|
|
499
|
+
const isMatch = matchedSet.has(b.node.id);
|
|
500
|
+
return (_jsx("rect", { x: px(b.x) * mmScale, y: py(b.y) * mmScale, width: Math.max(6, CARD_W * mmScale), height: Math.max(4, CARD_H * mmScale), rx: 2, fill: fill, stroke: isSel ? "var(--focus)" : isMatch ? "var(--brand)" : "none", strokeWidth: isSel || isMatch ? 1.5 : 0 }, b.node.id));
|
|
501
|
+
}), viewport.clientW > 0 && (_jsx("rect", { className: "mm-viewport", x: Math.max(0, (viewport.left / zoom) * mmScale), y: Math.max(0, (viewport.top / zoom) * mmScale), width: Math.min(mmW, (viewport.clientW / zoom) * mmScale), height: Math.min(mmH, (viewport.clientH / zoom) * mmScale), rx: 3 }))] }) }))] }), selectedNode && props.showProps !== false && (_jsx(NodeDetails, { plan: plan, estimates: estimates, 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) }))] }));
|
|
502
|
+
}
|
|
503
|
+
function ZoomControls({ zoom, setZoom, fit, showMinimap, onToggleMinimap, }) {
|
|
504
|
+
return (_jsxs("span", { className: "zoom", children: [_jsx("button", { type: "button", className: "btn icon ghost", title: t("ui.plan_diagram.zoom_out"), onClick: () => setZoom((z) => +(z - 0.15).toFixed(2)), children: _jsx(Minus, { size: 13 }) }), _jsxs("span", { className: "zoom-level", children: [Math.round(zoom * 100), "%"] }), _jsx("button", { type: "button", className: "btn icon ghost", title: t("ui.plan_diagram.zoom_in"), onClick: () => setZoom((z) => +(z + 0.15).toFixed(2)), children: _jsx(Plus, { size: 13 }) }), _jsx("button", { type: "button", className: "btn icon ghost", title: t("ui.plan_diagram.fit"), onClick: fit, children: _jsx(Scan, { size: 13 }) }), _jsx("button", { type: "button", className: "btn icon ghost", title: t("ui.plan_diagram.actual_size"), onClick: () => setZoom(() => 1), children: _jsx(Maximize2, { size: 12 }) }), onToggleMinimap && (_jsx("button", { type: "button", className: `btn icon ghost ${showMinimap ? "on" : ""}`, "aria-pressed": showMinimap, title: t("ui.plan_diagram.minimap_toggle"), onClick: onToggleMinimap, children: _jsx(MapIcon, { size: 12 }) }))] }));
|
|
505
|
+
}
|
|
506
|
+
function PlanCard(props) {
|
|
507
|
+
const { plan, node, x, y, hot, hottest, matched, selected, mark, insights, tint, ownMs, estimates, onSelect, noShare, badgeText } = props;
|
|
508
|
+
const share = props.share ?? 0;
|
|
509
|
+
const mis = node.warnings.includes("misestimate") ? misestimate(plan, node) : null;
|
|
510
|
+
const table = node.object?.split(".").pop();
|
|
511
|
+
const worst = insights?.[0];
|
|
512
|
+
const tip = [
|
|
513
|
+
node.op,
|
|
514
|
+
node.predicate ? predicateLabel("filter", node.predicate) : node.seek_predicate ? predicateLabel("seek", node.seek_predicate) : "",
|
|
515
|
+
estimates && props.share == null ? noShare ?? "" : "",
|
|
516
|
+
...(insights ?? []).map((i) => `• ${i.title}`),
|
|
517
|
+
]
|
|
518
|
+
.filter(Boolean)
|
|
519
|
+
.join("\n");
|
|
520
|
+
return (_jsxs("button", { type: "button", "data-node": node.id, "data-tint": tint, className: `plan-card ${selected ? "sel" : ""} ${hot ? "hot" : ""} ${matched ? "match" : ""} ${mark ? `mark-${mark}` : ""} ${worst ? `flag-${worst.severity}` : ""}`, style: {
|
|
521
|
+
left: x,
|
|
522
|
+
top: y,
|
|
523
|
+
width: CARD_W,
|
|
524
|
+
height: CARD_H,
|
|
525
|
+
["--heat"]: heat(share),
|
|
526
|
+
["--share"]: `${Math.max(share > 0 ? 3 : 0, Math.min(100, share * 100))}%`,
|
|
527
|
+
}, onClick: onSelect, title: tip, "aria-label": [
|
|
528
|
+
table ? t("ui.plan_diagram.card_on", { operator: node.op, table }) : node.op,
|
|
529
|
+
estimates && badgeText != null ? t("ui.plan_diagram.card_share", { share: badgeText }) : "",
|
|
530
|
+
worst ? t("ui.plan_diagram.card_issues", { count: insights.length }) : "",
|
|
531
|
+
]
|
|
532
|
+
.filter(Boolean)
|
|
533
|
+
.join(", "), children: [_jsxs("span", { className: "pc-top", children: [_jsx("span", { className: "pc-icon", children: _jsx(OpIcon, { node: node, size: 14 }) }), _jsx("span", { className: `pc-op ${compactOp(node.op).length > 13 ? "long" : ""}`, title: node.op, children: compactOp(node.op) }), estimates && (_jsxs("span", { className: "pc-share", children: [hottest && _jsx(Flame, { size: 11, color: "var(--heat-4)" }), badgeText ?? "-"] }))] }), _jsx("span", { className: "pc-obj mono", children: table ? `${table}${node.index ? ` · ${node.index}` : ""}` : node.detail ?? "\u00a0" }), _jsxs("span", { className: "pc-rows", children: [node.act_rows != null ? (_jsxs(_Fragment, { children: [rows(estRowsForRuns(plan, node)), " \u2192 ", _jsx("b", { children: rows(node.act_rows) }), mis != null && _jsxs("span", { className: "mis", children: ["\u00D7", rows(Math.abs(mis))] })] })) : estimates && !node.facts.estimated_rows_unavailable ? (_jsx(_Fragment, { children: t("ui.plan_diagram.estimated_rows", { rows: rows(estRows(plan, node)) }) })) : (node.seek_predicate && (_jsx("span", { className: "muted mono pc-seek", title: node.seek_predicate, children: node.seek_predicate }))), (ownMs ?? node.act_time_ms) != null && _jsxs("span", { className: "muted", children: [" \u00B7 ", duration(ownMs ?? node.act_time_ms)] }), node.warnings.length > 0 && !worst && _jsx(TriangleAlert, { size: 11, color: "var(--medium-text)", style: { marginLeft: 3 } }), mark && _jsx("span", { className: `pc-mark ${mark}`, children: MARK_LABEL[mark]() })] }), worst && (_jsx("span", { className: `pc-flag ${worst.severity}`, title: insights.map((i) => i.title).join("\n"), children: insights.length }))] }));
|
|
534
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { PlanViewerTheme } from "./PlanViewer.js";
|
|
3
|
+
import type { Plan, PlanDiff, PlanNode, QueryStat } from "./types.js";
|
|
4
|
+
export type PlanDiffLook = "diagram" | "tree";
|
|
5
|
+
export type PlanDiffViewerProps = {
|
|
6
|
+
a: Plan;
|
|
7
|
+
b: Plan;
|
|
8
|
+
diff: PlanDiff;
|
|
9
|
+
nameA?: string;
|
|
10
|
+
nameB?: string;
|
|
11
|
+
queryA?: QueryStat | null;
|
|
12
|
+
queryB?: QueryStat | null;
|
|
13
|
+
defaultLook?: PlanDiffLook;
|
|
14
|
+
defaultSync?: boolean;
|
|
15
|
+
toolbarStart?: ReactNode;
|
|
16
|
+
toolbarActions?: ReactNode;
|
|
17
|
+
theme?: PlanViewerTheme;
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Side-by-side execution plan comparison viewer: verdict summary, structural & access-path changes,
|
|
22
|
+
* root-cause scenarios, operator property diff table, and synchronized dual-plan pan/zoom.
|
|
23
|
+
*/
|
|
24
|
+
export declare function PlanDiffViewer({ a, b, diff, nameA, nameB, queryA, queryB, defaultLook, defaultSync, toolbarStart, toolbarActions, theme, className, }: PlanDiffViewerProps): import("react").JSX.Element;
|
|
25
|
+
export declare function PropsCompare({ a, b, planA, planB, names, }: {
|
|
26
|
+
a: PlanNode | null;
|
|
27
|
+
b: PlanNode | null;
|
|
28
|
+
planA: Plan;
|
|
29
|
+
planB: Plan;
|
|
30
|
+
names: [string, string];
|
|
31
|
+
}): import("react").JSX.Element;
|