accesspatterns.dev

One key, every level

A path in the sort key lets one begins_with read any level of a hierarchy.

Why

These weather stations live in one partition, with a sort key that encodes a path: country, then state, then city, joined by a delimiter. Because the partition is stored sorted, every station in a country sits together, and within it every station in a state sits together.

So one begins_with reads any level of the tree. A US# prefix gives a country, US#CA# narrows to a state, and the full path is a single city. No FilterExpression appears anywhere: the hierarchy is in the key, and the key narrows the read before it happens.

Encode a path into the sort key and one begins_with reads any level of the tree, in order, for free.

Geo

These rows are real and already here. Running an operation against them downloads a DynamoDB-compatible engine, about 850 KB, and executes it in this tab.

Try an example

begins_with(sk, 'US#') returns every US station and nothing else. A country-level prefix.

pk(pk)
sk(sk)
station
tempC
GEO
FR#IDF#PARISS
PAR-1S
19N
GEO
FR#PACA#MARSEILLES
MAR-1S
25N
GEO
FR#PACA#NICES
NIC-1S
23N
GEO
JP#KANSAI#OSAKAS
OSA-1S
26N
GEO
JP#KANTO#TOKYOS
TYO-1S
21N
GEO
US#CA#LOS-ANGELESS
LAX-1S
24N
GEO
US#CA#SACRAMENTOS
SAC-1S
31N
GEO
US#CA#SAN-DIEGOS
SAN-1S
22N
GEO
US#NY#BUFFALOS
BUF-1S
12N
GEO
US#NY#NEW-YORKS
NYC-1S
18N
GEO
US#TX#AUSTINS
AUS-1S
33N
GEO
US#TX#HOUSTONS
HOU-1S
30N

Run an operation to see the raw engine response.

table Geokeys pk / skitems 12