Skip to content

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.

Try it. Then change it.

Predict what each request will do. Run it, inspect the response, then change a value in the workbench and try again.

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

  2. Deepen the prefix one segment to US#CA# and the read narrows to three cities. Scanned still equals Returned.

  3. The full path is the whole sort key, so an equals returns a single station.

Built on this

GeoDynamoDB workbench
Ready to run
Explore an access patternSelect to load & run

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

Request
Execute against the local Dynoxide engine
ReturnedFiltered outChanged
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
Awaiting request
Your next query starts here.

Choose an access pattern above, or build your own request. See what comes back and what it costs.

Powered by DynoxideWASMStarts on your first run · Runs locally in your browser