Home / Function/ buildQueryExplanationPrompt() — supabase Function Reference

buildQueryExplanationPrompt() — supabase Function Reference

Architecture documentation for the buildQueryExplanationPrompt() function in QueryPerformance.ai.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  30f0a3ab_db83_7faa_cb69_e6f4d458b834["buildQueryExplanationPrompt()"]
  862166f4_4a42_1285_bc7d_cd62b193126e["QueryDetail()"]
  862166f4_4a42_1285_bc7d_cd62b193126e -->|calls| 30f0a3ab_db83_7faa_cb69_e6f4d458b834
  style 30f0a3ab_db83_7faa_cb69_e6f4d458b834 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/QueryPerformance/QueryPerformance.ai.ts lines 8–49

export function buildQueryExplanationPrompt(
  selectedRow: QueryPerformanceRow
): QueryExplanationPrompt {
  const metadata = [
    `Total Time: ${selectedRow.total_time.toLocaleString()}`,
    `Calls: ${selectedRow.calls.toLocaleString()}`,
    `Mean Time: ${selectedRow.mean_time.toLocaleString()}`,
    `Max Time: ${selectedRow.max_time.toLocaleString()}`,
    `Min Time: ${selectedRow.min_time.toLocaleString()}`,
    `Rows Read: ${selectedRow.rows_read.toLocaleString()}`,
    `Cache Hit Rate: ${selectedRow.cache_hit_rate.toLocaleString()}%`,
    `Role: ${selectedRow.rolname}`,
  ].join('\n')

  let additionalContext = ''
  if (selectedRow.index_advisor_result) {
    const indexResult = selectedRow.index_advisor_result

    if (indexResult.index_statements.length > 0) {
      additionalContext = `\n\nIndex Advisor Recommendations:\n${indexResult.index_statements.join('\n')}\n\nCost Analysis:\n- Startup Cost Before: ${indexResult.startup_cost_before}\n- Startup Cost After: ${indexResult.startup_cost_after}\n- Total Cost Before: ${indexResult.total_cost_before}\n- Total Cost After: ${indexResult.total_cost_after}`
    }
  }

  const prompt = `Analyze this database query and provide a brief, concise explanation:

**Performance Metrics:**
${metadata}

${additionalContext}

Provide a short response covering:
1. What the query does (1-2 sentences)
2. Performance assessment (good/concerning and why, keep it brief 2-3 sentences)
3. Actionable optimization suggestions (if any, keep it brief 2-3 sentences)

Keep your response concise and focused on actionable insights. We can continue the conversation if needed to get more details.`

  return {
    query: selectedRow.query,
    prompt,
  }
}

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free