accesspatterns.dev

Traverse a relationship both ways

An index that swaps the partition and sort keys reads the same edges from the other side.

Why

A maintainer belongs to many projects, and a project has many maintainers. Each membership is stored once, as an edge item keyed pk = PERSON, sk = PROJECT, carrying a second pair of keys that swap the two: gsi1pk = PROJECT, gsi1sk = PERSON.

So the base table answers 'Ada's projects' and the inverted index answers 'httpkit's maintainers', from the very same edges. One relationship, two directions, nothing duplicated. The profile items carry no index keys, so only the edges appear in the index.

Store a many-to-many as edges, then an inverted index, partition and sort swapped, reads the relationship from either side.

Maintainers

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

On the base table, Ada's partition holds one edge per project she maintains.

pk(pk)
sk(sk)
name
lang
gsi1pk
gsi1sk
role
PERSON#ada
PERSON#adaS
AdaS
PERSON#ada
PROJ#httpkitS
PROJ#httpkitS
PERSON#adaS
reviewerS
PERSON#ada
PROJ#zlib2S
PROJ#zlib2S
PERSON#adaS
leadS
PERSON#mei
PERSON#meiS
MeiS
PERSON#mei
PROJ#dataframeS
PROJ#dataframeS
PERSON#meiS
leadS
PERSON#raj
PERSON#rajS
RajS
PERSON#raj
PROJ#dataframeS
PROJ#dataframeS
PERSON#rajS
reviewerS
PERSON#raj
PROJ#httpkitS
PROJ#httpkitS
PERSON#rajS
leadS
PROJ#dataframe
PROJ#dataframeS
dataframeS
PythonS
PROJ#httpkit
PROJ#httpkitS
httpkitS
RustS
PROJ#zlib2
PROJ#zlib2S
zlib2S
CS

Run an operation to see the raw engine response.

table Maintainerskeys pk / skitems 11