Home / Function/ buildExplainPrompt() — supabase Function Reference

buildExplainPrompt() — supabase Function Reference

Architecture documentation for the buildExplainPrompt() function in ExplainVisualizer.ai.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  17c30479_66a8_9d4f_7c3b_d056cc949427["buildExplainPrompt()"]
  34099fbd_f8e3_b000_0086_6f2c8af63ba6["ExplainHeader()"]
  34099fbd_f8e3_b000_0086_6f2c8af63ba6 -->|calls| 17c30479_66a8_9d4f_7c3b_d056cc949427
  style 17c30479_66a8_9d4f_7c3b_d056cc949427 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/ExplainVisualizer/ExplainVisualizer.ai.ts lines 13–45

export function buildExplainPrompt({
  sql,
  explainPlanRows,
}: ExplainPromptInput): ExplainPromptOutput {
  const explainPlan = explainPlanRows.map((row) => row['QUERY PLAN']).join('\n')

  const prompt = `Explain this PostgreSQL EXPLAIN ANALYZE output in simple terms:

\`\`\`sql
${sql}
\`\`\`

\`\`\`
${explainPlan}
\`\`\`

Format your response with:

**What it does** - 1-2 sentences.

**How it runs** - Briefly explain the plan from bottom to top in plain English. Mention key operations (scans, joins, sorts) and why PostgreSQL chose them.

**Issues** - Identify bottlenecks: slowest steps, sequential scans on large tables, inefficient joins, missing indexes. Be specific with timings from the plan.

**Fixes** - 2-3 specific suggestions with CREATE INDEX statements if applicable.

Keep it concise. Focus on actionable insights.`

  return {
    query: sql,
    prompt,
  }
}

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free