Home / Function/ createNode() — supabase Function Reference

createNode() — supabase Function Reference

Architecture documentation for the createNode() function in ExplainVisualizer.parser.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  0cb11d5b_0044_bc0f_7964_0620c11647b6["createNode()"]
  ac30de94_dc70_4332_43a2_049c7d7d4364["parseExplainOutput()"]
  ac30de94_dc70_4332_43a2_049c7d7d4364 -->|calls| 0cb11d5b_0044_bc0f_7964_0620c11647b6
  93e57136_8408_1a30_8bc5_29ea980e7ed2["parseFloatMetric()"]
  0cb11d5b_0044_bc0f_7964_0620c11647b6 -->|calls| 93e57136_8408_1a30_8bc5_29ea980e7ed2
  d1a7099d_f832_a488_93d1_865b5def8dc0["parseIntMetric()"]
  0cb11d5b_0044_bc0f_7964_0620c11647b6 -->|calls| d1a7099d_f832_a488_93d1_865b5def8dc0
  style 0cb11d5b_0044_bc0f_7964_0620c11647b6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/ExplainVisualizer/ExplainVisualizer.parser.ts lines 128–187

function createNode(
  operation: string,
  details: string | undefined,
  metrics: string | undefined,
  level: number,
  raw: string
): ExplainNode {
  const node: ExplainNode = {
    operation: operation.trim(),
    details: details?.trim() || '',
    level,
    children: [],
    raw,
  }

  if (metrics) {
    // Parse cost=start..end
    const costMatch = metrics.match(/cost=([\d.]+)\.\.([\d.]+)/)
    if (costMatch) {
      const start = parseFloatMetric(costMatch[1])
      const end = parseFloatMetric(costMatch[2])
      // Only set cost if both values are valid numbers
      if (start !== undefined && end !== undefined) {
        node.cost = { start, end }
      }
    }

    // Parse rows=N (estimated rows, always the first occurrence)
    const rowsMatch = metrics.match(/rows=(\d+)/)
    if (rowsMatch) {
      node.rows = parseIntMetric(rowsMatch[1])
    }

    // Parse width=N
    const widthMatch = metrics.match(/width=(\d+)/)
    if (widthMatch) {
      node.width = parseIntMetric(widthMatch[1])
    }

    // Parse actual time=start..end
    const actualTimeMatch = metrics.match(/actual time=([\d.]+)\.\.([\d.]+)/)
    if (actualTimeMatch) {
      const start = parseFloatMetric(actualTimeMatch[1])
      const end = parseFloatMetric(actualTimeMatch[2])
      // Only set actualTime if both values are valid numbers
      if (start !== undefined && end !== undefined) {
        node.actualTime = { start, end }
      }

      // When EXPLAIN ANALYZE is used, the second rows= value (after actual time) is the actual rows
      const actualTimePart = metrics.substring(metrics.indexOf('actual time='))
      const actualRowsMatch = actualTimePart.match(/rows=(\d+)/)
      if (actualRowsMatch) {
        node.actualRows = parseIntMetric(actualRowsMatch[1])
      }
    }
  }

  return node
}

Subdomains

Frequently Asked Questions

What does createNode() do?
createNode() is a function in the supabase codebase.
What does createNode() call?
createNode() calls 2 function(s): parseFloatMetric, parseIntMetric.
What calls createNode()?
createNode() is called by 1 function(s): parseExplainOutput.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free