extended-statistics

Analyze and implement PostgreSQL extended statistics for correlated columns and expressions.

Updated Jun 1, 2026
One-click install
npx skills add https://github.com/matejformanek/postgres-claude --skill extended-statistics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: extended-statistics
Source: https://github.com/matejformanek/postgres-claude/tree/main/.claude/skills/extended-statistics
Command: npx skills add https://github.com/matejformanek/postgres-claude --skill extended-statistics

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses inaccurate query planner estimates caused by correlated columns or complex expressions, which often lead to suboptimal execution plans and poor database performance.

Core Features & Use Cases

  • Extended Statistics Management: Provides deep insights into dependencies, multi-column MCV lists, and expression statistics.
  • Planner Tuning: Helps identify why the planner fails to account for correlations between columns like city and state or complex function results.
  • Use Case: When a query involving multiple correlated filters performs a sequential scan instead of an index scan, use this skill to analyze and implement the correct extended statistics to guide the planner toward a more efficient execution path.

Quick Start

Use the extended-statistics skill to diagnose why the planner is producing incorrect row estimates for the correlated columns in the current table.

Frequently Asked Questions about extended-statistics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does the PostgreSQL planner choose a sequential scan instead of an index scan for correlated columns?

PostgreSQL planner sequential scans on correlated columns occur because default statistics miss data correlations, causing inaccurate selectivity estimates; extended statistics like functional dependencies and multi-column MCV lists correct these row estimates to guide the planner toward index scans.

How do I improve query planner selectivity estimates for complex PostgreSQL expressions?

To improve PostgreSQL query planner selectivity estimates for complex expressions, implement extended statistics using ndistinct and multi-column MCV lists to help the optimizer account for correlations within the clauselist_selectivity path.

What are PostgreSQL extended statistics and when do I need them?

PostgreSQL extended statistics are optimizer metadata objects that track correlations between multiple columns or complex expressions; you need them when standard per-column statistics produce poor query execution plans for multi-column filters.

How do I create multi-column MCV lists and ndistinct statistics in PostgreSQL?

Creating multi-column MCV lists and ndistinct statistics in PostgreSQL involves defining objects in the pg_statistic_ext catalog to analyze correlated columns, which updates the planner's selectivity estimates for complex query filters.

What are the limitations of using extended statistics for PostgreSQL query optimization?

Limitations of PostgreSQL extended statistics for query optimization include overhead in statistics collection and dependency on the clauselist_selectivity path, meaning they only improve estimates for specific correlated clauses rather than fixing all planner inaccuracies.