@culpritsql/plan-viewer 0.0.0 → 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.
Files changed (199) 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 +317 -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 +21 -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 +907 -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 +5 -0
  57. package/pkg/models/CompilationMemory.d.ts +3 -0
  58. package/pkg/models/CompileHistory.d.ts +13 -0
  59. package/pkg/models/Connect.d.ts +22 -0
  60. package/pkg/models/ConnectionSecurityMode.d.ts +3 -0
  61. package/pkg/models/ConnectionSecuritySpec.d.ts +4 -0
  62. package/pkg/models/ConstraintValidation.d.ts +6 -0
  63. package/pkg/models/DatabaseIdentity.d.ts +5 -0
  64. package/pkg/models/DatabaseLocation.d.ts +3 -0
  65. package/pkg/models/DatabaseProduct.d.ts +6 -0
  66. package/pkg/models/Deadlock.d.ts +23 -0
  67. package/pkg/models/DeadlockFix.d.ts +16 -0
  68. package/pkg/models/DeadlockFixKind.d.ts +6 -0
  69. package/pkg/models/DeadlockPattern.d.ts +3 -0
  70. package/pkg/models/DeadlockProcess.d.ts +23 -0
  71. package/pkg/models/DeadlockResource.d.ts +12 -0
  72. package/pkg/models/DistributionPopulation.d.ts +3 -0
  73. package/pkg/models/DocdbMetrics.d.ts +7 -0
  74. package/pkg/models/Engine.d.ts +3 -0
  75. package/pkg/models/EngineAbilities.d.ts +46 -0
  76. package/pkg/models/EngineFacts.d.ts +28 -0
  77. package/pkg/models/EvidencePresentation.d.ts +4 -0
  78. package/pkg/models/ExecutionProtection.d.ts +3 -0
  79. package/pkg/models/Guess.d.ts +6 -0
  80. package/pkg/models/InsightArea.d.ts +6 -0
  81. package/pkg/models/LocalizedText.d.ts +4 -0
  82. package/pkg/models/LockHolder.d.ts +3 -0
  83. package/pkg/models/LogRateGovernanceReason.d.ts +7 -0
  84. package/pkg/models/Message.d.ts +4 -0
  85. package/pkg/models/MessageValue.d.ts +4 -0
  86. package/pkg/models/Metric.d.ts +10 -0
  87. package/pkg/models/MssqlCatalogIndexColumn.d.ts +3 -0
  88. package/pkg/models/MssqlCurrentTableType.d.ts +10 -0
  89. package/pkg/models/MssqlCurrentTypeColumn.d.ts +7 -0
  90. package/pkg/models/MssqlCurrentTypeIndex.d.ts +4 -0
  91. package/pkg/models/MssqlCurrentTypeModule.d.ts +4 -0
  92. package/pkg/models/MssqlCurrentTypeParameter.d.ts +3 -0
  93. package/pkg/models/MssqlCurrentTypeSchema.d.ts +11 -0
  94. package/pkg/models/MssqlCurrentTypeSchemaStatus.d.ts +3 -0
  95. package/pkg/models/MssqlIndexParentKind.d.ts +3 -0
  96. package/pkg/models/MssqlObjectIdentity.d.ts +7 -0
  97. package/pkg/models/NativeIdentity.d.ts +3 -0
  98. package/pkg/models/NativePlanIdentity.d.ts +4 -0
  99. package/pkg/models/NativeQueryIdentity.d.ts +3 -0
  100. package/pkg/models/NativeReadContext.d.ts +13 -0
  101. package/pkg/models/NodeKind.d.ts +3 -0
  102. package/pkg/models/NodeMatch.d.ts +3 -0
  103. package/pkg/models/NodeRuntime.d.ts +28 -0
  104. package/pkg/models/PageServerReadAvailability.d.ts +3 -0
  105. package/pkg/models/PageServerReadStatistics.d.ts +8 -0
  106. package/pkg/models/PageServerReadSummary.d.ts +19 -0
  107. package/pkg/models/PartitionTail.d.ts +6 -0
  108. package/pkg/models/Plan.d.ts +11 -0
  109. package/pkg/models/PlanAccessRows.d.ts +13 -0
  110. package/pkg/models/PlanAutomaticIndex.d.ts +3 -0
  111. package/pkg/models/PlanChange.d.ts +17 -0
  112. package/pkg/models/PlanChangedColumn.d.ts +3 -0
  113. package/pkg/models/PlanConversion.d.ts +4 -0
  114. package/pkg/models/PlanConversionIssue.d.ts +3 -0
  115. package/pkg/models/PlanCurrentTypeSchemaView.d.ts +6 -0
  116. package/pkg/models/PlanDiff.d.ts +13 -0
  117. package/pkg/models/PlanExecutionMode.d.ts +3 -0
  118. package/pkg/models/PlanFacts.d.ts +36 -0
  119. package/pkg/models/PlanHistory.d.ts +6 -0
  120. package/pkg/models/PlanHistoryKind.d.ts +3 -0
  121. package/pkg/models/PlanIndexColumns.d.ts +3 -0
  122. package/pkg/models/PlanIndexHint.d.ts +3 -0
  123. package/pkg/models/PlanInsight.d.ts +44 -0
  124. package/pkg/models/PlanInsightShare.d.ts +3 -0
  125. package/pkg/models/PlanInsights.d.ts +8 -0
  126. package/pkg/models/PlanKind.d.ts +3 -0
  127. package/pkg/models/PlanMeasurementRef.d.ts +3 -0
  128. package/pkg/models/PlanMemoryGrantFeedback.d.ts +15 -0
  129. package/pkg/models/PlanMemoryGrantFeedbackIssue.d.ts +3 -0
  130. package/pkg/models/PlanMemoryGrantFeedbackState.d.ts +3 -0
  131. package/pkg/models/PlanNode.d.ts +7 -0
  132. package/pkg/models/PlanNodeFacts.d.ts +63 -0
  133. package/pkg/models/PlanOperatorView.d.ts +5 -0
  134. package/pkg/models/PlanPageServerIo.d.ts +16 -0
  135. package/pkg/models/PlanPageServerIoIssue.d.ts +4 -0
  136. package/pkg/models/PlanPageServerIoView.d.ts +7 -0
  137. package/pkg/models/PlanPageServerMetric.d.ts +3 -0
  138. package/pkg/models/PlanParameter.d.ts +10 -0
  139. package/pkg/models/PlanParameterComparison.d.ts +3 -0
  140. package/pkg/models/PlanParameterContext.d.ts +15 -0
  141. package/pkg/models/PlanParameterIssue.d.ts +3 -0
  142. package/pkg/models/PlanParameterUse.d.ts +4 -0
  143. package/pkg/models/PlanParameterUseKind.d.ts +3 -0
  144. package/pkg/models/PlanParameterValueState.d.ts +3 -0
  145. package/pkg/models/PlanParentRelationship.d.ts +3 -0
  146. package/pkg/models/PlanRegion.d.ts +7 -0
  147. package/pkg/models/PlanSampleSource.d.ts +6 -0
  148. package/pkg/models/PlanScanCompletion.d.ts +8 -0
  149. package/pkg/models/PlanScanThread.d.ts +3 -0
  150. package/pkg/models/PlanTemporaryTableUse.d.ts +7 -0
  151. package/pkg/models/PlanVariant.d.ts +23 -0
  152. package/pkg/models/PlanView.d.ts +9 -0
  153. package/pkg/models/PlanWarning.d.ts +3 -0
  154. package/pkg/models/PlanningStep.d.ts +7 -0
  155. package/pkg/models/ProductFacts.d.ts +11 -0
  156. package/pkg/models/QueryCosts.d.ts +62 -0
  157. package/pkg/models/QueryStat.d.ts +69 -0
  158. package/pkg/models/QueryTrend.d.ts +7 -0
  159. package/pkg/models/QueryVariantFamily.d.ts +9 -0
  160. package/pkg/models/QueryWaitCoverage.d.ts +8 -0
  161. package/pkg/models/ReadUnit.d.ts +7 -0
  162. package/pkg/models/Refusal.d.ts +7 -0
  163. package/pkg/models/RelationalInput.d.ts +5 -0
  164. package/pkg/models/RelationalInputKind.d.ts +3 -0
  165. package/pkg/models/RelationalInputProvenance.d.ts +3 -0
  166. package/pkg/models/RequestEvidence.d.ts +7 -0
  167. package/pkg/models/RetainedPlanProvenance.d.ts +11 -0
  168. package/pkg/models/RuntimeDistribution.d.ts +16 -0
  169. package/pkg/models/RuntimeDistributionIssue.d.ts +3 -0
  170. package/pkg/models/RuntimeDistributionOrigin.d.ts +3 -0
  171. package/pkg/models/RuntimeDuration.d.ts +3 -0
  172. package/pkg/models/RuntimeHistogramBucket.d.ts +8 -0
  173. package/pkg/models/RuntimeQuantile.d.ts +4 -0
  174. package/pkg/models/Scenario.d.ts +11 -0
  175. package/pkg/models/ScenarioKind.d.ts +3 -0
  176. package/pkg/models/SessionAction.d.ts +6 -0
  177. package/pkg/models/SessionIdFormat.d.ts +6 -0
  178. package/pkg/models/Severity.d.ts +3 -0
  179. package/pkg/models/SharedResourceIdentity.d.ts +11 -0
  180. package/pkg/models/SharedResourceKind.d.ts +3 -0
  181. package/pkg/models/SourcePartition.d.ts +8 -0
  182. package/pkg/models/Spread.d.ts +18 -0
  183. package/pkg/models/SqlSyntax.d.ts +6 -0
  184. package/pkg/models/StatementMetrics.d.ts +32 -0
  185. package/pkg/models/StatementOrigin.d.ts +6 -0
  186. package/pkg/models/StatementTemporaryWork.d.ts +3 -0
  187. package/pkg/models/StatisticsFreshness.d.ts +3 -0
  188. package/pkg/models/TriggerTiming.d.ts +3 -0
  189. package/pkg/models/Unit.d.ts +3 -0
  190. package/pkg/models/WaitClass.d.ts +3 -0
  191. package/pkg/models/WaitMechanism.d.ts +4 -0
  192. package/pkg/models/WaitSampling.d.ts +3 -0
  193. package/pkg/models/WaitStat.d.ts +4 -0
  194. package/pkg/models/WorkerSkew.d.ts +3 -0
  195. package/pkg/models/WriteLog.d.ts +7 -0
  196. package/pkg/models/WriteRows.d.ts +7 -0
  197. package/pkg/styles.css +3273 -0
  198. package/pkg/types.d.ts +29 -0
  199. package/pkg/types.js +1 -0
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@culpritsql/plan-viewer",
3
- "version": "0.0.0",
3
+ "version": "0.5.6",
4
4
  "description": "Interactive React execution plan diagram, structural plan diff, and deadlock cycle graph components for SQL Server, PostgreSQL, MySQL, MariaDB, YugabyteDB, and SQLite.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
