@culpritsql/plan-viewer 0.0.0 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/package.json +38 -3
  2. package/pkg/ActualSummary.d.ts +10 -0
  3. package/pkg/ActualSummary.js +72 -0
  4. package/pkg/DeadlockGraph.d.ts +9 -0
  5. package/pkg/DeadlockGraph.js +135 -0
  6. package/pkg/DeadlockViewer.d.ts +20 -0
  7. package/pkg/DeadlockViewer.js +62 -0
  8. package/pkg/DocdbWork.d.ts +7 -0
  9. package/pkg/DocdbWork.js +37 -0
  10. package/pkg/NodeDetails.d.ts +15 -0
  11. package/pkg/NodeDetails.js +161 -0
  12. package/pkg/OpIcon.d.ts +9 -0
  13. package/pkg/OpIcon.js +54 -0
  14. package/pkg/PlanAssessmentNotes.d.ts +3 -0
  15. package/pkg/PlanAssessmentNotes.js +8 -0
  16. package/pkg/PlanCanvas.d.ts +47 -0
  17. package/pkg/PlanCanvas.js +9 -0
  18. package/pkg/PlanDiagram.d.ts +47 -0
  19. package/pkg/PlanDiagram.js +534 -0
  20. package/pkg/PlanDiffViewer.d.ts +31 -0
  21. package/pkg/PlanDiffViewer.js +325 -0
  22. package/pkg/PlanInsights.d.ts +6 -0
  23. package/pkg/PlanInsights.js +100 -0
  24. package/pkg/PlanObjects.d.ts +7 -0
  25. package/pkg/PlanObjects.js +138 -0
  26. package/pkg/PlanOperations.d.ts +8 -0
  27. package/pkg/PlanOperations.js +114 -0
  28. package/pkg/PlanRaw.d.ts +4 -0
  29. package/pkg/PlanRaw.js +35 -0
  30. package/pkg/PlanSurface.d.ts +22 -0
  31. package/pkg/PlanSurface.js +66 -0
  32. package/pkg/PlanTypeSchema.d.ts +5 -0
  33. package/pkg/PlanTypeSchema.js +62 -0
  34. package/pkg/PlanView.d.ts +27 -0
  35. package/pkg/PlanView.js +160 -0
  36. package/pkg/PlanViewer.d.ts +30 -0
  37. package/pkg/PlanViewer.js +19 -0
  38. package/pkg/Prose.d.ts +4 -0
  39. package/pkg/Prose.js +6 -0
  40. package/pkg/Sql.d.ts +5 -0
  41. package/pkg/Sql.js +7 -0
  42. package/pkg/THIRD-PARTY-LICENSES.txt +9021 -0
  43. package/pkg/build-report.json +912 -0
  44. package/pkg/defaults.d.ts +29 -0
  45. package/pkg/defaults.js +438 -0
  46. package/pkg/host.d.ts +118 -0
  47. package/pkg/host.js +593 -0
  48. package/pkg/index.d.ts +22 -1
  49. package/pkg/index.js +21 -1
  50. package/pkg/models/Ability.d.ts +6 -0
  51. package/pkg/models/ActualSummary.d.ts +16 -0
  52. package/pkg/models/CachedStatementContext.d.ts +9 -0
  53. package/pkg/models/CachedStatementIdentity.d.ts +7 -0
  54. package/pkg/models/ChangeKind.d.ts +3 -0
  55. package/pkg/models/CleanupEvidence.d.ts +6 -0
  56. package/pkg/models/CollectionTarget.d.ts +6 -0
  57. package/pkg/models/CompilationMemory.d.ts +3 -0
  58. package/pkg/models/CompileHistory.d.ts +13 -0
  59. package/pkg/models/ConfiguredConnectionIdentity.d.ts +7 -0
  60. package/pkg/models/Connect.d.ts +22 -0
  61. package/pkg/models/ConnectionSecurityMode.d.ts +3 -0
  62. package/pkg/models/ConnectionSecuritySpec.d.ts +4 -0
  63. package/pkg/models/ConstraintValidation.d.ts +6 -0
  64. package/pkg/models/DatabaseIdentity.d.ts +5 -0
  65. package/pkg/models/DatabaseLocation.d.ts +3 -0
  66. package/pkg/models/DatabaseProduct.d.ts +6 -0
  67. package/pkg/models/Deadlock.d.ts +23 -0
  68. package/pkg/models/DeadlockFix.d.ts +16 -0
  69. package/pkg/models/DeadlockFixKind.d.ts +6 -0
  70. package/pkg/models/DeadlockPattern.d.ts +3 -0
  71. package/pkg/models/DeadlockProcess.d.ts +23 -0
  72. package/pkg/models/DeadlockResource.d.ts +12 -0
  73. package/pkg/models/DistributionPopulation.d.ts +3 -0
  74. package/pkg/models/DocdbMetrics.d.ts +7 -0
  75. package/pkg/models/Engine.d.ts +3 -0
  76. package/pkg/models/EngineAbilities.d.ts +46 -0
  77. package/pkg/models/EngineFacts.d.ts +28 -0
  78. package/pkg/models/EvidencePresentation.d.ts +4 -0
  79. package/pkg/models/ExecutionProtection.d.ts +3 -0
  80. package/pkg/models/Guess.d.ts +6 -0
  81. package/pkg/models/InsightArea.d.ts +6 -0
  82. package/pkg/models/LocalizedText.d.ts +4 -0
  83. package/pkg/models/LockHolder.d.ts +3 -0
  84. package/pkg/models/LogRateGovernanceReason.d.ts +7 -0
  85. package/pkg/models/Message.d.ts +4 -0
  86. package/pkg/models/MessageValue.d.ts +4 -0
  87. package/pkg/models/Metric.d.ts +10 -0
  88. package/pkg/models/MssqlCatalogIndexColumn.d.ts +3 -0
  89. package/pkg/models/MssqlCurrentTableType.d.ts +10 -0
  90. package/pkg/models/MssqlCurrentTypeColumn.d.ts +7 -0
  91. package/pkg/models/MssqlCurrentTypeIndex.d.ts +4 -0
  92. package/pkg/models/MssqlCurrentTypeModule.d.ts +4 -0
  93. package/pkg/models/MssqlCurrentTypeParameter.d.ts +3 -0
  94. package/pkg/models/MssqlCurrentTypeSchema.d.ts +11 -0
  95. package/pkg/models/MssqlCurrentTypeSchemaStatus.d.ts +3 -0
  96. package/pkg/models/MssqlIndexParentKind.d.ts +3 -0
  97. package/pkg/models/MssqlObjectIdentity.d.ts +7 -0
  98. package/pkg/models/NativeIdentity.d.ts +3 -0
  99. package/pkg/models/NativePlanIdentity.d.ts +4 -0
  100. package/pkg/models/NativeQueryIdentity.d.ts +3 -0
  101. package/pkg/models/NativeReadContext.d.ts +13 -0
  102. package/pkg/models/NodeKind.d.ts +3 -0
  103. package/pkg/models/NodeMatch.d.ts +3 -0
  104. package/pkg/models/NodeRuntime.d.ts +28 -0
  105. package/pkg/models/PageServerReadAvailability.d.ts +3 -0
  106. package/pkg/models/PageServerReadStatistics.d.ts +8 -0
  107. package/pkg/models/PageServerReadSummary.d.ts +19 -0
  108. package/pkg/models/PartitionTail.d.ts +6 -0
  109. package/pkg/models/Plan.d.ts +11 -0
  110. package/pkg/models/PlanAccessRows.d.ts +13 -0
  111. package/pkg/models/PlanAutomaticIndex.d.ts +3 -0
  112. package/pkg/models/PlanChange.d.ts +17 -0
  113. package/pkg/models/PlanChangedColumn.d.ts +3 -0
  114. package/pkg/models/PlanConversion.d.ts +4 -0
  115. package/pkg/models/PlanConversionIssue.d.ts +3 -0
  116. package/pkg/models/PlanCurrentTypeSchemaView.d.ts +6 -0
  117. package/pkg/models/PlanDiff.d.ts +13 -0
  118. package/pkg/models/PlanExecutionMode.d.ts +3 -0
  119. package/pkg/models/PlanFacts.d.ts +36 -0
  120. package/pkg/models/PlanHistory.d.ts +6 -0
  121. package/pkg/models/PlanHistoryKind.d.ts +3 -0
  122. package/pkg/models/PlanIndexColumns.d.ts +3 -0
  123. package/pkg/models/PlanIndexHint.d.ts +3 -0
  124. package/pkg/models/PlanInsight.d.ts +44 -0
  125. package/pkg/models/PlanInsightShare.d.ts +3 -0
  126. package/pkg/models/PlanInsights.d.ts +8 -0
  127. package/pkg/models/PlanKind.d.ts +3 -0
  128. package/pkg/models/PlanMeasurementRef.d.ts +3 -0
  129. package/pkg/models/PlanMemoryGrantFeedback.d.ts +15 -0
  130. package/pkg/models/PlanMemoryGrantFeedbackIssue.d.ts +3 -0
  131. package/pkg/models/PlanMemoryGrantFeedbackState.d.ts +3 -0
  132. package/pkg/models/PlanNode.d.ts +7 -0
  133. package/pkg/models/PlanNodeFacts.d.ts +63 -0
  134. package/pkg/models/PlanOperatorView.d.ts +5 -0
  135. package/pkg/models/PlanPageServerIo.d.ts +16 -0
  136. package/pkg/models/PlanPageServerIoIssue.d.ts +4 -0
  137. package/pkg/models/PlanPageServerIoView.d.ts +7 -0
  138. package/pkg/models/PlanPageServerMetric.d.ts +3 -0
  139. package/pkg/models/PlanParameter.d.ts +10 -0
  140. package/pkg/models/PlanParameterComparison.d.ts +3 -0
  141. package/pkg/models/PlanParameterContext.d.ts +15 -0
  142. package/pkg/models/PlanParameterIssue.d.ts +3 -0
  143. package/pkg/models/PlanParameterUse.d.ts +4 -0
  144. package/pkg/models/PlanParameterUseKind.d.ts +3 -0
  145. package/pkg/models/PlanParameterValueState.d.ts +3 -0
  146. package/pkg/models/PlanParentRelationship.d.ts +3 -0
  147. package/pkg/models/PlanRegion.d.ts +7 -0
  148. package/pkg/models/PlanSampleSource.d.ts +6 -0
  149. package/pkg/models/PlanScanCompletion.d.ts +8 -0
  150. package/pkg/models/PlanScanThread.d.ts +3 -0
  151. package/pkg/models/PlanTemporaryTableUse.d.ts +7 -0
  152. package/pkg/models/PlanVariant.d.ts +23 -0
  153. package/pkg/models/PlanView.d.ts +9 -0
  154. package/pkg/models/PlanWarning.d.ts +3 -0
  155. package/pkg/models/PlanningStep.d.ts +7 -0
  156. package/pkg/models/ProductFacts.d.ts +11 -0
  157. package/pkg/models/QueryCosts.d.ts +62 -0
  158. package/pkg/models/QueryStat.d.ts +69 -0
  159. package/pkg/models/QueryTrend.d.ts +7 -0
  160. package/pkg/models/QueryVariantFamily.d.ts +9 -0
  161. package/pkg/models/QueryWaitCoverage.d.ts +8 -0
  162. package/pkg/models/ReadUnit.d.ts +7 -0
  163. package/pkg/models/Refusal.d.ts +7 -0
  164. package/pkg/models/RelationalInput.d.ts +5 -0
  165. package/pkg/models/RelationalInputKind.d.ts +3 -0
  166. package/pkg/models/RelationalInputProvenance.d.ts +3 -0
  167. package/pkg/models/RequestEvidence.d.ts +7 -0
  168. package/pkg/models/RetainedPlanProvenance.d.ts +11 -0
  169. package/pkg/models/RuntimeDistribution.d.ts +16 -0
  170. package/pkg/models/RuntimeDistributionIssue.d.ts +3 -0
  171. package/pkg/models/RuntimeDistributionOrigin.d.ts +3 -0
  172. package/pkg/models/RuntimeDuration.d.ts +3 -0
  173. package/pkg/models/RuntimeHistogramBucket.d.ts +8 -0
  174. package/pkg/models/RuntimeQuantile.d.ts +4 -0
  175. package/pkg/models/Scenario.d.ts +11 -0
  176. package/pkg/models/ScenarioKind.d.ts +3 -0
  177. package/pkg/models/SessionAction.d.ts +6 -0
  178. package/pkg/models/SessionIdFormat.d.ts +6 -0
  179. package/pkg/models/Severity.d.ts +3 -0
  180. package/pkg/models/SharedResourceIdentity.d.ts +11 -0
  181. package/pkg/models/SharedResourceKind.d.ts +3 -0
  182. package/pkg/models/SourcePartition.d.ts +8 -0
  183. package/pkg/models/Spread.d.ts +18 -0
  184. package/pkg/models/SqlSyntax.d.ts +6 -0
  185. package/pkg/models/StatementMetrics.d.ts +32 -0
  186. package/pkg/models/StatementOrigin.d.ts +6 -0
  187. package/pkg/models/StatementTemporaryWork.d.ts +3 -0
  188. package/pkg/models/StatisticsFreshness.d.ts +3 -0
  189. package/pkg/models/TriggerTiming.d.ts +3 -0
  190. package/pkg/models/Unit.d.ts +3 -0
  191. package/pkg/models/WaitClass.d.ts +3 -0
  192. package/pkg/models/WaitMechanism.d.ts +4 -0
  193. package/pkg/models/WaitSampling.d.ts +3 -0
  194. package/pkg/models/WaitStat.d.ts +4 -0
  195. package/pkg/models/WorkerSkew.d.ts +3 -0
  196. package/pkg/models/WriteLog.d.ts +7 -0
  197. package/pkg/models/WriteRows.d.ts +7 -0
  198. package/pkg/styles.css +3463 -0
  199. package/pkg/types.d.ts +29 -0
  200. package/pkg/types.js +1 -0
