Repository navigation
fix(engine): name the start key of the wrong type in an index Scan - #1179
LeeroyHannigan wants to merge 4 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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.
|
@demohan The PartiQL On SQLite servers built from 74fe005 and from main at c057660, a scan of |
Changes since the last review
The review of 27 November 2026 approved 74fe005, and no commit came after it. This body adds a PartiQL
SELECTof an index to Breaking changes, and the check of that case to Testing done.The round before that review:
INDEX_START_KEY_ROWS: a Scan ofgsi2withlsi2skas a string set and an extra attributex. 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.issue_1033_tabletomeasured_table.What
A Scan of a GSI or an LSI now names a key of the
ExclusiveStartKeythat 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 answeredThe provided starting key is invalid.validate_scan_exclusive_start_keyincrates/engine/src/start_key.rsnow callsvalidate_index_key_typesfor 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
pkS HASH andskS RANGE. Its local indexlsi1has the sort keylsi1skS, and its GSIgsi2has the hash keylsi1skS and the sort keylsi2skS. TM(key, type) is the sentence above for that key, the sent type and the index of the row.ExclusiveStartKeygsi2lsi2skas{"SS": ["a"]}, the other keys as stringsThe provided starting key is invalidlsi1lsi1skas{"SS": ["a"]}gsi2lsi1sk, the GSI hash key, as a string setgsi2sk, a table key, as a string setlsi1pkas a string setlsi1lsi1skas N, B, BOOL, NULL, L, M, NS or BSgsi2lsi2skas a string set beside an extra attributegsi2lsi2skas a string set withskleft outgsi2,Segment0 or 1 of 2lsi2skas a string setA Query of either index answers
The provided starting key is invalidfor 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
--lockedon 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 warningsis clean, once with--features extenddb-storage/test-hooksand once with--features extenddb-engine/backup-test-hooks.cargo +1.91.1 check -p extenddb-engine --all-targetsandcargo +1.97.0 fmt --all -- --checkare clean too.cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -W clippy::pedanticgives no warning on a line this PR adds.tests/pythonpassed 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.pyandtest_composite_keys.py.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.pyandtest_query_begins_with_max_character.py. One test skipped, because it runs only on a backend that filters the first RANGE attribute alone.INDEX_START_KEY_ROWSsends 25 rows. DynamoDB gave each row's expected answer on two sends on 19 November 2026.start_key.rsfrom main, the engine testindex_start_key_faults_answer_as_dynamodb_doesfails 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.SELECT * FROM "<table>"."gsi2"andSELECT * FROM "<table>"."lsi1". EachNextTokenheld a key withlsi2skorlsi1skas a string set, or withlsi1skas N onlsi1. 74fe005 answered the type sentence for each, and main answeredThe provided starting key is invalid. Both answered that text for aSELECTofgsi2by its keylsi1skwithlsi2skas a string set in the token. Both also answered it for a scan ofgsi2whose token leaveslsi2skout.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:
: The provided key element does not match the schema, where DynamoDB answersThe provided starting key is invalid#1174: a Scan of the table answers ExtendDB's longer text for a start key fault, where DynamoDB answersThe provided starting key is invalid. Open PR fix(engine): answer an invalid table Scan start key as DynamoDB does #1218 fixes it, with this PR as its base.Limit0 gets ExtendDB's text, where DynamoDB writesValue at 'Limit'with no value.Other open PRs: #854 adds checks of the start key's values ahead of
validate_scan_exclusive_start_keyand 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
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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
ExclusiveStartKeygets the type sentence in place ofThe provided starting key is invalid.A PartiQL
SELECTthat scans a GSI or an LSI reaches the same check with the key in itsNextToken. So aNextTokenthat holds a key of the wrong type also gets the type sentence in place ofThe provided starting key is invalid. DynamoDB answersInvalid NextTokenfor such a token (measured in the review of 27 November 2026). ExtendDB writes aNextTokenonly from its ownLastEvaluatedKey. 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
SELECTthat 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.