Bird
0
0

Given this dbt model SQL snippet:

medium📝 Predict Output Q4 of 15
dbt - Performance Optimization

Given this dbt model SQL snippet:

select customer_id, sum(amount) as total_sales
from orders
group by customer_id

Which index would most improve query performance?

AIndex on customer_id column
BIndex on amount column
CIndex on total_sales column
DNo index needed
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the query's grouping column

    The query groups by customer_id, so indexing this column speeds grouping and aggregation.
  2. Step 2: Evaluate indexing other columns

    Indexing amount or total_sales (an alias) won't help grouping performance.
  3. Final Answer:

    Index on customer_id column -> Option A
  4. Quick Check:

    Group by column index = customer_id [OK]
Quick Trick: Index columns used in GROUP BY for faster aggregation [OK]
Common Mistakes:
MISTAKES
  • Indexing aggregated columns
  • Ignoring grouping columns
  • Assuming no index helps

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes