accesspatterns.dev

Modelling relationships · Lesson 16 of 20

Absence as a filter

An item appears in an index only if it has the index's key, so leaving the key off filters it out.

Next · Modelling relationshipsKeep the total where you read it

Why

An item is copied into a secondary index only if it has every attribute in that index's key. In this table only open tickets are given a gsi1pk, so only open tickets exist in the by-assignee index.

Scan the index, then the table. The index is a ready-made list of open work, with no filter expression and nothing wasted. Close a ticket by removing its gsi1pk and it drops out of the index on its own.

A sparse index uses absence as a global filter: only the items you care about ever appear in it.

Tickets
Try an example

Scan the by-assignee index. Only OPEN tickets carry gsi1pk, so closed tickets are simply not here, even though they exist in the table.

pk(pk)
sk(sk)
title
status
gsi1pk

Run an operation to see the raw engine response.

table Ticketskeys pk / skitems 20