Skip to content

fix(engine): name the start key of the wrong type in an index Scan - #1179

Open
LeeroyHannigan wants to merge 4 commits into
mainfrom
fix/1033-index-scan-start-key-type
Open

LeeroyHannigan wants to merge 4 commits into
mainfrom
fix/1033-index-scan-start-key-type

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

The review of 27 November 2026 approved 74fe005, and no commit came after it. This body adds a PartiQL SELECT of an index to Breaking changes, and the check of that case to Testing done.

The round before that review:

  • 9fafe38 merges main at 5252eda. The merge has no conflict and changes none of the three files of this PR.
  • 4b3e46e adds a row to the engine table and to INDEX_START_KEY_ROWS: a Scan of gsi2 with lsi2sk as a string set and an extra attribute x. DynamoDB answered it with the type sentence on two sends on 19 November 2026. With a change that skips the type check for a start key with an extra attribute, the engine test now fails on this row.
  • 74fe005 removes the references to the issue from the comments of this PR and keeps their dates. It also renames the test helper issue_1033_table to measured_table.
  • The body of that round fixed two sentences in What, about the writers of the type sentence and about the texts of an index Query. It also added a Breaking changes section, and Testing done gives the results at 74fe005.

What

A Scan of a GSI or an LSI now names a key of the ExclusiveStartKey that has the wrong type, as DynamoDB does: One or more parameter values were invalid: Type mismatch for Index Key <key> Expected: <type> Actual: <type> IndexName: <index>. Before this change, ExtendDB answered The provided starting key is invalid.

validate_scan_exclusive_start_key in crates/engine/src/start_key.rs now calls validate_index_key_types for an index read, before its other start key checks. That function writes the same sentence for an item write, so this PR adds no copy of the sentence. It checks the table keys and the index keys of the start key, and a scalar of another type as well as a set. It reports a key of the wrong type ahead of a key left out and ahead of an extra attribute.

A key left out, an extra attribute and an empty map keep The provided starting key is invalid. An index Query keeps that text for a key left out, an extra attribute, a key of the wrong type and an empty map. This PR does not change a Scan of the table.

Why

These are DynamoDB's answers, measured in us-east-1 on 14, 16 and 19 November 2026. Each request in the table was sent at least twice and got the same answer each time. The table has pk S HASH and sk S RANGE. Its local index lsi1 has the sort key lsi1sk S, and its GSI gsi2 has the hash key lsi1sk S and the sort key lsi2sk S. TM(key, type) is the sentence above for that key, the sent type and the index of the row.

Scan ExclusiveStartKey DynamoDB ExtendDB before
gsi2 lsi2sk as {"SS": ["a"]}, the other keys as strings TM(lsi2sk, SS) The provided starting key is invalid
lsi1 lsi1sk as {"SS": ["a"]} TM(lsi1sk, SS) the same
gsi2 lsi1sk, the GSI hash key, as a string set TM(lsi1sk, SS) the same
gsi2 sk, a table key, as a string set TM(sk, SS) the same
lsi1 pk as a string set TM(pk, SS) the same
lsi1 lsi1sk as N, B, BOOL, NULL, L, M, NS or BS TM(lsi1sk, ) the same
gsi2 lsi2sk as a string set beside an extra attribute TM(lsi2sk, SS) the same
gsi2 lsi2sk as a string set with sk left out TM(lsi2sk, SS) the same
gsi2, Segment 0 or 1 of 2 lsi2sk as a string set TM(lsi2sk, SS) the same

A Query of either index answers The provided starting key is invalid for the same start keys on both sides. So do a key left out, an extra attribute and an empty map in a Scan or a Query of either index.

Closes #1033

Testing done

At 74fe005, with --locked on each cargo build, check, clippy and test:

  • cargo +1.97.0 test -p extenddb-engine --lib: 934 passed.
  • cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings is clean, once with --features extenddb-storage/test-hooks and once with --features extenddb-engine/backup-test-hooks. cargo +1.91.1 check -p extenddb-engine --all-targets and cargo +1.97.0 fmt --all -- --check are clean too. cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -W clippy::pedantic gives no warning on a line this PR adds.
  • Against ExtendDB on SQLite, built from 74fe005, six files of tests/python passed 249 tests: test_scan_edge_cases.py, test_query_start_key_index.py, test_query_start_key_partition.py, test_query_start_key_range.py, test_query_scan.py and test_composite_keys.py.
  • On the same server, six files of tests/ passed 590 tests: test_attribute_value_validation.py, test_query_scan.py, test_read_paging.py, test_gsi_multi_range_query.py, test_query_key_value_types.py and test_query_begins_with_max_character.py. One test skipped, because it runs only on a backend that filters the first RANGE attribute alone.
  • The new table INDEX_START_KEY_ROWS sends 25 rows. DynamoDB gave each row's expected answer on two sends on 19 November 2026.
  • With start_key.rs from main, the engine test index_start_key_faults_answer_as_dynamodb_does fails on the first row of the issue. With a change that skips the type check for a start key with an extra attribute, it fails on the new row.
  • PartiQL on SQLite, 3 December 2026, two sends each. Servers built from 74fe005 and from main at c057660 got SELECT * FROM "<table>"."gsi2" and SELECT * FROM "<table>"."lsi1". Each NextToken held a key with lsi2sk or lsi1sk as a string set, or with lsi1sk as N on lsi1. 74fe005 answered the type sentence for each, and main answered The provided starting key is invalid. Both answered that text for a SELECT of gsi2 by its key lsi1sk with lsi2sk as a string set in the token. Both also answered it for a scan of gsi2 whose token leaves lsi2sk out.

