Contact us
Insights

Choosing a partition key

Partitioning splits large tables into manageable parts. How to choose a key that speeds up loads and queries instead of slowing them.

The problem

Big tables slow everything down

As transaction tables grow into hundreds of millions of rows, loads take longer, reports slow down, and reloading a single day means touching the whole table. Partitioning splits a table by a key, such as month, so the database can load, query, and archive one part at a time. With the right key, that’s a big improvement. With the wrong one, every query has to search every part and it gets slower.

Criteria

What makes a good partition key

Used in most filters

The column most reports filter on, so queries only read the parts they need.

Matches how data is loaded

New data lands in one part, so loads and reloads touch as little as possible.

Never changes

A record shouldn’t have to move between parts after it’s loaded.

Gives even parts

Parts of roughly similar size, without one huge part and many tiny ones.

Choosing

How to choose a partition key

Step 1 of 4

  1. Find the reports and loads that take longest and what they filter on.

  2. See whether data arrives by day, by store, or in another pattern.

  3. Day, month, or year, based on data volume and how far back reports look.

  4. Measure load and query times on a partitioned copy before changing the live table.

Date is usually the answer

For most sales, order, and stock movement tables, the transaction date, partitioned by month, meets every criterion. For example: reloading last month replaces one part, reports for this quarter read three parts, and archiving old years is a quick swap. Don’t partition small tables at all; an index is usually enough.

Reports slowing as data grows?

Tell us which tables are growing and which reports are slow. A few lines are enough.

Tell us what’s not working