+ "sideEffects": [
8
+ "*.css",
9
+ "./pkg/styles.css"
10
+ ],
7
11
  "files": [
8
12
  "pkg"
9
13
  ],
@@ -11,7 +15,14 @@
11
15
  ".": {
12
16
  "types": "./pkg/index.d.ts",
13
17
  "import": "./pkg/index.js"
14
- }
18
+ },
19
+ "./styles.css": "./pkg/styles.css"
20
+ },
21
+ "dependencies": {
22
+ "lucide-react": "1.68.0"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^18.0.0 || ^19.0.0"
15
26
  },
16
27
  "repository": {
17
28
  "type": "git",
@@ -20,5 +31,29 @@
20
31
  "homepage": "https://culpritsql.com",
21
32
  "bugs": {
22
33
  "url": "https://github.com/culpritsql/culprit-plan-viewer/issues"
23
- }
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "provenance": true
38
+ },
39
+ "keywords": [
40
+ "react",
41
+ "sql",
42
+ "execution-plan",
43
+ "query-plan",
44
+ "explain",
45
+ "explain-analyze",
46
+ "showplan",
47
+ "sqlplan",
48
+ "deadlock",
49
+ "plan-viewer",
50
+ "postgres",
51
+ "postgresql",
52
+ "mssql",
53
+ "sql-server",
54
+ "mysql",
55
+ "mariadb",
56
+ "yugabytedb",
57
+ "sqlite"
58
+ ]
24
59
  }
