accesspatterns.dev

Single-table design · Lesson 18 of 20

One index, many questions

Different entity types share generic index keys, so one index serves several access patterns.

Next · Single-table designAn index holds only what you project

Why

Here one table holds projects and tasks, and one index, GSI1, serves both. The trick is generic key names: projects write OWNER#ada into gsi1pk, tasks write STATUS#doing into the same attribute.

So one index answers 'Ada's projects' and 'tasks in progress': two access patterns, two entity types, one set of index keys. This overloading is the heart of single-table design.

Generic, overloaded keys let one index do the work of many. That is how a single table serves a whole application.

Workspace
Try an example

On GSI1, project items set gsi1pk to OWNER#ada. So this Query returns Ada's projects.

pk(pk)
sk(sk)
name
gsi1pk
gsi1sk
title

Run an operation to see the raw engine response.

table Workspacekeys pk / skitems 19