Skip to content

fix(memory): local index reads fetch what the index does not hold - #108

Merged
kalaspuff merged 4 commits into
mainfrom
fctl/52-https-github-com-kalaspuff-dynamoxy-issu
Oct 30, 2026
Merged

kalaspuff merged 4 commits into
mainfrom
fctl/52-https-github-com-kalaspuff-dynamoxy-issu

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The in-memory DynamoDB answered a read of a local secondary index from the index entries alone when a projection named attributes the index does not hold, where DynamoDB fetches each item from the table: a KEYS_ONLY index queried with ProjectionExpression="secret, lsk" returned only lsk, client.model(Note).query(index="by_kind", owner="ada").project("body", "kind") returned [{"kind": "todo"}], and PartiQL SELECTs did the same. Reads that did fetch the items (Select=ALL_ATTRIBUTES, which model reads of partial local indexes always send, ADR 0012) counted only the entries towards the 1 MB of a page and the read units, so ten 300 KB items came back in one page for 1 read unit.

Query, Scan and PartiQL SELECT of a local index now fetch each item they evaluate from the table whenever they return an attribute the index does not hold. Such a page stops at 1 MB of the entries (rounded up to 4 KB) plus each fetched item (rounded up to 4 KB on its own), and is charged a read of each fetched item on the table besides the read of the entries on the index, as the Query API reference and the local secondary index guide describe. The WHERE clause of a SELECT still reads the index entries.

Verified with new memory backend tests of projections, scans, page sizes, read units and PartiQL, which fail without the fix, an integration test of .project(...) of a local index, and make check. MiniStack never reads the table for local indexes, so the integration test checks the fetch on the memory backend only, like the existing test of Select=ALL_ATTRIBUTES.

Checklist

  • Tests cover the change (in-memory backend; the integration test runs on MiniStack too, without the fetch)
  • Docs updated (reading guide, changelog)
  • make check passes locally (lint, types, clippy, consistency, Rust and Python tests)
  • Breaking change? No: only the in-memory backend changes, towards DynamoDB's behaviour

Worth confirming

Fixes #73

fctl session


Note

Medium risk. It changes what the in-memory DynamoDB returns, how big its pages are and what read units it reports for local index reads, which tests of applications that use the memory backend may rely on; the AWS adapter and stored data are untouched.

What it does. Makes the in-memory backend read a local secondary index the way DynamoDB does: when a Query, Scan or PartiQL SELECT returns an attribute the index does not hold, each item is fetched from the table, so the result is complete instead of missing those attributes. Such a page now counts each fetched item (rounded up to 4 KB) towards the 1 MB limit and charges a read of each item to the table besides the read of the index entries. A new PageRead helper in table.rs carries this accounting for all three operations, and new memory backend tests and an integration test cover it.

Filter semantics. A FilterExpression of a fetching Query or Scan now evaluates the table item, so a filter on an attribute the index does not hold matches when the projection fetches; the description leaves open whether DynamoDB rejects such filters (#106).

fctl review's first look at e3bc3eb · 7 files, +237 −29 · Review agent settings

fctl-sh Bot and others added 4 commits October 30, 2026 23:24
The in-memory DynamoDB answered a read of a local index with a
projection from the index entries alone, so attributes the index does
not hold were missing: a KEYS_ONLY index queried with
ProjectionExpression "secret, lsk" returned only lsk, and model reads
with .project(...) lost the fields the index leaves out. PartiQL
SELECTs of such attributes did the same. Reads that did fetch the
items (Select=ALL_ATTRIBUTES, which model reads of partial local
indexes send) counted only the entries towards the 1 MB of a page and
the read units, so ten items of 300 KB came back in one page for one
read unit.

DynamoDB fetches the table item of each entry when a read of a local
index returns an attribute the index does not hold, counts the entries
(rounded up to 4 KB) and each fetched item (rounded up to 4 KB on its
own) towards the page, and charges a read of each fetched item to the
table besides the read of the entries on the index (the Query API
reference and the local secondary index guide). Query, Scan and
PartiQL SELECT now do that; the WHERE clause of a SELECT still reads
the index entries.

Refs #73

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

# Conflicts:
#	CHANGELOG.md
…com-kalaspuff-dynamoxy-issu

Brings in #104 (PartiQL transactions that name an item twice are
refused). CHANGELOG.md conflicted where both added an entry at the end
of [Unreleased] Fixed: both entries are kept, #104's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
…com-kalaspuff-dynamoxy-issu

Brings in #103 (list elements set past the end append in order of
their index). CHANGELOG.md conflicted where both added an entry at the
end of [Unreleased] Fixed: both entries are kept, #103's first.

Co-authored-by: Carl Oscar Aaro <[email protected]>
@kalaspuff
kalaspuff merged commit 0d2731d into main Oct 30, 2026
22 checks passed
@kalaspuff
kalaspuff deleted the fctl/52-https-github-com-kalaspuff-dynamoxy-issu branch October 30, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-memory DynamoDB: reads of a local index with a projection never fetch what the index does not hold

1 participant