CodeBlanks Logo Icon CodeBlanks

Statistics

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ür

This 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

query.sql
-- gather statistics
ANALYZE

Sample solution

query.sql
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

Question
ANALYZE ____
Answer
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

All lessons in Expert