Line counts against main: production +11, tests +250 -2.

With two keys of the wrong type, DynamoDB names either key, and the key changes between sends of the same request. On 19 November 2026, 12 such requests were sent, up to 7 times each. On each request, DynamoDB named each of the two keys on at least one send. ExtendDB names the first of the two in the start key schema of the read: the table keys, then the index keys. The tests have no row with two keys of the wrong type.

Not in this PR:

Other open PRs: #854 adds checks of the start key's values ahead of validate_scan_exclusive_start_key and keeps its call. So the rows above still reach the new check when both merge. This PR adds no conflict with any open PR.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

A Scan of a GSI or an LSI with a key of the wrong type in its ExclusiveStartKey gets the type sentence in place of The provided starting key is invalid.

A PartiQL SELECT that scans a GSI or an LSI reaches the same check with the key in its NextToken. So a NextToken that holds a key of the wrong type also gets the type sentence in place of The provided starting key is invalid. DynamoDB answers Invalid NextToken for such a token (measured in the review of 27 November 2026). ExtendDB writes a NextToken only from its own LastEvaluatedKey. A key of the wrong type comes only from a token that a client built or changed.

A client that matches the old text sees the new one. Other start keys, a Query, a SELECT that reads an index by its key and a Scan of the table get the same answers as before.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

ExtendDB answered "The provided starting key is invalid" to an index Scan
when a key of its ExclusiveStartKey had the wrong type. DynamoDB names the
key, the two types and the index. For a string set sent as the sort key
of gsi2 in issue #1033, it answers:

    One or more parameter values were invalid: Type mismatch for Index
    Key lsi2sk Expected: S Actual: SS IndexName: gsi2

The Scan check of an index read now compares each key of the start key
with its attribute definition first. This covers the table keys and the
index keys, and a scalar of another type as well as a set. The answer
comes from the index key type check that item writes use. A key of the
wrong type is reported ahead of a key left out.

A key left out, an extra attribute and an empty map keep the short
sentence. An index Query keeps the short sentence for every start key
fault. A Scan of the table is unchanged.

Each answer was measured on DynamoDB in us-east-1 on 2026-11-14,
2026-11-16 and 2026-11-19.

Fixes #1033.
The doc comment of validate_scan_exclusive_start_key says that an index
Scan reports a key of the wrong type ahead of an extra attribute. No row
of the two test tables had both faults. With a change that skipped the
type check for a start key with an extra attribute, the engine test
still passed.

The engine table and INDEX_START_KEY_ROWS now have that row: a Scan of
gsi2 with lsi2sk as a string set and an extra attribute x. DynamoDB
answered it twice in us-east-1 on 2026-11-19:

    One or more parameter values were invalid: Type mismatch for Index
    Key lsi2sk Expected: S Actual: SS IndexName: gsi2
The comments of the index start key check and of its two test tables
keep the dates of the measurements and name no issue. The test helper
that builds the measured table is now measured_table.
@demohan demohan self-assigned this Nov 27, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An index Scan names the start key attribute of the wrong type at 74fe005, as DynamoDB does. Across 73 request shapes, GSI and LSI reads, hash-only and hash-plus-range indexes, a hash-only table, multi-attribute GSI keys, N and B key types, table keys against index keys, missing and extra attributes, segments, ConsistentRead and every non-scalar type, each sent 2 to 6 times to us-east-1, a SQLite and a PostgreSQL build of this head answer as the service does on every shape the PR covers, and the two backends answer alike. Where the service varies between sends, as for a wrong-type key beside an empty-string key, this head gives one of its answers. Index Query and table Scan answer as before. The PR's 25 rows pass on the service and on both backends, and on main exactly the 9 type-sentence rows fail; six of seven mutations fail the engine test and the seventh fails the wire test. fmt, clippy, the 1.91.1 check and 934 engine tests are clean, and the branch merges cleanly with main. The integration runs at this head were cancelled, so the new wire test has no CI result yet.

A PartiQL SELECT on an index reaches the same check: a NextToken carrying a key of the wrong type answers the type sentence here and The provided starting key is invalid on main, where the service answers Invalid NextToken. That is no regression, but the Breaking changes section names only Scan.

fn sent_as(type_tag: &str) -> AttributeValue {
match type_tag {
"S" => s("a"),
"SS" => AttributeValue::SS(["a".to_owned()].into()),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. The rows send only S and SS values, so a check that looks only at set types passes all 38 tests; the wire test's lsi1sk N and B rows catch it. An N or B declared key and a hash-only index here would hold it in the engine test too.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan The PartiQL SELECT case is now in Breaking changes. A SELECT that scans a GSI or an LSI gets the type sentence for a NextToken that holds a key of the wrong type, in place of The provided starting key is invalid. The section gives your Invalid NextToken answer from the service, and says that such a token comes only from a client that built or changed it. A SELECT that reads an index by its key keeps the old text.

On SQLite servers built from 74fe005 and from main at c057660, a scan of gsi2 and of lsi1 with such a token answered the type sentence and The provided starting key is invalid. Each request went twice, on 3 December 2026, and Testing done lists these checks. The body edit adds no commit, so 74fe005 is still the head.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants