PrepCity

Data partitioning

Open the lab

By the last page, this is the design you will have built.

Lesson · 11 pages · about 9 min

Data partitioning

Split one huge table into one partition per day, and a query for one day reads one partition. See the planner skip the rest, and the filters that quietly stop it from skipping anything.

What it is
Partitioning stores one table as many smaller tables, each holding one range of a key such as the date. Queries still name the one table.
What it is for
A query for one day can skip every other day’s partition (partition pruning), and old days can be dropped whole instead of deleted row by row.
Use it when
For big tables that grow by date and are almost always asked about a date range: events, orders, logs, fact tables.
Not when
For small tables, or when queries rarely filter on the partition key: every query then reads every partition, plus the planning cost.

Words you’ll learn

  • Event
  • Fact table
  • Data warehouse
  • Dashboard
  • SQL
  • PostgreSQL
  • Query planner
  • Row
  • Partition
  • Disk

Page by page