pgexplain 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -125,6 +125,10 @@ interface PlanNode {
125
125
  diskUsage?: number;
126
126
  exactHeapBlocks?: number;
127
127
  lossyHeapBlocks?: number;
128
+ cacheHits?: number;
129
+ cacheMisses?: number;
130
+ cacheEvictions?: number;
131
+ cacheOverflows?: number;
128
132
  sharedHitBlocks?: number;
129
133
  sharedReadBlocks?: number;
130
134
  sharedDirtiedBlocks?: number;
@@ -137,11 +141,23 @@ interface PlanNode {
137
141
  ioWriteTime?: number;
138
142
  workersPlanned?: number;
139
143
  workersLaunched?: number;
144
+ /** Per-worker actuals (EXPLAIN ANALYZE VERBOSE). */
145
+ workers?: WorkerStat[];
146
+ walRecords?: number;
147
+ walBytes?: number;
148
+ walFpi?: number;
140
149
  children: PlanNode[];
141
150
  metrics: NodeMetrics;
142
151
  /** Original JSON node — rules may read rare fields not normalized above. */
143
152
  raw: RawPlan;
144
153
  }
154
+ interface WorkerStat {
155
+ number: number;
156
+ actualRows?: number;
157
+ actualLoops?: number;
158
+ actualStartupTime?: number;
159
+ actualTotalTime?: number;
160
+ }
145
161
  interface JitInfo {
146
162
  functions?: number;
147
163
  timing?: {
@@ -163,6 +179,8 @@ interface PlanTree {
163
179
  root: PlanNode;
164
180
  planningTime?: number;
165
181
  executionTime?: number;
182
+ /** Result-serialization time in ms (PG17+ EXPLAIN ANALYZE SERIALIZE). */
183
+ serializationTime?: number;
166
184
  triggers: TriggerInfo[];
167
185
  jit?: JitInfo;
168
186
  settings?: Record<string, string>;
@@ -184,6 +202,8 @@ interface Thresholds {
184
202
  jitPct: number;
185
203
  triggerPct: number;
186
204
  lowCacheHitRatio: number;
205
+ limitDiscardRows: number;
206
+ staleStatsModRatio: number;
187
207
  }
188
208
  interface AnalysisContext {
189
209
  tree: PlanTree;
@@ -250,6 +270,11 @@ declare function bottlenecks(tree: PlanTree, n?: number): PlanNode[];
250
270
  /** A short human label for a node, e.g. "Seq Scan on orders". */
251
271
  declare function nodeLabel(node: PlanNode): string;
252
272
 
273
+ /**
274
+ * Parse EXPLAIN input into one PlanTree per statement, auto-detecting the format:
275
+ * JSON (`[`/`{`) → parseExplainJson, otherwise plain-text `EXPLAIN` output.
276
+ */
277
+ declare function parseExplain(input: string): PlanTree[];
253
278
  /**
254
279
  * Parse EXPLAIN (FORMAT JSON) text into one PlanTree per statement.
255
280
  * Accepts the standard `[{ "Plan": … }]`, a bare statement object, or a bare plan node.
@@ -294,6 +319,8 @@ declare class AppError extends Error {
294
319
  readonly exitCode: ExitCode;
295
320
  constructor(diagnostic: Diagnostic, exitCode: ExitCode, cause?: unknown);
296
321
  }
322
+ /** True when `s` is at least as severe as `threshold` (error ≥ warn ≥ info). */
323
+ declare function severityAtLeast(s: Severity, threshold: Severity): boolean;
297
324
  /**
298
325
  * Remove secrets from any string before it is logged, shown, or written.
299
326
  * Targets:
@@ -304,6 +331,13 @@ declare class AppError extends Error {
304
331
  */
305
332
  declare function scrubCredentials(input: string): string;
306
333
 
334
+ /**
335
+ * Static lock analysis from the SQL text (+ optional plan). PostgreSQL's EXPLAIN
336
+ * does not show locks, so these findings come from the statement shape and node
337
+ * types. Each is an actionable Diagnostic with a PGX_LOCK_* code.
338
+ */
339
+ declare function analyzeLocks(sql: string, tree?: PlanTree): Diagnostic[];
340
+
307
341
  /** Bump on any breaking change to the JSON shape. Consumers can assert on it. */
308
342
  declare const JSON_SCHEMA_VERSION = 1;
309
343
 
@@ -328,8 +362,10 @@ interface AnalyzeOptions {
328
362
  statement?: number;
329
363
  /** Strip literal values from expressions before analysis (no data leaks downstream). */
330
364
  redact?: boolean;
365
+ /** The originating SQL — enables lock analysis (PGX_LOCK_* findings). */
366
+ sql?: string;
331
367
  }
332
- /** Parse → (redact) → compute metrics → run advisor → attach informational notices. */
368
+ /** Parse → (redact) → compute metrics → run advisor (+lock advisor) → attach notices. */
333
369
  declare function analyze(input: string, options?: AnalyzeOptions): AnalysisResult;
334
370
 
335
- export { type AnalysisContext, type AnalysisResult, type AnalyzeOptions, AppError, DEFAULT_CONFIG, DEFAULT_THRESHOLDS, type Diagnostic, type DiagnosticLocation, type Domain, ExitCode, FORMATS, type Format, JSON_SCHEMA_VERSION, type JitInfo, type NodeMetrics, type PgExplainConfig, type PlanNode, type PlanTree, type RawPlan, type Remediation, type RemediationCommand, type RenderOptions, type Rule, type Severity, type Thresholds, type TriggerInfo, analyze, bottlenecks, computeMetrics, executionMs, flatten, isFormat, nodeLabel, parseExplainJson, render, runAdvisor, scrubCredentials, walk };
371
+ export { type AnalysisContext, type AnalysisResult, type AnalyzeOptions, AppError, DEFAULT_CONFIG, DEFAULT_THRESHOLDS, type Diagnostic, type DiagnosticLocation, type Domain, ExitCode, FORMATS, type Format, JSON_SCHEMA_VERSION, type JitInfo, type NodeMetrics, type PgExplainConfig, type PlanNode, type PlanTree, type RawPlan, type Remediation, type RemediationCommand, type RenderOptions, type Rule, type Severity, type Thresholds, type TriggerInfo, type WorkerStat, analyze, analyzeLocks, bottlenecks, computeMetrics, executionMs, flatten, isFormat, nodeLabel, parseExplain, parseExplainJson, render, runAdvisor, scrubCredentials, severityAtLeast, walk };