Home / Function/ calculateSummary() — supabase Function Reference

calculateSummary() — supabase Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e8479e1a_684f_e89b_ec5c_39ea7bfa4ee4["calculateSummary()"]
  9441c419_825c_eb70_b2a5_2509ac4ef05d["ExplainVisualizer()"]
  9441c419_825c_eb70_b2a5_2509ac4ef05d -->|calls| e8479e1a_684f_e89b_ec5c_39ea7bfa4ee4
  style e8479e1a_684f_e89b_ec5c_39ea7bfa4ee4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/ExplainVisualizer/ExplainVisualizer.parser.ts lines 246–278

export function calculateSummary(tree: ExplainNode[]): ExplainSummary {
  const stats: ExplainSummary = {
    totalTime: 0,
    totalCost: 0,
    maxCost: 0,
    hasSeqScan: false,
    seqScanTables: [],
    hasIndexScan: false,
  }

  const traverse = (node: ExplainNode) => {
    if (node.actualTime) {
      stats.totalTime = Math.max(stats.totalTime, node.actualTime.end)
    }
    if (node.cost) {
      stats.maxCost = Math.max(stats.maxCost, node.cost.end)
    }
    const op = node.operation.toLowerCase()
    if (op.includes('seq scan')) {
      stats.hasSeqScan = true
      const tableMatch = node.details.match(/on\s+((?:"[^"]+"|[\w]+)(?:\.(?:"[^"]+"|[\w]+))*)/)
      if (tableMatch) stats.seqScanTables.push(tableMatch[1])
    }
    if (op.includes('index')) {
      stats.hasIndexScan = true
    }
    node.children.forEach(traverse)
  }
  tree.forEach(traverse)

  stats.totalCost = tree[0]?.cost?.end ?? 0
  return stats
}

Subdomains

Frequently Asked Questions

What does calculateSummary() do?
calculateSummary() is a function in the supabase codebase.
What calls calculateSummary()?
calculateSummary() is called by 1 function(s): ExplainVisualizer.

Analyze Your Own Codebase

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

Try Supermodel Free