@@ -0,0 +1,10 @@
1
+ import type { Plan } from "./types.js";
2
+ /**
3
+ * What a measured run cost, in words: how long it took, what it read, how much memory it was given and used, and the
4
+ * operators that explain the time (slowest step, worst estimate, a worker doing most of the work, a spill).
5
+ * Each callout selects its operator in the diagram.
6
+ */
7
+ export declare function ActualSummary({ plan, onPick }: {
8
+ plan: Plan;
9
+ onPick?: (id: number) => void;
10
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,72 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Clock, Cpu, Database, Gauge, HardDrive, Scale, TriangleAlert, Users } from "lucide-react";
3
+ import { actualFacts, count, duration, estRowsForRuns, percent, rowCount, t, tx, when } from "./host.js";
4
+ function kb(value) {
5
+ if (value >= 1024 * 1024)
6
+ return `${(value / 1024 / 1024).toFixed(1)} GB`;
7
+ if (value >= 1024)
8
+ return `${(value / 1024).toFixed(value >= 10 * 1024 ? 0 : 1)} MB`;
9
+ return `${Math.round(value)} KB`;
10
+ }
11
+ function where(node) {
12
+ const table = node.object?.split(".").pop();
13
+ return table ? t("ui.actual_summary.op_on", { op: node.op, table }) : node.op;
14
+ }
15
+ function Stat({ icon, value, label, title }) {
16
+ return (_jsxs("span", { className: "as-stat", title: title, children: [icon, _jsx("b", { children: value }), _jsx("span", { children: label })] }));
17
+ }
18
+ /**
19
+ * What a measured run cost, in words: how long it took, what it read, how much memory it was given and used, and the
20
+ * operators that explain the time (slowest step, worst estimate, a worker doing most of the work, a spill).
21
+ * Each callout selects its operator in the diagram.
22
+ */
23
+ export function ActualSummary({ plan, onPick }) {
24
+ const f = actualFacts(plan);
25
+ if (!f)
26
+ return null;
27
+ const memory = f.grantedKb != null && f.grantedKb > 0 && f.usedKb != null ? { granted: f.grantedKb, used: f.usedKb } : null;
28
+ const idle = memory ? 1 - memory.used / memory.granted : 0;
29
+ const callouts = [];
30
+ if (f.slowest && f.slowest.share >= 0.2) {
31
+ callouts.push({
32
+ key: "slowest",
33
+ tone: "hot",
34
+ icon: _jsx(Gauge, { size: 13 }),
35
+ text: _jsx(_Fragment, { children: tx("ui.actual_summary.slowest", { time: duration(f.slowest.ms), share: percent(f.slowest.share) }, { operator: _jsx("b", { children: where(f.slowest.node) }) }) }),
36
+ node: f.slowest.node.id,
37
+ title: t("ui.actual_summary.slowest_hint"),
38
+ });
39
+ }
40
+ if (f.worstEstimate) {
41
+ const n = f.worstEstimate.node;
42
+ const expected = estRowsForRuns(plan, n);
43
+ callouts.push({
44
+ key: "estimate",
45
+ tone: "warn",
46
+ icon: _jsx(Scale, { size: 13 }),
47
+ text: (_jsx(_Fragment, { children: tx("ui.actual_summary.estimate", { expected: rowCount(expected), factor: count(Math.abs(f.worstEstimate.factor)) }, { actual: _jsx("b", { children: count(n.act_rows ?? 0) }), operator: _jsx("b", { children: where(n) }) }) })),
48
+ node: f.worstEstimate.node.id,
49
+ title: t("ui.actual_summary.estimate_hint"),
50
+ });
51
+ }
52
+ if (f.skew) {
53
+ callouts.push({
54
+ key: "skew",
55
+ tone: "warn",
56
+ icon: _jsx(Users, { size: 13 }),
57
+ text: _jsx(_Fragment, { children: tx("ui.actual_summary.skew", { threads: String(f.skew.threads), share: percent(f.skew.busiest) }, { operator: _jsx("b", { children: where(f.skew.node) }) }) }),
58
+ node: f.skew.node.id,
59
+ title: t("ui.actual_summary.skew_hint"),
60
+ });
61
+ }
62
+ if (f.spilled) {
63
+ callouts.push({
64
+ key: "spill",
65
+ tone: "warn",
66
+ icon: _jsx(HardDrive, { size: 13 }),
67
+ text: f.spillPages > 0 ? t("ui.actual_summary.spill_pages", { n: f.spillPages, pages: count(f.spillPages) }) : t("ui.actual_summary.spill"),
68
+ title: t("ui.actual_summary.spill_hint"),
69
+ });
70
+ }
71
+ return (_jsxs("div", { className: "actual-summary", children: [_jsxs("div", { className: "as-head", children: [_jsx("span", { className: "as-kicker", children: f.lastRunAt ? t("ui.common.last_run") : t("ui.actual_summary.measured_run") }), f.elapsedMs != null && (_jsxs("span", { className: "as-elapsed", title: t("ui.actual_summary.elapsed"), children: [_jsx(Clock, { size: 14 }), duration(f.elapsedMs)] })), _jsxs("span", { className: "as-stats", children: [f.cpuMs != null && (_jsx(Stat, { icon: _jsx(Cpu, { size: 12 }), value: duration(f.cpuMs), label: t("ui.actual_summary.cpu"), title: f.workers ? t("ui.actual_summary.across_workers", { workers: String(f.workers) }) : undefined })), f.logicalReads != null && (_jsx(Stat, { icon: _jsx(Database, { size: 12 }), value: count(f.logicalReads), label: f.physicalReads ? t("ui.actual_summary.reads_from_disk", { disk: count(f.physicalReads) }) : t("ui.actual_summary.reads"), title: t("ui.actual_summary.reads_hint") })), f.rows != null && _jsx(Stat, { icon: null, value: count(f.rows), label: t("ui.actual_summary.rows", { n: f.rows }) }), f.workers != null && f.workers > 1 && _jsx(Stat, { icon: _jsx(Users, { size: 12 }), value: String(f.workers), label: t("ui.actual_summary.workers", { n: f.workers }) })] }), f.lastRunAt && (_jsx("span", { className: "as-when", title: when(f.lastRunAt.endsWith("Z") ? f.lastRunAt : `${f.lastRunAt}Z`).full, children: when(f.lastRunAt.endsWith("Z") ? f.lastRunAt : `${f.lastRunAt}Z`).short }))] }), memory && (_jsxs("div", { className: "as-memory", title: t("ui.actual_summary.memory_hint"), children: [_jsx("span", { className: "as-label", children: t("ui.actual_summary.memory") }), _jsx("span", { className: "as-bar", "aria-hidden": true, children: _jsx("span", { style: { width: `${Math.min(100, (memory.used / memory.granted) * 100)}%` } }) }), _jsxs("span", { children: [tx("ui.actual_summary.memory_used", { granted: kb(memory.granted) }, { used: _jsx("b", { children: kb(memory.used) }) }), idle >= 0.75 && memory.granted >= 10 * 1024 && _jsxs("span", { className: "muted", children: [" \u00B7 ", t("ui.actual_summary.memory_idle", { share: percent(idle) })] })] })] })), f.grantedKb != null && f.grantedKb > 0 && f.usedKb == null && _jsx("p", { className: "as-note", children: t("ui.actual_summary.memory_unrecorded", { granted: kb(f.grantedKb) }) }), f.triggers.length > 0 && (_jsxs("section", { className: "actual-triggers", "aria-label": t("ui.actual_summary.triggers_label"), children: [_jsx("h4", { children: t("ui.actual_summary.triggers") }), _jsx("p", { className: "muted", children: t("ui.actual_summary.triggers_note") }), _jsx("ul", { children: f.triggers.map((trigger, i) => (_jsxs("li", { children: [_jsx("span", { children: trigger.relation ? tx("ui.actual_summary.trigger_on", { relation: trigger.relation }, { trigger: _jsx("b", { children: trigger.name }) }) : _jsx("b", { children: trigger.name }) }), _jsxs("span", { children: [duration(trigger.ms), " \u00B7", " ", trigger.calls == null ? t("ui.actual_summary.calls_unrecorded") : t("ui.actual_summary.calls", { n: trigger.calls, calls: count(trigger.calls) })] })] }, `${trigger.name}-${i}`))) })] })), !f.timed && (_jsxs("div", { className: "as-note", children: [_jsx(TriangleAlert, { size: 12 }), " ", f.lastRunAt ? t("ui.actual_summary.untimed_past") : t("ui.actual_summary.untimed_run")] })), callouts.length > 0 && (_jsx("div", { className: "as-callouts", children: callouts.map((c) => c.node != null && onPick ? (_jsxs("button", { type: "button", className: `as-callout ${c.tone}`, title: c.title, onClick: () => onPick(c.node), children: [c.icon, _jsx("span", { children: c.text })] }, c.key)) : (_jsxs("span", { className: `as-callout ${c.tone}`, title: c.title, children: [c.icon, _jsx("span", { children: c.text })] }, c.key))) }))] }));
72
+ }
@@ -0,0 +1,9 @@
1
+ import type { PlanViewerTheme } from "./PlanViewer.js";
2
+ import type { Deadlock, DeadlockProcess } from "./types.js";
3
+ export declare function DeadlockGraph({ deadlock, onPick, showLegend, theme, className, }: {
4
+ deadlock: Deadlock;
5
+ onPick?: (process: DeadlockProcess) => void;
6
+ showLegend?: boolean;
7
+ theme?: PlanViewerTheme;
8
+ className?: string;
9
+ }): import("react").JSX.Element;
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from "react";
3
+ import { t, useLanguage } from "./host.js";
4
+ const W = 640;
5
+ const PROC_W = 172;
6
+ const PROC_H = 70;
7
+ const RES_W = 168;
8
+ const RES_H = 48;
9
+ const ROW = 100;
10
+ const TOP = 26;
11
+ const LABEL_H = 16;
12
+ function clip(text, max) {
13
+ const flat = text.replace(/\s+/g, " ").trim();
14
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
15
+ }
16
+ function shortMode(mode) {
17
+ const m = mode?.split(" (")[0]?.trim();
18
+ return m && m.length <= 3 ? m : null;
19
+ }
20
+ function path(e) {
21
+ const fromRight = e.from.x + e.from.w <= e.to.x;
22
+ const x1 = fromRight ? e.from.x + e.from.w : e.from.x;
23
+ const x2 = fromRight ? e.to.x : e.to.x + e.to.w;
24
+ const bow = e.kind === "holds" ? -9 : 9;
25
+ const y1 = e.from.y + e.from.h / 2 + bow;
26
+ const y2 = e.to.y + e.to.h / 2 + bow;
27
+ const dx = (x2 - x1) * 0.45;
28
+ return { d: `M ${x1} ${y1} C ${x1 + dx} ${y1}, ${x2 - dx} ${y2}, ${x2} ${y2}`, mx: (x1 + x2) / 2, my: (y1 + y2) / 2 };
29
+ }
30
+ function who(p) {
31
+ return p.session ? t("ui.deadlock_graph.session", { session: p.session }) : t("ui.deadlock_graph.process", { process: p.id });
32
+ }
33
+ function resourceLabel(r) {
34
+ const kind = r.kind.toLowerCase();
35
+ const scope = kind.includes("key") || kind === "record" || kind === "rid" || kind === "ridlock" || kind === "tuple"
36
+ ? t("ui.deadlock_graph.scope.row")
37
+ : kind.includes("page")
38
+ ? t("ui.deadlock_graph.scope.page")
39
+ : kind.includes("object") || kind === "table"
40
+ ? t("ui.deadlock_graph.scope.table")
41
+ : kind === "transaction"
42
+ ? t("ui.deadlock_graph.scope.transaction")
43
+ : r.kind;
44
+ return { title: r.object ?? (kind === "transaction" ? r.id : r.kind), sub: [r.index, scope].filter(Boolean).join(" · ") };
45
+ }
46
+ function lockTitle(r, label) {
47
+ const held = r.holders.map((h) => h.mode ?? "?").join(", ") || "?";
48
+ const wanted = r.waiters.map((h) => h.mode ?? "?").join(", ") || "?";
49
+ return label.sub
50
+ ? t("ui.deadlock_graph.lock_title_scope", { object: label.title, scope: label.sub, held, wanted })
51
+ : t("ui.deadlock_graph.lock_title", { object: label.title, held, wanted });
52
+ }
53
+ function processLabel(p) {
54
+ const statement = p.statement ?? t("ui.deadlock_graph.statement_unknown");
55
+ return p.victim
56
+ ? t("ui.deadlock_graph.process_label_victim", { process: who(p), statement })
57
+ : t("ui.deadlock_graph.process_label", { process: who(p), statement });
58
+ }
59
+ function edgeLabel(e) {
60
+ const mode = shortMode(e.mode);
61
+ return mode ? t("ui.deadlock_graph.edge_mode", { kind: e.kind, mode }) : t("ui.deadlock_graph.edge", { kind: e.kind });
62
+ }
63
+ export function DeadlockGraph({ deadlock, onPick, showLegend = true, theme, className, }) {
64
+ const [focus, setFocus] = useState(null);
65
+ const lang = useLanguage();
66
+ const layout = useMemo(() => {
67
+ const resources = deadlock.resources.length ? deadlock.resources : [];
68
+ const rows = Math.max(resources.length, Math.ceil(deadlock.processes.length / 2), 1);
69
+ const height = TOP * 2 + (rows - 1) * ROW + Math.max(PROC_H, RES_H);
70
+ const resBox = new Map();
71
+ resources.forEach((r, i) => resBox.set(r.id, { x: (W - RES_W) / 2, y: TOP + i * ROW + (PROC_H - RES_H) / 2, w: RES_W, h: RES_H }));
72
+ const procBox = new Map();
73
+ deadlock.processes.forEach((p, i) => {
74
+ const touched = resources
75
+ .map((r, j) => (r.holders.some((h) => h.process === p.id) || r.waiters.some((h) => h.process === p.id) ? j : -1))
76
+ .filter((j) => j >= 0);
77
+ const centre = touched.length ? touched.reduce((a, b) => a + b, 0) / touched.length : Math.floor(i / 2);
78
+ const left = i % 2 === 0;
79
+ procBox.set(p.id, {
80
+ x: left ? 0 : W - PROC_W,
81
+ y: TOP + centre * ROW + (deadlock.processes.length > 2 ? Math.floor(i / 2) * 8 : 0),
82
+ w: PROC_W,
83
+ h: PROC_H,
84
+ });
85
+ });
86
+ const edges = [];
87
+ for (const r of resources) {
88
+ const rb = resBox.get(r.id);
89
+ for (const h of r.holders) {
90
+ const pb = procBox.get(h.process);
91
+ if (pb)
92
+ edges.push({ from: rb, to: pb, kind: "holds", mode: h.mode, proc: h.process, res: r.id, leftward: pb.x < rb.x });
93
+ }
94
+ for (const h of r.waiters) {
95
+ const pb = procBox.get(h.process);
96
+ if (pb)
97
+ edges.push({ from: pb, to: rb, kind: "wants", mode: h.mode, proc: h.process, res: r.id, leftward: rb.x < pb.x });
98
+ }
99
+ }
100
+ return { height, resBox, procBox, edges };
101
+ }, [deadlock]);
102
+ const lit = (e) => !focus || focus === e.proc || focus === e.res;
103
+ const labelY = useMemo(() => {
104
+ const boxes = layout.edges.map((e, i) => {
105
+ const p = path(e);
106
+ const text = edgeLabel(e);
107
+ return { i, x: p.mx, half: text.length * 3.3, y: p.my + 4 };
108
+ });
109
+ const sorted = [...boxes].sort((a, b) => a.y - b.y);
110
+ for (let a = 0; a < sorted.length; a++) {
111
+ for (let b = a + 1; b < sorted.length; b++) {
112
+ const A = sorted[a];
113
+ const B = sorted[b];
114
+ const gap = B.y - A.y;
115
+ if (Math.abs(A.x - B.x) < A.half + B.half + 4 && gap < LABEL_H) {
116
+ A.y -= (LABEL_H - gap) / 2;
117
+ B.y += (LABEL_H - gap) / 2;
118
+ }
119
+ }
120
+ }
121
+ return new Map(boxes.map((b) => [b.i, b.y]));
122
+ }, [layout, lang]);
123
+ return (_jsxs("figure", { className: `culprit-pv dl-graph ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [_jsxs("svg", { viewBox: `0 0 ${W} ${layout.height}`, role: "group", "aria-label": t("ui.deadlock_graph.label", { headline: deadlock.headline }), preserveAspectRatio: "xMidYMin meet", children: [_jsx("defs", { children: _jsx("marker", { id: "dl-arrow", viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", className: "dl-arrowhead" }) }) }), layout.edges.map((e, i) => {
124
+ const p = path(e);
125
+ return (_jsxs("g", { className: `dl-edge ${e.kind} ${lit(e) ? "" : "dim"}`, children: [_jsx("title", { children: e.mode ? t("ui.deadlock_graph.edge_title_mode", { kind: e.kind, mode: e.mode }) : t("ui.deadlock_graph.edge_title", { kind: e.kind }) }), _jsx("path", { d: p.d, markerEnd: e.kind === "wants" ? "url(#dl-arrow)" : undefined }), _jsx("text", { x: p.mx, y: labelY.get(i), textAnchor: "middle", className: "dl-edge-label", children: edgeLabel(e) })] }, i));
126
+ }), deadlock.resources.map((r) => {
127
+ const b = layout.resBox.get(r.id);
128
+ const label = resourceLabel(r);
129
+ return (_jsxs("g", { className: `dl-res ${focus && focus !== r.id && !layout.edges.some((e) => e.res === r.id && e.proc === focus) ? "dim" : ""}`, tabIndex: 0, role: "button", "aria-label": t("ui.deadlock_graph.lock_label", { object: label.title, scope: label.sub }), onMouseEnter: () => setFocus(r.id), onMouseLeave: () => setFocus(null), onFocus: () => setFocus(r.id), onBlur: () => setFocus(null), children: [_jsx("title", { children: lockTitle(r, label) }), _jsx("rect", { x: b.x, y: b.y, width: b.w, height: b.h, rx: b.h / 2 }), _jsx("text", { x: b.x + b.w / 2, y: b.y + 20, textAnchor: "middle", className: "dl-res-title", children: clip(label.title, 22) }), _jsx("text", { x: b.x + b.w / 2, y: b.y + 36, textAnchor: "middle", className: "dl-res-sub", children: clip(label.sub, 26) })] }, r.id));
130
+ }), deadlock.processes.map((p) => {
131
+ const b = layout.procBox.get(p.id);
132
+ const meta = [p.application, p.login].filter(Boolean).join(" · ");
133
+ return (_jsxs("g", { className: `dl-proc ${p.victim ? "victim" : ""} ${focus && focus !== p.id && !layout.edges.some((e) => e.proc === p.id && e.res === focus) ? "dim" : ""}`, tabIndex: 0, role: "button", "aria-label": processLabel(p), onMouseEnter: () => setFocus(p.id), onMouseLeave: () => setFocus(null), onFocus: () => setFocus(p.id), onBlur: () => setFocus(null), onClick: () => onPick?.(p), onKeyDown: (e) => e.key === "Enter" && onPick?.(p), children: [_jsx("title", { children: p.statement ?? who(p) }), _jsx("rect", { x: b.x, y: b.y, width: b.w, height: b.h, rx: 9 }), _jsx("text", { x: b.x + 12, y: b.y + 21, className: "dl-proc-title", children: who(p) }), p.victim && (_jsxs("g", { className: "dl-victim-tag", children: [_jsx("rect", { x: b.x + b.w - 84, y: b.y + 9, width: 74, height: 17, rx: 8.5 }), _jsx("text", { x: b.x + b.w - 47, y: b.y + 21, textAnchor: "middle", children: t("ui.deadlock_graph.rolled_back") })] })), _jsx("text", { x: b.x + 12, y: b.y + 38, className: "dl-proc-meta", children: clip(meta || p.host || "", 26) }), _jsx("text", { x: b.x + 12, y: b.y + 56, className: "dl-proc-sql", children: clip(p.statement ?? "", 25) })] }, p.id));
134
+ })] }), showLegend && (_jsxs("figcaption", { className: "dl-legend", children: [_jsxs("span", { children: [_jsx("i", { className: "dl-key holds" }), " ", t("ui.deadlock_graph.edge", { kind: "holds" })] }), _jsxs("span", { children: [_jsx("i", { className: "dl-key wants" }), " ", t("ui.deadlock_graph.edge", { kind: "wants" })] }), _jsx("span", { className: "muted", children: t("ui.deadlock_graph.hint") })] }))] }));
135
+ }
@@ -0,0 +1,20 @@
1
+ import { type ReactNode } from "react";
2
+ import type { PlanViewerTheme } from "./PlanViewer.js";
3
+ import type { Deadlock, DeadlockFix, DeadlockPattern } from "./types.js";
4
+ export declare function deadlockPatternLabel(pattern: DeadlockPattern): string;
5
+ export declare function deadlockWhen(iso: string | null): {
6
+ short: string;
7
+ full: string;
8
+ };
9
+ export type DeadlockViewerProps = {
10
+ deadlock: Deadlock;
11
+ /** Optional renderer for linking a deadlock fix to a host finding card. */
12
+ renderRelatedFinding?: (fix: DeadlockFix) => ReactNode;
13
+ theme?: PlanViewerTheme;
14
+ className?: string;
15
+ };
16
+ /**
17
+ * Complete deadlock investigation view: pattern classification, timestamp, interactive lock-cycle SVG graph,
18
+ * plain-language explanation, numbered SQL fixes, and involved session/process cards.
19
+ */
20
+ export declare function DeadlockViewer({ deadlock, renderRelatedFinding, theme, className }: DeadlockViewerProps): import("react").JSX.Element;
@@ -0,0 +1,62 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Copy } from "lucide-react";
3
+ import { useRef } from "react";
4
+ import { DeadlockGraph } from "./DeadlockGraph.js";
5
+ import { copyAndTell, dateLocale, t } from "./host.js";
6
+ import { Sql } from "./Sql.js";
7
+ export function deadlockPatternLabel(pattern) {
8
+ switch (pattern) {
9
+ case "key-lookup":
10
+ return t("ui.deadlocks.pattern.key_lookup");
11
+ case "lock-conversion":
12
+ return t("ui.deadlocks.pattern.lock_conversion");
13
+ case "opposite-order":
14
+ return t("ui.deadlocks.pattern.opposite_order");
15
+ case "lock-escalation":
16
+ return t("ui.deadlocks.pattern.lock_escalation");
17
+ case "parallelism":
18
+ return t("ui.deadlocks.pattern.parallelism");
19
+ case "cycle":
20
+ return t("ui.deadlocks.pattern.cycle");
21
+ }
22
+ }
23
+ export function deadlockWhen(iso) {
24
+ if (!iso)
25
+ return { short: t("ui.deadlocks.time_unknown"), full: t("ui.deadlocks.time_unknown_full") };
26
+ const d = new Date(iso);
27
+ if (Number.isNaN(d.getTime()))
28
+ return { short: iso, full: iso };
29
+ const today = new Date();
30
+ const sameDay = d.toDateString() === today.toDateString();
31
+ const loc = dateLocale();
32
+ const time = d.toLocaleTimeString(loc, { hour: "numeric", minute: "2-digit" });
33
+ const short = sameDay
34
+ ? t("ui.deadlocks.today", { time })
35
+ : t("ui.format.when.this_year", { date: d.toLocaleDateString(loc, { month: "short", day: "numeric" }), time });
36
+ return { short, full: d.toLocaleString(loc) };
37
+ }
38
+ /**
39
+ * Complete deadlock investigation view: pattern classification, timestamp, interactive lock-cycle SVG graph,
40
+ * plain-language explanation, numbered SQL fixes, and involved session/process cards.
41
+ */
42
+ export function DeadlockViewer({ deadlock, renderRelatedFinding, theme, className }) {
43
+ const rootRef = useRef(null);
44
+ const at = deadlockWhen(deadlock.at);
45
+ const handlePickProcess = (p) => {
46
+ const reduce = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
47
+ rootRef.current?.querySelector(`[data-proc-id="${p.id}"]`)?.scrollIntoView({ block: "nearest", behavior: reduce ? "auto" : "smooth" });
48
+ };
49
+ return (_jsxs("article", { ref: rootRef, className: `culprit-pv dl-detail ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [_jsxs("div", { className: "dl-detail-meta", children: [_jsx("span", { className: "dl-pattern", children: deadlockPatternLabel(deadlock.pattern) }), _jsx("span", { className: "muted", title: at.full, children: deadlock.source === "pasted"
50
+ ? deadlock.at
51
+ ? `${at.short} · ${t("ui.deadlocks.pasted")}`
52
+ : t("ui.deadlocks.pasted")
53
+ : `${at.short} · ${deadlock.source}` })] }), _jsx("h2", { className: "dl-headline", children: deadlock.headline }), _jsx(DeadlockGraph, { deadlock: deadlock, onPick: handlePickProcess }), _jsx("p", { className: "dl-explain", children: deadlock.explanation }), deadlock.fixes.length > 0 && (_jsxs(_Fragment, { children: [_jsx("h3", { className: "dl-section", children: t("ui.deadlocks.how_to_fix") }), _jsx("ol", { className: "dl-fixes", children: deadlock.fixes.map((f, i) => (_jsxs("li", { className: "dl-fix", children: [_jsx("div", { className: "dl-fix-title", children: f.title }), _jsx("p", { children: f.detail }), f.sql && (_jsxs("div", { className: "dl-fix-sql", children: [_jsx(Sql, { text: f.sql, pretty: false }), _jsxs("button", { type: "button", className: "btn ghost small", onClick: () => copyAndTell(f.sql, t("ui.common.copied")), "aria-label": t("ui.deadlocks.copy_sql"), children: [_jsx(Copy, { size: 12 }), " ", t("ui.common.copy")] })] })), renderRelatedFinding?.(f)] }, i))) })] })), _jsx("h3", { className: "dl-section", children: t("ui.deadlocks.involved") }), _jsx("div", { className: "dl-procs", children: deadlock.processes.map((p) => (_jsxs("div", { id: `dl-proc-${p.id}`, "data-proc-id": p.id, className: `dl-proc-card ${p.victim ? "victim" : ""}`, children: [_jsxs("div", { className: "dl-proc-head", children: [_jsx("strong", { children: p.session ? t("ui.deadlocks.session", { session: p.session }) : t("ui.deadlocks.process", { id: p.id }) }), p.victim && _jsx("span", { className: "pill victim", children: t("ui.deadlocks.rolled_back") })] }), _jsx("div", { className: "dl-proc-facts muted", children: [
54
+ p.application,
55
+ p.login && p.host ? `${p.login}@${p.host}` : (p.login ?? p.host),
56
+ p.isolation,
57
+ p.wait_mode ? t("ui.deadlocks.wanted", { mode: p.wait_mode }) : null,
58
+ p.procedure ? t("ui.deadlocks.in_procedure", { procedure: p.procedure }) : null,
59
+ ]
60
+ .filter(Boolean)
61
+ .join(" · ") }), p.statement ? _jsx(Sql, { text: p.statement, className: "dl-proc-sql" }) : _jsx("p", { className: "muted", children: t("ui.deadlocks.no_statement") })] }, p.id))) })] }));
62
+ }
@@ -0,0 +1,7 @@
1
+ import type { DocdbMetrics } from "./types.js";
2
+ /** Native storage entries and RPCs retain their units; they are never PostgreSQL pages or CPU utilization. */
3
+ export declare function DocdbWork({ metrics, basis, runs }: {
4
+ metrics?: DocdbMetrics | null;
5
+ basis: "execution" | "loop" | "workload";
6
+ runs?: number;
7
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { count, duration, t } from "./host.js";
3
+ /** Native storage entries and RPCs retain their units; they are never PostgreSQL pages or CPU utilization. */
4
+ export function DocdbWork({ metrics, basis, runs }) {
5
+ if (!metrics)
6
+ return null;
7
+ const divisor = basis === "workload" && runs != null && runs > 0 ? runs : 1;
8
+ const said = basis === "workload" ? (runs != null && runs > 0 ? "per_run" : "retained") : basis === "loop" ? "per_loop" : "execution";
9
+ const entries = [
10
+ ["read_requests", t("ui.docdb_work.read_requests"), "count"],
11
+ ["write_requests", t("ui.docdb_work.write_requests"), "count"],
12
+ ["read_operations", t("ui.docdb_work.read_operations"), "count"],
13
+ ["write_operations", t("ui.docdb_work.write_operations"), "count"],
14
+ ["rows_scanned", t("ui.docdb_work.rows_scanned"), "count"],
15
+ ["rows_returned", t("ui.docdb_work.rows_returned"), "count"],
16
+ ["read_ms", t("ui.docdb_work.read_ms"), "time"],
17
+ ["write_ms", t("ui.docdb_work.write_ms"), "time"],
18
+ ["wait_ms", t("ui.docdb_work.wait_ms"), "time"],
19
+ ["catalog_ms", t("ui.docdb_work.catalog_ms"), "time"],
20
+ ["retries", t("ui.docdb_work.retries"), "count"],
21
+ ["conflict_retries", t("ui.docdb_work.conflict_retries"), "count"],
22
+ ["read_restarts", t("ui.docdb_work.read_restarts"), "count"],
23
+ ["obsolete_rows_scanned", t("ui.docdb_work.obsolete_rows_scanned"), "count"],
24
+ ["seeks", t("ui.docdb_work.seeks"), "count"],
25
+ ["nexts", t("ui.docdb_work.nexts"), "count"],
26
+ ["prevs", t("ui.docdb_work.prevs"), "count"],
27
+ ];
28
+ const rows = entries.flatMap(([key, title, unit]) => {
29
+ const value = metrics[key];
30
+ return value == null || !Number.isFinite(value) || value < 0
31
+ ? []
32
+ : [{ key, title, value: unit === "time" ? duration(value / divisor) : count(value / divisor) }];
33
+ });
34
+ if (rows.length === 0)
35
+ return null;
36
+ return (_jsxs("section", { className: "beyond", "aria-label": t("ui.docdb_work.title"), children: [_jsx("h3", { children: t("ui.docdb_work.title") }), _jsx("p", { className: "beyond-foot", children: t("ui.docdb_work.foot", { basis: said }) }), _jsx("div", { className: "beyond-rows", role: "list", children: rows.map((row) => (_jsxs("div", { className: "beyond-row", role: "listitem", children: [_jsx("i", { className: "sig-dot info", "aria-hidden": true }), _jsx("span", { className: "beyond-label", children: row.title }), _jsx("span", { className: "beyond-value", children: row.value })] }, row.key))) })] }));
37
+ }
@@ -0,0 +1,15 @@
1
+ import type { PlanViewerTheme } from "./PlanViewer.js";
2
+ import type { Plan, PlanInsight, PlanNode } from "./types.js";
3
+ /** One operator, explained: what it does, its rows, cost, buffers/I/O, parallelism, warnings, then raw properties on demand. */
4
+ export declare function NodeDetails({ plan, node, share, subtreeShare, noShare, insights, estimates, actual, theme, className, }: {
5
+ plan?: Plan;
6
+ node: PlanNode;
7
+ share: number | null;
8
+ subtreeShare?: number | null;
9
+ noShare?: string | null;
10
+ insights?: PlanInsight[];
11
+ estimates?: boolean;
12
+ actual?: boolean;
13
+ theme?: PlanViewerTheme;
14
+ className?: string;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,161 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronRight, Search, TriangleAlert } from "lucide-react";
3
+ import { Fragment, useMemo, useState } from "react";
4
+ import { DocdbWork } from "./DocdbWork.js";
5
+ import { cost, count, duration, estRowsForRuns, exact, misestimate, operatorRuns, operatorView, percent, propValue, shortPredicate, t } from "./host.js";
6
+ import { OpIcon } from "./OpIcon.js";
7
+ function warningLabel(warning) {
8
+ switch (warning) {
9
+ case "implicit-conversion":
10
+ return t("ui.node_details.warning.implicit_conversion");
11
+ case "spill":
12
+ return t("ui.node_details.warning.spill");
13
+ case "no-join-predicate":
14
+ return t("ui.node_details.warning.no_join_predicate");
15
+ case "missing-statistics":
16
+ return t("ui.node_details.warning.missing_statistics");
17
+ case "memory-grant":
18
+ return t("ui.node_details.warning.memory_grant");
19
+ case "misestimate":
20
+ return t("ui.node_details.warning.misestimate");
21
+ case "residual-predicate":
22
+ return t("ui.node_details.warning.residual_predicate");
23
+ default:
24
+ return warning;
25
+ }
26
+ }
27
+ const SHOWN = new Set([
28
+ "PhysicalOp",
29
+ "LogicalOp",
30
+ "EstimateRows",
31
+ "EstimatedRowsRead",
32
+ "TableCardinality",
33
+ "EstimatedTotalSubtreeCost",
34
+ "EstimateCPU",
35
+ "EstimateIO",
36
+ "ActualRows",
37
+ "ActualExecutions",
38
+ "ActualRowsRead",
39
+ "ActualLogicalReads",
40
+ "ActualPhysicalReads",
41
+ "ActualExecutionMode",
42
+ "EstimateRebinds",
43
+ "EstimateRewinds",
44
+ "OutputList",
45
+ "Rows Removed by Filter",
46
+ "Parent Relationship",
47
+ "Shared Hit Blocks",
48
+ "Shared Read Blocks",
49
+ "Shared Dirtied Blocks",
50
+ "Shared Written Blocks",
51
+ "Local Hit Blocks",
52
+ "Local Read Blocks",
53
+ "Temp Read Blocks",
54
+ "Temp Written Blocks",
55
+ "I/O Read Time",
56
+ "I/O Write Time",
57
+ "WAL Bytes",
58
+ "WAL Records",
59
+ "Workers Planned",
60
+ "Workers Launched",
61
+ "Sort Space Used",
62
+ ]);
63
+ const MAX_PAGE_SERVER_METRICS = 4;
64
+ const MAX_PAGE_SERVER_LIMITATIONS = 2;
65
+ function formatKb(kb) {
66
+ if (kb >= 1024 * 1024)
67
+ return `${(kb / 1024 / 1024).toFixed(1)}\u00a0GB`;
68
+ if (kb >= 1024)
69
+ return `${(kb / 1024).toFixed(kb >= 10 * 1024 ? 0 : 1)}\u00a0MB`;
70
+ return `${Math.round(kb)}\u00a0KB`;
71
+ }
72
+ function formatBytes(bytes) {
73
+ if (bytes >= 1024 * 1024 * 1024)
74
+ return `${(bytes / 1024 / 1024 / 1024).toFixed(1)}\u00a0GB`;
75
+ if (bytes >= 1024 * 1024)
76
+ return `${(bytes / 1024 / 1024).toFixed(1)}\u00a0MB`;
77
+ if (bytes >= 1024)
78
+ return `${(bytes / 1024).toFixed(1)}\u00a0KB`;
79
+ return `${Math.round(bytes)}\u00a0B`;
80
+ }
81
+ function uses8KbPages(engine) {
82
+ return engine === "postgres" || engine === "mssql" || engine === "yugabyte";
83
+ }
84
+ function formatPages(pages, engine) {
85
+ const base = exact(pages);
86
+ if (!uses8KbPages(engine) || pages <= 0)
87
+ return base;
88
+ return `${base} (${formatKb(pages * 8)})`;
89
+ }
90
+ function optNumber(raw) {
91
+ if (raw == null || raw.trim() === "")
92
+ return null;
93
+ const n = Number(raw);
94
+ return Number.isFinite(n) && n > 0 ? n : null;
95
+ }
96
+ function PageServerIoDetails({ view }) {
97
+ return (_jsxs("details", { className: "nd-all nd-page-server", children: [_jsxs("summary", { children: [_jsx(ChevronRight, { size: 13, className: "chev", "aria-hidden": "true" }), " ", t("view.plan_page_server_io.title")] }), _jsxs("div", { className: "nd-card nd-page-server-body", children: [_jsx("dl", { children: view.metrics.slice(0, MAX_PAGE_SERVER_METRICS).map((metric) => (_jsxs(Fragment, { children: [_jsx("dt", { children: metric.label }), _jsx("dd", { children: metric.text ?? t("view.plan_page_server_io.unknown") })] }, metric.key || metric.label))) }), view.limitations.slice(0, MAX_PAGE_SERVER_LIMITATIONS).map((limitation) => (_jsx("p", { className: "nd-page-server-limit muted", children: limitation }, limitation)))] })] }));
98
+ }
99
+ function ratio(plan, n) {
100
+ const factor = misestimate(plan, n);
101
+ if (factor == null || Math.abs(factor) < 2)
102
+ return null;
103
+ return (_jsx("span", { className: `nd-ratio ${n.warnings.includes("misestimate") ? "bad" : ""}`, children: factor > 0
104
+ ? t("ui.node_details.more_than_expected", { factor: exact(Math.round(Math.abs(factor))) })
105
+ : t("ui.node_details.fewer_than_expected", { factor: exact(Math.round(Math.abs(factor))) }) }));
106
+ }
107
+ /** One operator, explained: what it does, its rows, cost, buffers/I/O, parallelism, warnings, then raw properties on demand. */
108
+ export function NodeDetails({ plan, node, share, subtreeShare, noShare, insights = [], estimates = true, actual = false, theme, className, }) {
109
+ const [filter, setFilter] = useState("");
110
+ const props = useMemo(() => {
111
+ const q = filter.trim().toLowerCase();
112
+ return Object.entries(node.props)
113
+ .filter(([k, v]) => v != null && v !== "" && !SHOWN.has(k))
114
+ .filter(([k, v]) => !q || k.toLowerCase().includes(q) || v.toLowerCase().includes(q))
115
+ .sort(([a], [b]) => a.localeCompare(b));
116
+ }, [node, filter]);
117
+ const cpu = Number(node.props.EstimateCPU ?? NaN);
118
+ const io = Number(node.props.EstimateIO ?? NaN);
119
+ const split = Number.isFinite(cpu) && Number.isFinite(io) && cpu + io > 0 ? cpu / (cpu + io) : null;
120
+ const removed = node.props["Rows Removed by Filter"];
121
+ const executions = operatorRuns(plan, node) ?? 0;
122
+ const pageServerIo = operatorView(plan, node)?.page_server_io;
123
+ const rt = node.runtime;
124
+ const logicalReads = rt?.logical_reads ?? null;
125
+ const physicalReads = rt?.physical_reads ?? null;
126
+ const cachedReads = logicalReads != null && physicalReads != null ? Math.max(0, logicalReads - physicalReads) : null;
127
+ const hitShare = logicalReads != null && logicalReads > 0 && cachedReads != null ? cachedReads / logicalReads : null;
128
+ const spillPages = rt?.spill_pages != null && rt.spill_pages > 0 ? rt.spill_pages : null;
129
+ const cpuMs = rt?.cpu_ms ?? null;
130
+ const heapFetches = node.facts.heap_fetches != null && node.facts.heap_fetches > 0 ? node.facts.heap_fetches : null;
131
+ const sortSpaceKb = node.facts.sort_space_kb != null && node.facts.sort_space_kb > 0 ? node.facts.sort_space_kb : null;
132
+ const diskUsageKb = node.facts.disk_usage_kb != null && node.facts.disk_usage_kb > 0 ? node.facts.disk_usage_kb : null;
133
+ const ioReadMs = optNumber(node.props["I/O Read Time"]);
134
+ const ioWriteMs = optNumber(node.props["I/O Write Time"]);
135
+ const walBytes = optNumber(node.props["WAL Bytes"]);
136
+ const execMode = node.facts.actual_execution_mode ?? null;
137
+ const hasIoCard = logicalReads != null ||
138
+ physicalReads != null ||
139
+ spillPages != null ||
140
+ cpuMs != null ||
141
+ heapFetches != null ||
142
+ sortSpaceKb != null ||
143
+ diskUsageKb != null ||
144
+ ioReadMs != null ||
145
+ ioWriteMs != null ||
146
+ walBytes != null ||
147
+ execMode != null;
148
+ const workersPlanned = node.facts.workers_planned ?? null;
149
+ const workersLaunched = node.facts.workers_launched ?? null;
150
+ const threadRows = rt?.thread_rows ?? [];
151
+ const maxWorkerRows = threadRows.length > 0 ? Math.max(1, ...threadRows) : 1;
152
+ const hasParallelCard = workersPlanned != null || workersLaunched != null || threadRows.length > 1;
153
+ return (_jsxs("div", { className: `culprit-pv nd ${className ?? ""}`, "data-theme": theme && theme !== "system" ? theme : undefined, children: [_jsxs("div", { className: "nd-head", children: [_jsx("span", { className: "nd-icon", children: _jsx(OpIcon, { node: node, size: 16 }) }), _jsxs("div", { className: "nd-title", children: [_jsxs("div", { className: "nd-op", children: [node.op, node.detail && _jsx("span", { className: "nd-detail", children: node.detail })] }), (node.object || node.index) && (_jsxs("div", { className: "nd-obj mono", children: [node.object, node.index && _jsxs("span", { className: "muted", children: [" \u00B7 ", node.index] })] }))] }), estimates &&
154
+ (share != null ? (_jsxs("span", { className: "nd-share", title: t("ui.node_details.share_hint"), children: [percent(share), _jsxs("span", { className: "muted", children: [" ", t("ui.node_details.of_the_work")] })] })) : (_jsx("span", { className: "nd-share muted", title: noShare ?? undefined, children: t("ui.node_details.no_share_of_work") })))] }), insights.length > 0 && (_jsx("ul", { className: "nd-insights", children: insights.map((i) => (_jsxs("li", { className: i.severity, children: [_jsx("i", {}), i.title] }, i.rule))) })), _jsx(DocdbWork, { metrics: node.facts.docdb, basis: "loop" }), _jsxs("div", { className: "nd-grid", children: [(node.seek_predicate || node.predicate) && (_jsxs("section", { className: "nd-card wide", children: [_jsx("h4", { children: t("ui.node_details.what_it_does") }), node.seek_predicate && (_jsxs("div", { className: "nd-cond", children: [_jsx("span", { className: "nd-k", children: node.kind === "seek" || node.kind === "lookup" ? t("ui.node_details.seeks_on") : t("ui.node_details.index_condition") }), _jsx("code", { children: shortPredicate(node.seek_predicate) })] })), node.predicate && (_jsxs("div", { className: "nd-cond", children: [_jsx("span", { className: "nd-k", children: t("ui.node_details.then_filters") }), _jsx("code", { children: shortPredicate(node.predicate) })] }))] })), estimates && (_jsxs("section", { className: "nd-card", children: [_jsx("h4", { children: t("ui.node_details.rows") }), _jsxs("dl", { children: [_jsx("dt", { children: t("ui.node_details.estimated") }), _jsx("dd", { title: node.act_executions != null ? t("ui.node_details.estimated_hint") : undefined, children: exact(estRowsForRuns(plan, node)) }), node.act_rows != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.actual") }), _jsxs("dd", { children: [exact(node.act_rows), " ", ratio(plan, node)] })] })), executions > 1 && (_jsxs(_Fragment, { children: [_jsx("dt", { children: node.act_executions != null ? t("ui.node_details.ran") : t("ui.node_details.expected_runs") }), _jsx("dd", { children: t("ui.node_details.times", { n: executions, count: exact(executions) }) })] })), node.rows_read != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: actual ? t("ui.node_details.read") : t("ui.node_details.expected_to_read") }), _jsx("dd", { children: exact(node.rows_read) })] })), removed && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.filtered_out") }), _jsx("dd", { children: propValue(removed) })] })), node.table_rows != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.in_table") }), _jsx("dd", { children: exact(node.table_rows) })] }))] })] })), estimates && (_jsxs("section", { className: "nd-card", children: [_jsx("h4", { children: t("ui.node_details.cost") }), _jsxs("dl", { children: [_jsx("dt", { children: t("ui.node_details.this_operator") }), _jsxs("dd", { children: [share != null ? percent(share) : t("ui.node_details.no_share"), " ", _jsxs("span", { className: "muted", children: ["\u00B7 ", plan?.facts.estimated_cost_unavailable ? t("ui.node_details.cost_unavailable") : t("ui.node_details.units", { cost: cost(node.self_cost) })] })] }), subtreeShare != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.with_inputs") }), _jsx("dd", { children: percent(subtreeShare) })] })), node.act_time_ms != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.actual_time") }), _jsx("dd", { children: duration(node.act_time_ms) })] }))] }), share == null && noShare && _jsx("p", { className: "muted", style: { margin: "6px 0 0", fontSize: 12 }, children: noShare }), split != null && (_jsxs("div", { className: "nd-split", title: t("ui.node_details.split_hint", { cpu: percent(split), io: percent(1 - split) }), children: [_jsxs("div", { className: "nd-split-bar", children: [_jsx("span", { className: "cpu", style: { width: `${split * 100}%` } }), _jsx("span", { className: "io", style: { width: `${(1 - split) * 100}%` } })] }), _jsxs("div", { className: "nd-split-legend", children: [_jsxs("span", { children: [_jsx("i", { className: "cpu" }), t("ui.node_details.cpu_share", { share: percent(split) })] }), _jsxs("span", { children: [_jsx("i", { className: "io" }), t("ui.node_details.io_share", { share: percent(1 - split) })] })] })] }))] })), hasIoCard && (_jsxs("section", { className: "nd-card", children: [_jsx("h4", { children: t("ui.node_details.io_buffers") }), _jsxs("dl", { children: [logicalReads != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.logical_reads") }), _jsx("dd", { children: formatPages(logicalReads, plan?.engine) })] })), cachedReads != null && cachedReads > 0 && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.from_cache") }), _jsx("dd", { children: formatPages(cachedReads, plan?.engine) })] })), physicalReads != null && physicalReads > 0 && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.from_disk") }), _jsx("dd", { children: formatPages(physicalReads, plan?.engine) })] })), spillPages != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.spill_pages") }), _jsx("dd", { children: _jsx("span", { className: "nd-ratio bad", children: formatPages(spillPages, plan?.engine) }) })] })), sortSpaceKb != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.sort_memory") }), _jsx("dd", { children: formatKb(sortSpaceKb) })] })), diskUsageKb != null && sortSpaceKb == null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.work_memory") }), _jsx("dd", { children: formatKb(diskUsageKb) })] })), heapFetches != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.heap_fetches") }), _jsx("dd", { children: exact(heapFetches) })] })), cpuMs != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.cpu_time") }), _jsx("dd", { children: duration(cpuMs) })] })), ioReadMs != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.io_read_time") }), _jsx("dd", { children: duration(ioReadMs) })] })), ioWriteMs != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.io_write_time") }), _jsx("dd", { children: duration(ioWriteMs) })] })), walBytes != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.wal_bytes") }), _jsx("dd", { children: formatBytes(walBytes) })] })), execMode != null && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.execution_mode") }), _jsx("dd", { children: execMode.kind === "batch"
155
+ ? t("ui.node_details.mode_batch")
156
+ : execMode.kind === "row"
157
+ ? t("ui.node_details.mode_row")
158
+ : execMode.value })] }))] }), hitShare != null && (_jsxs("div", { className: "nd-split", children: [_jsxs("div", { className: "nd-split-bar", children: [_jsx("span", { className: "hit", style: { width: `${hitShare * 100}%` } }), _jsx("span", { className: "disk", style: { width: `${(1 - hitShare) * 100}%` } })] }), _jsxs("div", { className: "nd-split-legend", children: [_jsxs("span", { children: [_jsx("i", { className: "hit" }), t("ui.node_details.cache_hit_share", { share: percent(hitShare) })] }), _jsxs("span", { children: [_jsx("i", { className: "disk" }), t("ui.node_details.disk_read_share", { share: percent(1 - hitShare) })] })] })] }))] })), hasParallelCard && (_jsxs("section", { className: "nd-card", children: [_jsx("h4", { children: t("ui.node_details.parallelism") }), _jsx("dl", { children: (workersLaunched != null || workersPlanned != null) && (_jsxs(_Fragment, { children: [_jsx("dt", { children: t("ui.node_details.workers_launched") }), _jsx("dd", { children: workersLaunched != null && workersPlanned != null
159
+ ? t("ui.node_details.workers_of_planned", { launched: String(workersLaunched), planned: String(workersPlanned) })
160
+ : String(workersLaunched ?? workersPlanned) })] })) }), threadRows.length > 1 && (_jsx("div", { className: "nd-workers", children: threadRows.slice(0, 8).map((wRows, idx) => (_jsxs("div", { className: "nd-worker-row", children: [_jsx("span", { className: "muted", children: t("ui.node_details.worker_rows", { worker: String(idx + 1) }) }), _jsx("span", { className: "nd-worker-bar", children: _jsx("span", { style: { width: `${Math.max(3, (wRows / maxWorkerRows) * 100)}%` } }) }), _jsx("span", { className: "num", children: count(wRows) })] }, idx))) }))] })), node.warnings.length > 0 && (_jsxs("section", { className: "nd-card nd-warn", children: [_jsxs("h4", { children: [_jsx(TriangleAlert, { size: 12 }), " ", t("ui.node_details.warnings")] }), _jsx("ul", { children: node.warnings.map((w) => (_jsx("li", { children: warningLabel(w) }, w))) })] }))] }), pageServerIo && _jsx(PageServerIoDetails, { view: pageServerIo }, node.id), Object.keys(node.props).length > 0 && (_jsxs("details", { className: "nd-all", children: [_jsxs("summary", { children: [_jsx(ChevronRight, { size: 13, className: "chev" }), " ", t("ui.node_details.all_properties"), " ", _jsx("span", { className: "muted", children: props.length })] }), _jsxs("label", { className: "search nd-search", children: [_jsx(Search, { size: 12 }), _jsx("input", { value: filter, placeholder: t("ui.node_details.find_property"), onChange: (e) => setFilter(e.target.value) })] }), _jsx("dl", { className: "nd-props", children: props.map(([k, v]) => (_jsxs("div", { className: "nd-prop", children: [_jsx("dt", { children: k }), _jsx("dd", { title: v.length > 80 ? v : undefined, children: propValue(v) })] }, k))) })] }))] }));
161
+ }