accesspatterns.dev

Modelling relationships · Lesson 15 of 20

Traverse a relationship both ways

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

Next · Modelling relationshipsAbsence as a filter

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
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

Run an operation to see the raw engine response.

table Maintainerskeys pk / skitems 11