Skip to Content
Course content

An introduction to the cost-based optimizer. This chapter details how PostgreSQL predicts the computational cost of a query before running it. Students will evaluate the system catalogs (pg_class, pg_statistic), analyze how ANALYZE gathers data distributions (histograms, MCVs), and calculate specific cost parameters (e.g., seq_page_cost, random_page_cost) explicitly dictate planner decisions.

Outside Reading

  • Official Docs: Chapter 75: How the Planner Uses Statistics. (A critical read on row estimation math).
  • GitHub Source: src/backend/optimizer/path/costsize.c. This is pure gold for students. Have them read the exact C formulas for cost_seqscan() and cost_index() to see how seq_page_cost and random_page_cost are mathematically applied.
  • GitHub Source: src/backend/commands/analyze.c. Review the Vitter's reservoir sampling algorithm used to sample rows.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.

Additional Resources
Join this Course to access resources