Statistics
- SQL course
- Expert
- Lesson 14/45
- 5 min
Learn statistics and histograms.
Statistics
Statistics are table and column facts the optimizer uses to choose a plan. They include row count, most common values (MCV) and a histogram.
ANALYZE orders;
-- pg_stats görünümünde histogram görünürThis query statistics drive plan choice.
Statistics — details
A histogram splits column values into equal-width buckets. It reflects skewed data correctly and prevents wrong plans.
Practice Statistics
Refresh statistics for the orders table: ANALYZE orders.
Starter code
-- gather statistics
ANALYZESample solution
ANALYZE orders;Expected output
ANALYZE
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Gather statistics
ANALYZE ____
ANALYZE orders
Explanation: ANALYZE orders collects the table's statistics; the optimizer picks plans based on them.
2 What does the optimizer use?
- A procedure
- A trigger
- A view
- Statistics Correct answer
Explanation: The optimizer uses statistics.
3 Statistics: match the terms
| Term | Meaning |
|---|---|
statistics |
statistics |
histogram |
histogram |
MCV |
most common |
skewed |
skewed |