Conceptual
Login

The Heap: Where PostgreSQL Stores Rows, and What a ctid Points To

In PostgreSQL a table is stored as a heap: an unordered pile of pages, where a new row goes wherever there is room rather than into any sorted position. Each stored row version has an address called a ctid, which is simply a page number and a slot number inside that page, and every index entry ends with one of these addresses. Because the heap has no order of its own, a query with no usable index has only one option, which is to read every page of the pile, and that is exactly what a sequential scan does.

Questions this Concept answers

  • Why must a PostgreSQL query with no usable index read every page of a table?