Indexes & Query Planning
PostgreSQL offers B-tree, GIN, GiST, SP-GiST, BRIN and hash indexes, and a cost-based planner chooses among them from statistics. Interviewers hand you EXPLAIN ANALYZE and ask why.
part ofPostgreSQLread it →on this pageshowhide
explore
- Access Methods18 questions
- B-Tree Specifics6 questions
- GIN, GiST & BRIN6 questions
- Concurrent Builds & Upkeep6 questions
- Choosing a Plan15 questions
- EXPLAIN ANALYZE Output4 questions
- Planner Statistics5 questions
- Cost Knobs & Parallelism6 questions
questions
page 2 of 2In PostgreSQL, what does B-tree deduplication do, and why can adding INCLUDE (price) to an index on books(category_id) make it much larger?
basics
~20 sDeduplication stores a repeated key once with a sorted list of heap TIDs, shrinking low-cardinality B-trees. It is on by default but never used in INCLUDE indexes, so adding INCLUDE (price) turns every row back into a full index tuple.
In PostgreSQL, how do join_collapse_limit, from_collapse_limit and geqo_threshold bound join-order search, and when would you set join_collapse_limit to 1?
basics
~20 sfrom_collapse_limit and join_collapse_limit (both 8) stop subqueries and explicit JOINs merging into one larger search; join problems of geqo_threshold (12) items or more go to the genetic optimizer. join_collapse_limit = 1 joins explicit JOINs in written order.
On a 600-million-row PostgreSQL delivery_addresses table, pg_stats.n_distinct for customer_id is far below the true count; why does ANALYZE miss it, and how do you fix it durably?
basics
~20 sANALYZE extrapolates distinct counts from about 30,000 sampled rows, which fails on huge tables. Measure the true ratio once, set ALTER TABLE ... ALTER COLUMN customer_id SET (n_distinct = -0.05), then ANALYZE; later ANALYZEs keep that override.
showing 31–33 of 33