accesspatterns.dev

Modelling relationships · Lesson 14 of 20

A different key for a different question

A secondary index re-keys your items so you can Query them on a new axis.

Next · Modelling relationshipsTraverse a relationship both ways

Why

The base table groups tickets by project. But 'every ticket assigned to Ada, across all projects' needs a different partition key, and you cannot change the table's keys.

A global secondary index is the answer: it is an automatically-maintained, re-keyed copy of your items. Query the base table for a project; Query the index for an assignee. Same items, two axes.

An index is a re-keyed copy of your data. Add one when an access pattern needs a key the table does not have.

Tickets
Try an example

The base table is keyed by project, so 'this project's tickets' is a Query on the table.

pk(pk)
sk(sk)
title
status
gsi1pk

Run an operation to see the raw engine response.

table Ticketskeys pk / skitems 20