@@ -0,0 +1,325 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowRightLeft, CircleCheck, EqualNot, FileDiff, Flag, Gauge, KeyRound, Link2, MemoryStick, Ruler, Split, Unlink2, Variable, } from "lucide-react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { canPlanEstimates, count, duration, estRows, percent, planEngineName, stepShare, t, tabListKeys } from "./host.js";
5
+ import { PlanDiagram } from "./PlanDiagram.js";
6
+ import { PlanView } from "./PlanView.js";
7
+ const CHANGE_TONE = {
8
+ access: "warn",
9
+ operator: "warn",
10
+ added: "good",
11
+ removed: "bad",
12
+ cost: "info",
13
+ rows: "info",
14
+ warning: "warn",
15
+ };
16
+ function changeLabel(kind) {
17
+ switch (kind) {
18
+ case "access":
19
+ return t("ui.plan_compare.change.access");
20
+ case "operator":
21
+ return t("ui.plan_compare.change.operator");
22
+ case "added":
23
+ return t("ui.plan_compare.change.added");
24
+ case "removed":
25
+ return t("ui.plan_compare.change.removed");
26
+ case "cost":
27
+ return t("ui.plan_compare.change.cost");
28
+ case "rows":
29
+ return t("ui.plan_compare.change.rows");
30
+ case "warning":
31
+ return t("ui.plan_compare.change.warning");
32
+ }
33
+ }
34
+ const SCENARIO_ICON = {
35
+ statement: _jsx(FileDiff, { size: 15 }),
36
+ "plan-kind": _jsx(Flag, { size: 15 }),
37
+ estimator: _jsx(Gauge, { size: 15 }),
38
+ parameters: _jsx(Variable, { size: 15 }),
39
+ estimates: _jsx(Ruler, { size: 15 }),
40
+ index: _jsx(KeyRound, { size: 15 }),
41
+ conversion: _jsx(ArrowRightLeft, { size: 15 }),
42
+ parallelism: _jsx(Split, { size: 15 }),
43
+ memory: _jsx(MemoryStick, { size: 15 }),
44
+ };
45
+ function scenarioLabel(kind) {
46
+ switch (kind) {
47
+ case "statement":
48
+ return t("ui.plan_compare.scenario.statement");
49
+ case "plan-kind":
50
+ return t("ui.plan_compare.scenario.plan_kind");
51
+ case "estimator":
52
+ return t("ui.plan_compare.scenario.estimator");
53
+ case "parameters":
54
+ return t("ui.plan_compare.scenario.parameters");
55
+ case "estimates":
56
+ return t("ui.plan_compare.scenario.estimates");
57
+ case "index":
58
+ return t("ui.plan_compare.scenario.index");
59
+ case "conversion":
60
+ return t("ui.plan_compare.scenario.conversion");
61
+ case "parallelism":
62
+ return t("ui.plan_compare.scenario.parallelism");
63
+ case "memory":
64
+ return t("ui.plan_compare.scenario.memory");
65
+ }
66
+ }
67
+ function formatCost(value) {
68
+ if (value < 10)
69
+ return value.toFixed(3);
70
+ if (value < 100)
71
+ return value.toFixed(1);
72
+ if (value >= 1e6)
73
+ return `${(value / 1e6).toFixed(1)}M`;
74
+ return value >= 1e4 ? `${Math.round(value / 1e3)}K` : value.toFixed(0);
75
+ }
76
+ function nodesOf(plan) {
77
+ const out = [];
78
+ const walk = (n) => {
79
+ out.push(n);
80
+ n.children.forEach(walk);
81
+ };
82
+ walk(plan.root);
83
+ return out;
84
+ }
85
+ function verdict(diff) {
86
+ const timed = diff.time_a_ms != null && diff.time_b_ms != null && diff.time_a_ms > 0 && diff.time_b_ms > 0;
87
+ const r = timed ? diff.time_b_ms / diff.time_a_ms : diff.cost_ratio;
88
+ if (r == null)
89
+ return { tone: "same", text: diff.comparable ? t("ui.plan_compare.verdict.no_costs") : t("ui.plan_compare.verdict.different_engines") };
90
+ const x = (v) => (v >= 1000 ? `${(v / 1000).toFixed(1).replace(/\.0$/, "")}K×` : v >= 10 ? `${Math.round(v)}×` : `${v.toFixed(1)}×`);
91
+ if (r >= 1.25)
92
+ return { tone: "worse", text: timed ? t("ui.plan_compare.verdict.slower", { ratio: x(r) }) : t("ui.plan_compare.verdict.costlier", { ratio: x(r) }) };
93
+ if (r <= 0.8)
94
+ return { tone: "better", text: timed ? t("ui.plan_compare.verdict.faster", { ratio: x(1 / r) }) : t("ui.plan_compare.verdict.cheaper", { ratio: x(1 / r) }) };
95
+ return { tone: "same", text: t("ui.plan_compare.verdict.same") };
96
+ }
97
+ /**
98
+ * Side-by-side execution plan comparison viewer: verdict summary, structural & access-path changes,
99
+ * root-cause scenarios, operator property diff table, and synchronized dual-plan pan/zoom.
100
+ */
101
+ export function PlanDiffViewer({ a, b, diff, nameA, nameB, queryA, queryB, defaultLook = "diagram", defaultSync = true, toolbarStart, toolbarActions, theme, className, }) {
102
+ const [pickA, setPickA] = useState(null);
103
+ const [pickB, setPickB] = useState(null);
104
+ const [active, setActive] = useState(null);
105
+ const [tab, setTab] = useState("changes");
106
+ const [look, setLook] = useState(defaultLook);
107
+ const [sync, setSync] = useState(defaultSync);
108
+ const [zoom, setZoom] = useState(0.8);
109
+ const sideA = useRef(null);
110
+ const sideB = useRef(null);
111
+ const labelA = nameA ?? t("ui.plan_compare.plan_a");
112
+ const labelB = nameB ?? t("ui.plan_compare.plan_b");
113
+ const names = labelA === labelB ? [t("ui.plan_compare.plan_a"), t("ui.plan_compare.plan_b")] : [labelA, labelB];
114
+ useEffect(() => {
115
+ setActive(null);
116
+ setPickA(null);
117
+ setPickB(null);
118
+ }, [a, b, diff]);
119
+ const view = useMemo(() => {
120
+ const marksA = new Map();
121
+ const marksB = new Map();
122
+ const tintsA = new Map();
123
+ const tintsB = new Map();
124
+ const aToB = new Map();
125
+ const bToA = new Map();
126
+ diff.matches.forEach((m) => {
127
+ aToB.set(m.a, m.b);
128
+ bToA.set(m.b, m.a);
129
+ });
130
+ diff.regions.forEach((r, i) => {
131
+ r.a.forEach((id) => tintsA.set(id, i % 6));
132
+ r.b.forEach((id) => tintsB.set(id, i % 6));
133
+ });
134
+ diff.changes.forEach((c) => {
135
+ if (c.kind === "access" || c.kind === "operator") {
136
+ if (c.a != null)
137
+ marksA.set(c.a, "changed");
138
+ if (c.b != null)
139
+ marksB.set(c.b, "changed");
140
+ }
141
+ });
142
+ diff.only_a.forEach((id) => marksA.set(id, "removed"));
143
+ diff.only_b.forEach((id) => marksB.set(id, "added"));
144
+ return { marksA, marksB, tintsA, tintsB, aToB, bToA };
145
+ }, [diff]);
146
+ useEffect(() => {
147
+ const reduce = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
148
+ const show = (side, id) => {
149
+ if (id == null || !side)
150
+ return;
151
+ requestAnimationFrame(() => side.querySelector(`[data-node="${id}"]`)?.scrollIntoView({ block: "nearest", inline: "center", behavior: reduce ? "auto" : "smooth" }));
152
+ };
153
+ show(sideA.current, pickA);
154
+ show(sideB.current, pickB);
155
+ }, [pickA, pickB]);
156
+ useEffect(() => {
157
+ if (!sync || look !== "diagram")
158
+ return;
159
+ const boxes = [sideA.current, sideB.current].map((s) => s?.querySelector(".diagram-scroll") ?? null);
160
+ if (!boxes[0] || !boxes[1])
161
+ return;
162
+ let mirroring = false;
163
+ const handlers = boxes.map((from, i) => () => {
164
+ const to = boxes[1 - i];
165
+ if (!from || !to || mirroring)
166
+ return;
167
+ mirroring = true;
168
+ const fx = from.scrollWidth - from.clientWidth;
169
+ const fy = from.scrollHeight - from.clientHeight;
170
+ to.scrollLeft = fx > 0 ? (from.scrollLeft / fx) * (to.scrollWidth - to.clientWidth) : 0;
171
+ to.scrollTop = fy > 0 ? (from.scrollTop / fy) * (to.scrollHeight - to.clientHeight) : 0;
172
+ requestAnimationFrame(() => (mirroring = false));
173
+ });
174
+ boxes.forEach((box, i) => box?.addEventListener("scroll", handlers[i], { passive: true }));
175
+ return () => boxes.forEach((box, i) => box?.removeEventListener("scroll", handlers[i]));
176
+ }, [sync, look, diff, a, b]);
177
+ const pickChange = (i) => {
178
+ const c = diff.changes[i];
179
+ if (!c)
180
+ return;
181
+ setActive(i);
182
+ setPickA(c.a ?? (c.b != null ? view.bToA.get(c.b) ?? null : null));
183
+ setPickB(c.b ?? (c.a != null ? view.aToB.get(c.a) ?? null : null));
184
+ };
185
+ const nodeA = pickA != null ? nodesOf(a).find((n) => n.id === pickA) ?? null : null;
186
+ const nodeB = pickB != null ? nodesOf(b).find((n) => n.id === pickB) ?? null : null;
187
+ const v = verdict(diff);
188
+ return (_jsxs("div", { className: `culprit-pv pv-diff cmp ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [(toolbarStart || toolbarActions || names[0] || names[1]) && (_jsxs("div", { className: "compare-pickers", children: [toolbarStart ?? (_jsxs("div", { className: "pv-meta", children: [_jsx("span", { className: "side-badge", children: "A" }), " ", _jsx("b", { children: names[0] }), _jsx("span", { className: "muted", children: "vs" }), _jsx("span", { className: "side-badge", children: "B" }), " ", _jsx("b", { children: names[1] })] })), toolbarActions && (_jsxs(_Fragment, { children: [_jsx("span", { className: "spacer" }), toolbarActions] }))] })), _jsxs("section", { className: "cmp-verdict", "aria-live": "polite", children: [_jsxs("p", { className: "cmp-lead", children: [_jsx("span", { className: `cmp-pill ${v.tone}`, children: v.text }), diff.headlines[0]] }), diff.headlines.length > 1 && (_jsx("ul", { className: "cmp-more", children: diff.headlines.slice(1).map((h, i) => (_jsx("li", { children: h }, i))) })), _jsxs("div", { className: "cmp-figures", children: [_jsx(Figure, { label: t("ui.plan_compare.figure.cost", { plan: names[0] }), value: diff.cost_a == null ? t("ui.plan_compare.unavailable") : formatCost(diff.cost_a) }), _jsx(Figure, { label: t("ui.plan_compare.figure.cost", { plan: names[1] }), value: diff.cost_b == null ? t("ui.plan_compare.unavailable") : formatCost(diff.cost_b), tone: v.tone }), diff.time_a_ms != null && diff.time_b_ms != null && (_jsxs(_Fragment, { children: [_jsx(Figure, { label: t("ui.plan_compare.figure.time", { plan: names[0] }), value: duration(diff.time_a_ms) }), _jsx(Figure, { label: t("ui.plan_compare.figure.time", { plan: names[1] }), value: duration(diff.time_b_ms), tone: v.tone })] })), _jsx(Figure, { label: t("ui.plan_compare.figure.operators"), value: `${nodesOf(a).length} → ${nodesOf(b).length}` }), _jsx(Figure, { label: t("ui.plan_compare.figure.regions"), value: String(diff.regions.length) })] })] }), _jsxs("section", { className: "cmp-panel", children: [_jsxs("div", { className: "cmp-tabs", role: "tablist", "aria-label": t("ui.plan_compare.details"), onKeyDown: tabListKeys, children: [_jsx(TabButton, { id: "changes", tab: tab, onPick: setTab, label: t("ui.plan_compare.tab.changes"), count: diff.changes.length }), _jsx(TabButton, { id: "why", tab: tab, onPick: setTab, label: t("ui.plan_compare.tab.why"), count: diff.scenarios.length }), _jsx(TabButton, { id: "props", tab: tab, onPick: setTab, label: t("ui.plan_compare.tab.props") })] }), _jsxs("div", { className: "cmp-body", role: "tabpanel", children: [tab === "changes" &&
189
+ (diff.changes.length === 0 ? (_jsxs("div", { className: "cmp-empty", children: [_jsx(CircleCheck, { size: 18 }), _jsxs("div", { children: [_jsx("b", { children: diff.same_shape ? t("ui.plan_compare.same_steps") : t("ui.plan_compare.minor_steps") }), _jsx("div", { className: "muted", children: t("ui.plan_compare.same_steps_detail") })] })] })) : (_jsx("ul", { className: "cmp-changes", children: diff.changes.map((c, i) => (_jsx("li", { children: _jsxs("button", { type: "button", className: `cmp-change ${active === i ? "on" : ""}`, onClick: () => pickChange(i), children: [_jsx("span", { className: `cmp-tag ${CHANGE_TONE[c.kind]}`, children: changeLabel(c.kind) }), _jsxs("span", { className: "cmp-change-text", children: [_jsx("span", { className: "cmp-title", children: c.title }), c.detail && _jsx("span", { className: "cmp-detail", children: c.detail })] })] }) }, i))) }))), tab === "why" &&
190
+ (diff.scenarios.length === 0 ? (_jsxs("div", { className: "cmp-empty", children: [_jsx(CircleCheck, { size: 18 }), _jsxs("div", { children: [_jsx("b", { children: t("ui.plan_compare.same_conditions") }), _jsx("div", { className: "muted", children: t("ui.plan_compare.same_conditions_detail") })] })] })) : (_jsx("ul", { className: "cmp-scenarios", children: diff.scenarios.map((s, i) => (_jsxs("li", { className: "cmp-scenario", children: [_jsx("span", { className: "cmp-scenario-icon", "aria-hidden": true, children: SCENARIO_ICON[s.kind] }), _jsxs("div", { children: [_jsx("div", { className: "cmp-scenario-kind", children: scenarioLabel(s.kind) }), _jsx("div", { className: "cmp-title", children: s.title }), s.detail && _jsx("div", { className: "cmp-detail wrap", children: s.detail }), (s.a != null || s.b != null) && (_jsx("button", { type: "button", className: "link", onClick: () => {
191
+ setPickA(s.a ?? (s.b != null ? view.bToA.get(s.b) ?? null : null));
192
+ setPickB(s.b ?? (s.a != null ? view.aToB.get(s.a) ?? null : null));
193
+ setTab("props");
194
+ }, children: t("ui.plan_compare.show_step") }))] })] }, i))) }))), tab === "props" && _jsx(PropsCompare, { a: nodeA, b: nodeB, planA: a, planB: b, names: names })] })] }), _jsxs("div", { className: "cmp-canvas-bar", children: [_jsxs("div", { className: "cmp-canvas-controls", children: [_jsxs("span", { className: "seg", role: "group", "aria-label": t("ui.plan_compare.plan_view"), children: [_jsx("button", { type: "button", className: look === "diagram" ? "on" : "", onClick: () => setLook("diagram"), children: t("ui.plan_compare.diagram") }), _jsx("button", { type: "button", className: look === "tree" ? "on" : "", onClick: () => setLook("tree"), children: t("ui.plan_compare.tree") })] }), look === "diagram" && (_jsxs("button", { type: "button", className: `btn ghost cmp-sync ${sync ? "on" : ""}`, "aria-pressed": sync, title: sync ? t("ui.plan_compare.sync_on") : t("ui.plan_compare.sync_off"), onClick: () => setSync(!sync), children: [sync ? _jsx(Link2, { size: 13 }) : _jsx(Unlink2, { size: 13 }), " ", t("ui.plan_compare.sync")] }))] }), look === "diagram" && (_jsxs("div", { className: "cmp-legend", "aria-hidden": true, children: [_jsxs("span", { className: "cmp-key", children: [_jsx("i", { className: "tint" }), " ", t("ui.plan_compare.legend.same")] }), _jsxs("span", { className: "cmp-key", children: [_jsx("i", { className: "changed" }), " ", t("ui.plan_compare.legend.changed")] }), _jsxs("span", { className: "cmp-key", children: [_jsx("i", { className: "only" }), " ", t("ui.plan_compare.legend.only")] })] }))] }), _jsxs("div", { className: "compare-sides", children: [_jsx(Side, { label: "A", name: names[0], plan: a, innerRef: sideA, children: look === "diagram" ? (_jsx(PlanDiagram, { plan: a, query: queryA, marks: view.marksA, tints: view.tintsA, selectedId: pickA, initialZoom: 0.8, zoom: sync ? zoom : undefined, onZoomChange: setZoom, showProps: false, onSelect: (id) => {
195
+ setActive(null);
196
+ setPickA(id);
197
+ setPickB(view.aToB.get(id) ?? null);
198
+ setTab("props");
199
+ } })) : (_jsx(PlanView, { plan: a, query: queryA, selectedId: pickA, onSelect: (id) => {
200
+ setActive(null);
201
+ setPickA(id);
202
+ setPickB(view.aToB.get(id) ?? null);
203
+ } })) }), _jsx(Side, { label: "B", name: names[1], plan: b, innerRef: sideB, children: look === "diagram" ? (_jsx(PlanDiagram, { plan: b, query: queryB, marks: view.marksB, tints: view.tintsB, selectedId: pickB, initialZoom: 0.8, zoom: sync ? zoom : undefined, onZoomChange: setZoom, showProps: false, onSelect: (id) => {
204
+ setActive(null);
205
+ setPickB(id);
206
+ setPickA(view.bToA.get(id) ?? null);
207
+ setTab("props");
208
+ } })) : (_jsx(PlanView, { plan: b, query: queryB, selectedId: pickB, onSelect: (id) => {
209
+ setActive(null);
210
+ setPickB(id);
211
+ setPickA(view.bToA.get(id) ?? null);
212
+ } })) })] })] }));
213
+ }
214
+ function TabButton({ id, tab, onPick, label, count: n }) {
215
+ return (_jsxs("button", { type: "button", role: "tab", "aria-selected": tab === id, tabIndex: tab === id ? 0 : -1, className: `cmp-tab ${tab === id ? "on" : ""}`, onClick: () => onPick(id), children: [label, n != null && _jsx("span", { className: "cmp-count", children: n })] }));
216
+ }
217
+ function Figure({ label, value, tone }) {
218
+ return (_jsxs("div", { className: `cmp-figure ${tone === "worse" || tone === "better" ? tone : ""}`, children: [_jsx("div", { className: "value", children: value }), _jsx("div", { className: "label", title: label, children: label })] }));
219
+ }
220
+ function Side({ label, name, plan, innerRef, children }) {
221
+ return (_jsxs("div", { className: "compare-side", ref: innerRef, children: [_jsxs("div", { className: "compare-side-head", children: [_jsx("span", { className: "side-badge", children: label }), _jsx("b", { children: name }), _jsx("span", { className: "muted", children: t("ui.plan_compare.side_meta", { engine: planEngineName(plan), kind: plan.kind }) })] }), children] }));
222
+ }
223
+ function norm(value) {
224
+ return value.replace(/\[[^\]]+\]\.(?=\[[^\]]+\]\.\[[^\]]+\]\.\[[^\]]+\])/g, "").replace(/\s+/g, " ").trim();
225
+ }
226
+ function rowsFor(node, plan) {
227
+ if (!node)
228
+ return {};
229
+ const est = estRows(plan, node);
230
+ const weighed = canPlanEstimates(plan.engine) || plan.kind === "actual";
231
+ return {
232
+ operator: node.op,
233
+ table: node.object,
234
+ index: node.index,
235
+ seek: node.seek_predicate ? norm(node.seek_predicate) : null,
236
+ filter: node.predicate ? norm(node.predicate) : null,
237
+ est_rows: weighed && est != null ? count(est) : null,
238
+ est_executions: weighed && est != null ? count(node.est_executions) : null,
239
+ act_rows: node.act_rows != null ? count(node.act_rows) : null,
240
+ rows_read: node.rows_read != null ? count(node.rows_read) : null,
241
+ table_rows: node.table_rows != null ? count(node.table_rows) : null,
242
+ act_time: node.act_time_ms != null ? duration(node.act_time_ms) : null,
243
+ cost_share: weighed ? percent(stepShare(plan, node)) : null,
244
+ subtree_cost: weighed && !plan.facts.estimated_cost_unavailable ? formatCost(node.subtree_cost) : null,
245
+ warnings: node.warnings.length ? node.warnings.map((w) => w.replace(/-/g, " ")).join(", ") : null,
246
+ };
247
+ }
248
+ function propLabel(prop) {
249
+ switch (prop) {
250
+ case "operator":
251
+ return t("ui.plan_compare.prop.operator");
252
+ case "table":
253
+ return t("ui.plan_compare.prop.table");
254
+ case "index":
255
+ return t("ui.plan_compare.prop.index");
256
+ case "seek":
257
+ return t("ui.plan_compare.prop.seek");
258
+ case "filter":
259
+ return t("ui.plan_compare.prop.filter");
260
+ case "est_rows":
261
+ return t("ui.plan_compare.prop.est_rows");
262
+ case "est_executions":
263
+ return t("ui.plan_compare.prop.est_executions");
264
+ case "act_rows":
265
+ return t("ui.plan_compare.prop.act_rows");
266
+ case "rows_read":
267
+ return t("ui.plan_compare.prop.rows_read");
268
+ case "table_rows":
269
+ return t("ui.plan_compare.prop.table_rows");
270
+ case "act_time":
271
+ return t("ui.plan_compare.prop.act_time");
272
+ case "cost_share":
273
+ return t("ui.plan_compare.prop.cost_share");
274
+ case "subtree_cost":
275
+ return t("ui.plan_compare.prop.subtree_cost");
276
+ case "warnings":
277
+ return t("ui.plan_compare.prop.warnings");
278
+ }
279
+ }
280
+ const GROUPS = [
281
+ { group: "does", props: ["operator", "table", "index", "seek", "filter"] },
282
+ { group: "rows", props: ["est_rows", "est_executions", "act_rows", "rows_read", "table_rows"] },
283
+ { group: "cost", props: ["cost_share", "subtree_cost", "act_time"] },
284
+ { group: "warnings", props: ["warnings"] },
285
+ ];
286
+ function groupTitle(group) {
287
+ switch (group) {
288
+ case "does":
289
+ return t("ui.plan_compare.group.does");
290
+ case "rows":
291
+ return t("ui.plan_compare.group.rows");
292
+ case "cost":
293
+ return t("ui.plan_compare.group.cost");
294
+ case "warnings":
295
+ return t("ui.plan_compare.group.warnings");
296
+ }
297
+ }
298
+ export function PropsCompare({ a, b, planA, planB, names, }) {
299
+ const [showSame, setShowSame] = useState(false);
300
+ if (!a && !b) {
301
+ return (_jsxs("div", { className: "cmp-empty", children: [_jsx(EqualNot, { size: 18 }), _jsxs("div", { children: [_jsx("b", { children: t("ui.plan_compare.select_step") }), _jsx("div", { className: "muted", children: t("ui.plan_compare.select_step_detail") })] })] }));
302
+ }
303
+ const ra = rowsFor(a, planA);
304
+ const rb = rowsFor(b, planB);
305
+ const label = (n) => (n ? `${n.op}${n.object ? ` · ${n.object.split(".").pop()}` : ""}` : "—");
306
+ const groups = GROUPS.map((g) => ({
307
+ title: groupTitle(g.group),
308
+ rows: g.props
309
+ .map((k) => ({ label: propLabel(k), a: ra[k] ?? null, b: rb[k] ?? null }))
310
+ .filter((r) => r.a != null || r.b != null),
311
+ })).filter((g) => g.rows.length > 0);
312
+ const keys = [...new Set([...Object.keys(a?.props ?? {}), ...Object.keys(b?.props ?? {})])].sort();
313
+ const other = keys.map((k) => ({
314
+ label: k,
315
+ a: a?.props[k] != null ? norm(a.props[k]) : null,
316
+ b: b?.props[k] != null ? norm(b.props[k]) : null,
317
+ }));
318
+ const differs = (r) => (r.a ?? "") !== (r.b ?? "");
319
+ const changed = other.filter(differs);
320
+ const same = other.filter((r) => !differs(r));
321
+ const line = (r) => (_jsxs("div", { className: `cmp-prop ${differs(r) ? "diff" : ""}`, children: [_jsx("span", { className: "cmp-prop-label", title: r.label, children: r.label }), _jsx("span", { className: `cmp-prop-value ${r.a == null ? "none" : ""}`, children: r.a ?? "—" }), _jsx("span", { className: "cmp-prop-sign", role: "img", "aria-label": differs(r) ? t("ui.plan_compare.differs") : t("ui.plan_compare.same"), children: differs(r) ? "≠" : "" }), _jsx("span", { className: `cmp-prop-value ${r.b == null ? "none" : ""}`, children: r.b ?? "—" })] }, r.label));
322
+ return (_jsxs("div", { className: "cmp-props", children: [_jsxs("div", { className: "cmp-prop head", children: [_jsx("span", {}), _jsxs("span", { children: [_jsx("span", { className: "side-badge", children: "A" }), " ", label(a), !a && _jsxs("span", { className: "muted", children: [" \u00B7 ", t("ui.plan_compare.only_in", { plan: names[1] })] })] }), _jsx("span", {}), _jsxs("span", { children: [_jsx("span", { className: "side-badge", children: "B" }), " ", label(b), !b && _jsxs("span", { className: "muted", children: [" \u00B7 ", t("ui.plan_compare.only_in", { plan: names[0] })] })] })] }), groups.map((g) => (_jsxs("div", { className: "cmp-prop-group", children: [_jsx("div", { className: "cmp-prop-title", children: g.title }), g.rows.map(line)] }, g.title))), other.length > 0 && (_jsxs("div", { className: "cmp-prop-group", children: [_jsxs("div", { className: "cmp-prop-title", children: [t("ui.plan_compare.engine_props"), " ", _jsxs("span", { className: "muted", children: ["\u00B7 ", t("ui.plan_compare.differ_count", { n: changed.length, count: String(changed.length) })] })] }), changed.map(line), same.length > 0 && (_jsx("button", { type: "button", className: "link cmp-prop-more", onClick: () => setShowSame((v) => !v), children: showSame
323
+ ? t("ui.plan_compare.hide_identical", { count: String(same.length) })
324
+ : t("ui.plan_compare.show_identical", { count: String(same.length) }) })), showSame && same.map(line)] }))] }));
325
+ }
@@ -0,0 +1,6 @@
1
+ import type { Plan } from "./types.js";
2
+ export declare function PlanInsights({ plan, selectedNode, onSelectNode }: {
3
+ plan: Plan;
4
+ selectedNode?: number | null;
5
+ onSelectNode: (id: number) => void;
6
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,100 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChartColumn, ChevronDown, CircleCheck, Copy, Cpu, Crosshair, KeyRound, ListChecks, MemoryStick, Server, SquareCode, } from "lucide-react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { bySeverity, canPlanEstimates, copyAndTell, percent, statedInsightShare, t } from "./host.js";
5
+ import { PlanAssessmentNotes } from "./PlanAssessmentNotes.js";
6
+ import { Prose } from "./Prose.js";
7
+ import { Sql } from "./Sql.js";
8
+ const AREA = {
9
+ index: { icon: KeyRound, label: () => t("ui.plan_insights.area.index") },
10
+ query: { icon: SquareCode, label: () => t("ui.plan_insights.area.query") },
11
+ statistics: { icon: ChartColumn, label: () => t("ui.plan_insights.area.statistics") },
12
+ memory: { icon: MemoryStick, label: () => t("ui.plan_insights.area.memory") },
13
+ parallelism: { icon: Cpu, label: () => t("ui.plan_insights.area.parallelism") },
14
+ server: { icon: Server, label: () => t("ui.plan_insights.area.server") },
15
+ };
16
+ const SEVERITY_LABEL = {
17
+ high: () => t("ui.plan_insights.severity.high"),
18
+ medium: () => t("ui.plan_insights.severity.medium"),
19
+ low: () => t("ui.plan_insights.severity.low"),
20
+ };
21
+ const SEVERITY_COUNT = {
22
+ high: (n) => t("ui.plan_insights.count.high", { n, count: String(n) }),
23
+ medium: (n) => t("ui.plan_insights.count.medium", { n, count: String(n) }),
24
+ low: (n) => t("ui.plan_insights.count.low", { n, count: String(n) }),
25
+ };
26
+ const shareOf = (plan, i) => canPlanEstimates(plan.engine) || plan.kind === "actual" ? statedInsightShare(plan, i) : null;
27
+ const SHOWN = 4;
28
+ const insightMarkdown = (i, share) => {
29
+ const severity = SEVERITY_LABEL[i.severity]();
30
+ const area = AREA[i.area].label();
31
+ return [
32
+ share != null
33
+ ? t("ui.plan_insights.md.heading_share", { severity, area, title: i.title, share: percent(share) })
34
+ : t("ui.plan_insights.md.heading", { severity, area, title: i.title }),
35
+ "",
36
+ i.detail,
37
+ "",
38
+ t("ui.plan_insights.md.fix", { fix: i.fix }),
39
+ ...(i.fix_sql ? ["", "```sql", i.fix_sql, "```"] : []),
40
+ "",
41
+ t("ui.plan_insights.md.verify", { verify: i.verify }),
42
+ ].join("\n");
43
+ };
44
+ const insightsMarkdown = (plan, items) => [
45
+ t("ui.plan_insights.md.title"),
46
+ ...(plan.statement ? [t("ui.plan_insights.md.statement"), ["```sql", plan.statement.trim(), "```"].join("\n")] : []),
47
+ ...items.map((i, n) => `### ${n + 1}. ${insightMarkdown(i, shareOf(plan, i))}`),
48
+ ].join("\n\n");
49
+ export function PlanInsights({ plan, selectedNode, onSelectNode }) {
50
+ const items = useMemo(() => [...(plan.insights?.items ?? [])].sort(bySeverity), [plan]);
51
+ const note = plan.insights?.note ?? null;
52
+ const [open, setOpen] = useState(null);
53
+ const [all, setAll] = useState(false);
54
+ const list = useRef(null);
55
+ const counts = useMemo(() => {
56
+ const c = { high: 0, medium: 0, low: 0 };
57
+ items.forEach((i) => (c[i.severity] += 1));
58
+ return c;
59
+ }, [items]);
60
+ const related = (i) => selectedNode != null && i.nodes.includes(selectedNode);
61
+ useEffect(() => {
62
+ if (selectedNode == null)
63
+ return;
64
+ const index = items.findIndex((i) => i.nodes.includes(selectedNode));
65
+ if (index >= SHOWN)
66
+ setAll(true);
67
+ }, [selectedNode, items]);
68
+ if (!plan.insights)
69
+ return null;
70
+ if (items.length === 0) {
71
+ return (_jsxs("div", { className: "culprit-pv insights empty-insights", children: [_jsx(CircleCheck, { size: 16, className: "ok" }), _jsxs("div", { children: [_jsx("div", { className: "ins-empty-title", children: t("ui.plan_insights.none") }), _jsx(PlanAssessmentNotes, { note: note })] })] }));
72
+ }
73
+ const shown = all ? items : items.slice(0, SHOWN);
74
+ const focusRow = (index) => list.current?.querySelectorAll(".ins-row")[index]?.focus();
75
+ return (_jsxs("section", { className: "culprit-pv insights", "aria-label": t("ui.plan_insights.label"), children: [_jsxs("header", { className: "ins-head", children: [_jsx(ListChecks, { size: 14 }), _jsx("span", { className: "ins-label", children: t("ui.plan_insights.title") }), _jsx("span", { className: "ins-counts", children: ["high", "medium", "low"]
76
+ .filter((s) => counts[s] > 0)
77
+ .map((s) => (_jsxs("span", { className: `ins-count ${s}`, children: [_jsx("i", {}), SEVERITY_COUNT[s](counts[s])] }, s))) }), _jsx("span", { className: "spacer" }), _jsxs("button", { type: "button", className: "btn ghost small ins-copy-all", onClick: () => copyAndTell(insightsMarkdown(plan, items), t("ui.plan_insights.copied_all", { count: items.length })), title: t("ui.plan_insights.copy_all_title"), children: [_jsx(Copy, { size: 12 }), " ", t("ui.common.copy")] })] }), _jsx(PlanAssessmentNotes, { note: note }), _jsx("div", { className: "ins-list", ref: list, role: "list", "aria-label": t("ui.plan_insights.list_label"), children: shown.map((i, index) => {
78
+ const area = AREA[i.area];
79
+ const Icon = area.icon;
80
+ const expanded = open === index;
81
+ return (_jsxs("div", { role: "listitem", className: `ins ${i.severity} ${expanded ? "open" : ""} ${related(i) ? "related" : ""}`, children: [_jsxs("button", { type: "button", className: "ins-row", "aria-current": related(i) || undefined, "aria-expanded": expanded, onClick: () => {
82
+ setOpen(expanded ? null : index);
83
+ if (i.nodes[0] != null)
84
+ onSelectNode(i.nodes[0]);
85
+ }, onKeyDown: (e) => {
86
+ if (e.key === "ArrowDown") {
87
+ e.preventDefault();
88
+ focusRow(Math.min(shown.length - 1, index + 1));
89
+ }
90
+ else if (e.key === "ArrowUp") {
91
+ e.preventDefault();
92
+ focusRow(Math.max(0, index - 1));
93
+ }
94
+ else if (e.key === "Escape" && expanded) {
95
+ e.preventDefault();
96
+ setOpen(null);
97
+ }
98
+ }, children: [_jsx("span", { className: "ins-sev", title: t("ui.plan_insights.severity_title", { severity: i.severity }) }), _jsx("span", { className: "ins-area", title: area.label(), children: _jsx(Icon, { size: 13 }) }), _jsx("span", { className: "ins-title", children: i.title }), shareOf(plan, i) != null && (_jsxs("span", { className: "ins-impact", title: t("ui.plan_insights.share_title"), children: [_jsx("span", { className: "ins-bar", children: _jsx("span", { style: { width: `${Math.max(4, Math.min(100, (shareOf(plan, i) ?? 0) * 100))}%` } }) }), percent(shareOf(plan, i))] })), _jsx(ChevronDown, { size: 14, className: "ins-chev" })] }), expanded && (_jsxs("div", { className: "ins-body", children: [_jsx("p", { className: "ins-detail", children: _jsx(Prose, { text: i.detail }) }), _jsxs("div", { className: "ins-block", children: [_jsx("div", { className: "ins-block-label", children: t("ui.plan_insights.fix") }), _jsx("p", { children: _jsx(Prose, { text: i.fix }) }), i.fix_sql && (_jsxs("div", { className: "ins-sql", children: [_jsx(Sql, { text: i.fix_sql }), _jsxs("button", { type: "button", className: "btn ghost small ins-copy", onClick: () => copyAndTell(i.fix_sql, t("ui.plan_insights.fix_copied")), title: t("ui.plan_insights.copy_fix_title"), children: [_jsx(Copy, { size: 12 }), " ", t("ui.common.copy")] })] }))] }), _jsxs("div", { className: "ins-block", children: [_jsx("div", { className: "ins-block-label", children: t("ui.plan_insights.verify") }), _jsx("p", { children: i.verify })] }), _jsxs("div", { className: "ins-actions", children: [i.nodes[0] != null && (_jsxs("button", { type: "button", className: "btn ghost small", onClick: () => onSelectNode(i.nodes[0]), children: [_jsx(Crosshair, { size: 12 }), " ", t("ui.plan_insights.show_operator")] })), _jsxs("button", { type: "button", className: "btn ghost small", onClick: () => copyAndTell(insightMarkdown(i, shareOf(plan, i)), t("ui.plan_insights.copied_one")), title: t("ui.plan_insights.copy_one_title"), children: [_jsx(Copy, { size: 12 }), " ", t("ui.plan_insights.copy_one")] })] })] }))] }, `${i.rule}-${i.nodes[0] ?? index}`));
99
+ }) }), items.length > SHOWN && (_jsx("button", { type: "button", className: "ins-more", onClick: () => setAll((v) => !v), children: all ? t("ui.plan_insights.show_fewer") : t("ui.plan_insights.show_more", { count: String(items.length - SHOWN) }) }))] }));
100
+ }
@@ -0,0 +1,7 @@
1
+ import type { Plan, QueryStat } from "./types.js";
2
+ export declare function PlanObjects({ plan, query, selectedId, onSelect, }: {
3
+ plan: Plan;
4
+ query?: QueryStat | null;
5
+ selectedId: number | null;
6
+ onSelect: (id: number) => void;
7
+ }): import("react").JSX.Element;
@@ -0,0 +1,138 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Database, KeyRound } from "lucide-react";
3
+ import { useMemo } from "react";
4
+ import { allNodes, canPlanEstimates, insightsByNode, percent, planShares, rows, rowsOut, t } from "./host.js";
5
+ const SEV_RANK = { high: 3, medium: 2, low: 1 };
6
+ export function PlanObjects({ plan, query, selectedId, onSelect, }) {
7
+ const shares = useMemo(() => planShares(plan, query), [plan, query]);
8
+ const flagged = useMemo(() => insightsByNode(plan), [plan]);
9
+ const weighed = canPlanEstimates(plan.engine) || plan.kind === "actual";
10
+ const rollups = useMemo(() => {
11
+ const byObject = new Map();
12
+ for (const node of allNodes(plan.root)) {
13
+ if (!node.object)
14
+ continue;
15
+ const list = byObject.get(node.object) ?? [];
16
+ list.push(node);
17
+ byObject.set(node.object, list);
18
+ }
19
+ const items = [];
20
+ for (const [object, nodes] of byObject) {
21
+ const parts = object.split(".");
22
+ const shortName = parts[parts.length - 1] ?? object;
23
+ const schema = parts.length > 1 ? parts.slice(0, -1).join(".") : null;
24
+ let share = 0;
25
+ let hasShare = false;
26
+ let scans = 0;
27
+ let seeks = 0;
28
+ let lookups = 0;
29
+ let directTableScan = false;
30
+ const indexSet = new Set();
31
+ let rowsProduced = 0;
32
+ let hasRows = false;
33
+ let logicalReads = 0;
34
+ let hasLogical = false;
35
+ let physicalReads = 0;
36
+ let hasPhysical = false;
37
+ let rowsRead = 0;
38
+ let hasRowsRead = false;
39
+ const seenInsightRules = new Set();
40
+ let warningCount = 0;
41
+ let worst = null;
42
+ const sortedOps = [...nodes].sort((a, b) => (shares.stated.get(b.id) ?? 0) - (shares.stated.get(a.id) ?? 0));
43
+ for (const n of sortedOps) {
44
+ const s = shares.stated.get(n.id);
45
+ if (s != null) {
46
+ share += s;
47
+ hasShare = true;
48
+ }
49
+ if (n.kind === "scan") {
50
+ scans++;
51
+ if (!n.index)
52
+ directTableScan = true;
53
+ }
54
+ else if (n.kind === "seek") {
55
+ seeks++;
56
+ }
57
+ else if (n.kind === "lookup") {
58
+ lookups++;
59
+ }
60
+ if (n.index)
61
+ indexSet.add(n.index);
62
+ const out = rowsOut(plan, n);
63
+ if (out != null) {
64
+ rowsProduced += out;
65
+ hasRows = true;
66
+ }
67
+ if (n.runtime?.logical_reads != null) {
68
+ logicalReads += n.runtime.logical_reads;
69
+ hasLogical = true;
70
+ }
71
+ if (n.runtime?.physical_reads != null) {
72
+ physicalReads += n.runtime.physical_reads;
73
+ hasPhysical = true;
74
+ }
75
+ if (n.rows_read != null) {
76
+ rowsRead += n.rows_read;
77
+ hasRowsRead = true;
78
+ }
79
+ warningCount += n.warnings.length;
80
+ if (n.warnings.length > 0 && !worst)
81
+ worst = "low";
82
+ for (const ins of flagged.get(n.id) ?? []) {
83
+ seenInsightRules.add(`${ins.rule}:${ins.nodes.join(",")}`);
84
+ if (!worst || SEV_RANK[ins.severity] > SEV_RANK[worst])
85
+ worst = ins.severity;
86
+ }
87
+ }
88
+ const hitRatio = hasLogical && logicalReads > 0 && hasPhysical
89
+ ? Math.max(0, Math.min(1, (logicalReads - physicalReads) / logicalReads))
90
+ : null;
91
+ items.push({
92
+ object,
93
+ shortName,
94
+ schema,
95
+ operators: sortedOps,
96
+ share: Math.min(1, share),
97
+ hasShare: weighed && hasShare,
98
+ scans,
99
+ seeks,
100
+ lookups,
101
+ indexes: [...indexSet],
102
+ directTableScan,
103
+ rowsProduced: hasRows ? rowsProduced : null,
104
+ reads: hasLogical ? logicalReads : hasRowsRead ? rowsRead : null,
105
+ hitRatio,
106
+ issues: seenInsightRules.size + warningCount,
107
+ worst,
108
+ });
109
+ }
110
+ return items.sort((a, b) => b.share - a.share || (b.reads ?? 0) - (a.reads ?? 0) || a.object.localeCompare(b.object));
111
+ }, [plan, shares, flagged, weighed]);
112
+ if (rollups.length === 0) {
113
+ return (_jsx("div", { className: "culprit-pv ops", children: _jsx("div", { className: "empty", children: t("ui.plan_objects.none") }) }));
114
+ }
115
+ const hasReads = rollups.some((r) => r.reads != null);
116
+ const hasHits = rollups.some((r) => r.hitRatio != null);
117
+ const hasIssues = rollups.some((r) => r.issues > 0);
118
+ return (_jsx("div", { className: "culprit-pv ops plan-objects", children: _jsx("div", { className: "ops-scroll", children: _jsxs("table", { className: "ops-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: t("ui.plan_objects.table") }), _jsx("th", { children: t("ui.plan_objects.access") }), _jsx("th", { children: t("ui.plan_objects.indexes") }), weighed && _jsx("th", { className: "r", children: t("ui.plan_objects.share") }), _jsx("th", { className: "r", children: t("ui.plan_objects.rows_out") }), hasReads && _jsx("th", { className: "r", children: t("ui.plan_objects.reads") }), hasHits && _jsx("th", { className: "r", children: t("ui.plan_objects.cache_hit") }), hasIssues && _jsx("th", { className: "r", children: t("ui.plan_objects.issues") })] }) }), _jsx("tbody", { children: rollups.map((item) => {
119
+ const isSelected = item.operators.some((n) => n.id === selectedId);
120
+ const accessParts = [];
121
+ if (item.scans > 0)
122
+ accessParts.push(t("ui.plan_objects.scans_count", { n: item.scans, count: String(item.scans) }));
123
+ if (item.seeks > 0)
124
+ accessParts.push(t("ui.plan_objects.seeks_count", { n: item.seeks, count: String(item.seeks) }));
125
+ if (item.lookups > 0)
126
+ accessParts.push(t("ui.plan_objects.lookups_count", { n: item.lookups, count: String(item.lookups) }));
127
+ if (accessParts.length === 0) {
128
+ accessParts.push(t("ui.plan_objects.ops_count", { n: item.operators.length, count: String(item.operators.length) }));
129
+ }
130
+ return (_jsxs("tr", { className: isSelected ? "sel" : "", onClick: () => {
131
+ if (item.operators[0])
132
+ onSelect(item.operators[0].id);
133
+ }, children: [_jsx("td", { children: _jsxs("span", { className: "ops-name", children: [_jsx("span", { className: "ops-icon", children: _jsx(Database, { size: 13 }) }), _jsxs("span", { className: "ops-text", children: [_jsx("b", { className: "mono", children: item.shortName }), item.schema && _jsx("span", { className: "mono muted", children: item.schema })] })] }) }), _jsx("td", { children: _jsxs("div", { className: "po-access", children: [_jsx("span", { children: accessParts.join(" · ") }), item.operators.length > 1 && (_jsx("span", { className: "po-step-pills", children: item.operators.map((op) => (_jsx("button", { type: "button", className: `po-step-pill ${op.id === selectedId ? "on" : ""}`, onClick: (e) => {
134
+ e.stopPropagation();
135
+ onSelect(op.id);
136
+ }, children: op.op }, op.id))) }))] }) }), _jsx("td", { children: _jsxs("div", { className: "po-indexes", children: [item.indexes.map((ix) => (_jsxs("span", { className: "tag mono", children: [_jsx(KeyRound, { size: 10 }), " ", ix] }, ix))), item.directTableScan && _jsx("span", { className: "tag medium", children: t("ui.plan_objects.direct_table") })] }) }), weighed && (_jsx("td", { className: "r num", children: item.hasShare ? (_jsxs("span", { className: "ops-cost", children: [_jsx("span", { className: "ops-cost-bar", children: _jsx("span", { style: { width: `${Math.min(100, item.share * 100)}%` } }) }), percent(item.share)] })) : (_jsx("span", { className: "muted", children: "-" })) })), _jsx("td", { className: "r num", children: item.rowsProduced != null ? rows(item.rowsProduced) : _jsx("span", { className: "muted", children: "-" }) }), hasReads && _jsx("td", { className: "r num", children: item.reads != null ? rows(item.reads) : _jsx("span", { className: "muted", children: "-" }) }), hasHits && (_jsx("td", { className: "r num", children: item.hitRatio != null ? (_jsx("span", { className: item.hitRatio < 0.8 ? "ops-err bad" : "", children: percent(item.hitRatio) })) : (_jsx("span", { className: "muted", children: "-" })) })), hasIssues && (_jsx("td", { className: "r num", children: item.issues > 0 ? _jsx("span", { className: `ops-issues ${item.worst ?? ""}`, children: item.issues }) : _jsx("span", { className: "muted", children: "-" }) }))] }, item.object));
137
+ }) })] }) }) }));
138
+ }
@@ -0,0 +1,8 @@
1
+ import type { Plan, QueryStat } from "./types.js";
2
+ export declare function PlanOperations({ plan, query: statement, focus, selectedId, onSelect, }: {
3
+ plan: Plan;
4
+ query?: QueryStat | null;
5
+ focus?: number | null;
6
+ selectedId: number | null;
7
+ onSelect: (id: number) => void;
8
+ }): import("react").JSX.Element;