Bird
0
0

You want to improve performance for a report that aggregates sales by month from a large sales table. Which approach is best?

hard📝 optimization Q8 of 15
PostgreSQL - Performance Tuning
You want to improve performance for a report that aggregates sales by month from a large sales table. Which approach is best?
ACreate a materialized view that pre-aggregates sales by month and refresh it regularly
BRun the aggregation query directly on the large table every time
CDelete old sales data to reduce table size
DCreate an index on the sales amount column
Step-by-Step Solution
Solution:
  1. Step 1: Understand aggregation cost on large tables

    Aggregating large data repeatedly is slow and resource-heavy.
  2. Step 2: Use materialized views for pre-computation

    Materialized views store pre-aggregated results, speeding up report queries.
  3. Final Answer:

    Create a materialized view that pre-aggregates sales by month and refresh it regularly -> Option A
  4. Quick Check:

    Materialized views = faster repeated aggregations [OK]
Quick Trick: Use materialized views to speed up repeated aggregations [OK]
Common Mistakes:
  • Running aggregation every time slows queries
  • Deleting data loses valuable info
  • Index on amount doesn't help aggregation speed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes