accesspatterns.dev

A filter is not an index

A FilterExpression runs after the read: you pay for everything scanned.

Why

It is tempting to read this Scan as 'find the rock songs'. It is not. A Scan reads every item in the table, and the FilterExpression only drops some of them on the way out. The 1MB read limit and the bill are both applied before the filter.

Run the Scan, then the index Query for the identical result. The Scan's Scanned is the whole table; the index Query's Scanned equals what it returned. Same answer, very different cost.

You pay for Scanned, not Returned. A filter trims the result, never the bill. When you reach for a filter, reach for a key or an index instead.

MusicLibrary

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

Read the whole table, then drop everything that is not rock. Watch Scanned climb far past Returned.

pk(pk)
sk(sk)
name
country
type
title
genre
year
ARTIST#radiohead
PROFILES
RadioheadS
UKS
ARTISTS
ARTIST#radiohead
SONG#creepS
CreepS
rockS
1992N
ARTIST#radiohead
SONG#everythingS
Everything In Its Right PlaceS
electronicS
2000N
ARTIST#radiohead
SONG#idiotequeS
IdiotequeS
electronicS
2000N
ARTIST#radiohead
SONG#karma-policeS
Karma PoliceS
rockS
1997N
ARTIST#radiohead
SONG#no-surprisesS
No SurprisesS
rockS
1997N
ARTIST#daftpunk
PROFILES
Daft PunkS
FRS
ARTISTS
ARTIST#daftpunk
SONG#aerodynamicS
AerodynamicS
electronicS
2001N
ARTIST#daftpunk
SONG#get-luckyS
Get LuckyS
popS
2013N
ARTIST#daftpunk
SONG#harder-betterS
Harder, Better, Faster, StrongerS
electronicS
2001N
ARTIST#daftpunk
SONG#one-more-timeS
One More TimeS
electronicS
2000N
ARTIST#adele
PROFILES
AdeleS
UKS
ARTISTS
ARTIST#adele
SONG#helloS
HelloS
popS
2015N
ARTIST#adele
SONG#rolling-in-the-deepS
Rolling in the DeepS
popS
2011N
ARTIST#adele
SONG#someone-like-youS
Someone Like YouS
popS
2011N
ARTIST#arcadefire
PROFILES
Arcade FireS
CAS
ARTISTS
ARTIST#arcadefire
SONG#rebellionS
Rebellion (Lies)S
rockS
2004N
ARTIST#arcadefire
SONG#the-suburbsS
The SuburbsS
rockS
2010N
ARTIST#arcadefire
SONG#wake-upS
Wake UpS
rockS
2004N
ARTIST#miles-davis
PROFILES
Miles DavisS
USS
ARTISTS
ARTIST#miles-davis
SONG#blue-in-greenS
Blue in GreenS
jazzS
1959N
ARTIST#miles-davis
SONG#freddieS
Freddie FreeloaderS
jazzS
1959N
ARTIST#miles-davis
SONG#so-whatS
So WhatS
jazzS
1959N
ARTIST#nina-simone
PROFILES
Nina SimoneS
USS
ARTISTS
ARTIST#nina-simone
SONG#feeling-goodS
Feeling GoodS
jazzS
1965N
ARTIST#nina-simone
SONG#sinnermanS
SinnermanS
jazzS
1965N
ARTIST#kendrick
PROFILES
Kendrick LamarS
USS
ARTISTS
ARTIST#kendrick
SONG#alrightS
AlrightS
hip-hopS
2015N
ARTIST#kendrick
SONG#humbleS
HUMBLE.S
hip-hopS
2017N
ARTIST#kendrick
SONG#money-treesS
Money TreesS
hip-hopS
2012N
ARTIST#bjork
PROFILES
BjörkS
ISS
ARTISTS
ARTIST#bjork
SONG#hyperballadS
HyperballadS
electronicS
1995N
ARTIST#bjork
SONG#jogaS
JógaS
electronicS
1997N
ARTIST#bowie
PROFILES
David BowieS
UKS
ARTISTS
ARTIST#bowie
SONG#ashesS
Ashes to AshesS
popS
1980N
ARTIST#bowie
SONG#heroesS
HeroesS
rockS
1977N
ARTIST#bowie
SONG#lets-danceS
Let's DanceS
popS
1983N
ARTIST#fleetwood
PROFILES
Fleetwood MacS
UKS
ARTISTS
ARTIST#fleetwood
SONG#dreamsS
DreamsS
rockS
1977N
ARTIST#fleetwood
SONG#go-your-own-wayS
Go Your Own WayS
rockS
1977N
ARTIST#fleetwood
SONG#the-chainS
The ChainS
rockS
1977N
ARTIST#aphex-twin
PROFILES
Aphex TwinS
UKS
ARTISTS
ARTIST#aphex-twin
SONG#avril-14thS
Avril 14thS
electronicS
2001N
ARTIST#aphex-twin
SONG#windowlickerS
WindowlickerS
electronicS
1999N
ARTIST#sufjan
PROFILES
Sufjan StevensS
USS
ARTISTS
ARTIST#sufjan
SONG#casimirS
Casimir Pulaski DayS
folkS
2005N
ARTIST#sufjan
SONG#chicagoS
ChicagoS
folkS
2005N

Run an operation to see the raw engine response.

table MusicLibrarykeys pk / skitems 47