Repository navigation
fix(query): refuse key condition values over the key size limits - #481
Conversation
Closes #435. The service refuses a Query whose key condition values exceed the key size limits before it reads anything; ExtendDB ran the Query. Measured on 2026-10-23, every row repeated with identical answers: - A HASH value over 2048 bytes: "One or more parameter values were invalid: Size of hashkey has exceeded the maximum size limit of2048 bytes" (no space after "of", as the service writes it). 2048 bytes is accepted. - HASH values that each fit but add up to more than 2048 bytes (an index with two HASH attributes): "One or more parameter values were invalid: Aggregated size of all hash keys has exceeded the size limit of 2048 bytes". A sum of exactly 2048 is accepted. A single oversized value gets the single sentence even when the sum is also over. - RANGE values adding up to more than 1024 bytes, one clause or several: "One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes". 1024 is accepted. Every operator is sized (=, <, <=, >, >=, begins_with); BETWEEN contributes its larger bound, not the sum of both. - The HASH checks are reported before the RANGE check. - Strings are sized by UTF-8 bytes (683 U+20AC characters, 2049 bytes, refused; 682 plus "xx", 2048 bytes, accepted) and binary values by byte length. Base tables, LSIs, GSIs and legacy KeyConditions behave the same. - An undefined #name or :value in the key condition is reported before the size check. Ordering, measured with a 2049-byte value: filter syntax, unused names and values, index name, ConsistentRead on a GSI, missing table, Limit, projection syntax and overlap, the Select conflicts and the filter operand type are all reported first; the ExclusiveStartKey checks after. The check is crates/core/src/validation/key_size.rs, called from handle_query after the expression validations and before the start key checks. The limits come from the configuration and the sentences name them. Tests: unit tests in validation/key_size/tests.rs and the engine; tests/python/test_query_key_size.py, test_query_key_size_values.py and test_query_key_size_order.py (64 rows) pass against the service. On ExtendDB alone, five rows with two or more RANGE clauses on one index skip until the multi-attribute range change in #429 merges (the handler refuses the shape earlier today); they pass on the merged tree. The undefined-name row stays unit level because the undefined-name refusal for a sort key clause arrives with #479. Pre-existing, measured, not changed here: a BETWEEN with the lower bound above the upper bound is refused by the service with a bound-order sentence; two conditions on one key are refused with "KeyConditionExpressions must only contain one condition per key"; a Number with 39 or more digits is refused with "Attempting to store more than 38 significant digits in a Number"; a FilterExpression on a key attribute is refused with "Filter Expression can only contain non-primary key attributes". ExtendDB accepts all four.
…y sentence matches the other backends
… multi-RANGE index The Cassandra backend answers InternalServerError to any Query on an index with several RANGE attributes: its ORDER BY lists sk_* then base_pk and skips the sk2_* to skN_* clustering columns, which Cassandra refuses with "Order by currently only supports the ordering of columns following their declared order in the PRIMARY KEY". require_multi_range now also skips on InternalServerError, so test_one_600_byte_range_value_is_accepted carries the probe like the other idx rows.
docs/dynamodb-limits.md conflicted in the key and item size rows. The merged table keeps main's rows for the item size and the attribute name size, and this branch's rows for the partition key and sort key sizes, which describe the Query checks.
Since #429, the MongoDB and Cassandra backends refuse a key condition on a later RANGE attribute of a multi-attribute index with a ValidationException. Two rows of TestGsiQueryKeySize expect such a Query to be served, and they failed on MongoDB. They now skip when a probe gets that refusal, as the multi-range tests on main do. The refusal rows still run on those backends, because the size check answers first.
crates/core/src/validation/mod.rs keeps the restorable_item and warm_throughput re-exports from main and the key_size re-export from this branch.
…orable_item Main added validation/restorable_item.rs, which sizes a backup item's key with key_value_byte_size from the validation module. This branch moved that function into validation/key_size.rs. The call now names the new module, as check_key_size does.
demohan
left a comment
There was a problem hiding this comment.
Three items to change before merge. The size refusals and their order match the service on SQLite, PostgreSQL, MongoDB and Cassandra for every other shape I sent (131 shapes, each twice, us-east-1). Once these three are done, it merges.
- An invalid Number in the key condition gets the size sentence. The service sends its number sentence.
- With no ExclusiveStartKey, the Select check for a GSI projection runs before the size check. The service reports the size first.
require_multi_rangeskips refusal rows on any InternalServerError.
Smaller notes are inline and optional.
crates/engine/src/query.rs:136: With no ExclusiveStartKey this Select check runs before validate_query_key_sizes. On a KEYS_ONLY GSI, g = :v with a 2049-byte :v and Select=ALL_ATTRIBUTES gets Size of hashkey has exceeded the maximum size limit of2048 bytes from the service (two samples, two tables). Here it gets Select type ALL_ATTRIBUTES is not supported for global secondary index gko because its projection type is not ALL. With a 1-byte :v both answer the Select sentence. With an ExclusiveStartKey this branch already matches. Moving the no-ESK call below the size check, plus a wire row, covers it.
tests/python/test_query_key_size_order.py, the unvalidated_client fixture (optional): conftest.py already provides this client as raw_client.
| pub(super) fn key_value_byte_size(value: &AttributeValue) -> usize { | ||
| match value { | ||
| AttributeValue::S(s) => s.len(), | ||
| AttributeValue::N(n) => n.len(), |
There was a problem hiding this comment.
A valid Number is normalized before it gets here, so only an invalid one can exceed the limit, and that one gets the size sentence. On a GSI with HASH n (N), n = :v with :v set to 2049 1 digits: the service answers Attempting to store more than 38 significant digits in a Number (two samples). This branch answers Size of hashkey has exceeded the maximum size limit of2048 bytes. 1 followed by 2100 zeros gets Number overflow... from the service and the size sentence here. Validating each N value with validation::number before sizing fixes both. It also fixes 39 digits, which the service refuses and ExtendDB serves today.
There was a problem hiding this comment.
Fixed in 001fe29 and 31159a2. The size check now reads each N value with normalize_number and sizes the normalized digits. 2049 digits and 39 digits get Attempting to store more than 38 significant digits in a Number, and 1 followed by 2100 zeros gets the overflow sentence, in the expression and in KeyConditions. The rows are in TestNumberKeyValues in test_query_key_size_values.py. A value the validator does not read as a number, such as one written in U+FF11, is sized by its text. DynamoDB serves such a value (HTTP 200, Count 0, measured 2026-11-20).
There was a problem hiding this comment.
A correction to my reply above. 001fe29 and 31159a2 fixed this for ASCII digit counts and magnitudes only. At 31159a2 the check sized a value the validator does not read as a number by its text. So 2049 x or 2049 U+FF11 got the hash size sentence.
DynamoDB refuses these values before it looks up the table. Measured 2026-11-24 in us-east-1, twice each, on a table that does not exist:
abcand 2049xanswerThe parameter cannot be converted to a numeric value:followed by the value, inKeyConditionExpressionand inKeyConditions.- 39 and 2049 U+FF11 answer
Attempting to store more than 38 significant digits in a Number. So my sentence that DynamoDB serves a value written in U+FF11 holds for a single U+FF11 (measured 2026-11-20), not for 39 or more.
a3f733d adds nothing to the size for a value the validator does not read as a number, so ExtendDB serves these Queries, as main does. The number check of these values is #544's for ExpressionAttributeValues and #507's for KeyConditions. number_values_get_the_number_rules_before_any_size gains a 2049 x row and a 2049 U+FF11 row. Both fail with the old n.len() arm.
| assert!(check(&kc, &base_schema(), &m).is_ok()); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
This pins the size sentence for a 2049-digit N. The service answers Attempting to store more than 38 significant digits in a Number for this value.
There was a problem hiding this comment.
| err = exc.response["Error"] | ||
| if err["Message"] == MISSING_HASH_MESSAGE: | ||
| pytest.skip("multi-attribute range conditions need the #429 change") | ||
| if err["Code"] == "InternalServerError": |
There was a problem hiding this comment.
The refusal rows call this probe too. The size refusal answers before any storage read, so a 500 or a classifier change on an idx Query would turn those rows into skips. Neither branch fires on SQLite, PostgreSQL, MongoDB or Cassandra at this head. Dropping the probe from the refusal rows and removing the InternalServerError branch keeps a failure visible.
There was a problem hiding this comment.
Fixed in b116a46: require_multi_range is gone. With #429 merged, neither of its branches fires on SQLite, PostgreSQL, MongoDB or Cassandra. The refusal rows and the accept row on a now fail when the server answers 500 or refuses the shape. The two accept rows on a later RANGE attribute keep require_served.
| // Refuse key values over the key size limits (hash 2048 bytes, all range | ||
| // values together 1024 bytes) before any storage read. Order measured | ||
| // 2026-10-23 with a 2049-byte hash value plus one other fault: a missing | ||
| // table, a wrong IndexName, ConsistentRead on a GSI, Limit 0, a key |
There was a problem hiding this comment.
The type check already runs above this call, at resolve_key_schema_with with check_key_value_type. A wrong-typed key value with a 2049-byte value answers the type sentence first, as the service does.
There was a problem hiding this comment.
Fixed in 9061b23. The comment now says the type check runs above the size check, in resolve_key_schema_with.
| /// the aggregated sentence; on an index with HASH `h` and RANGE `a`, `b`, `c`, | ||
| /// `d`: `a` of 600 and `c` of 600 bytes (with `b` of 1) refused, 512 and 512 | ||
| /// passes, 512 and 513 refused, `b > 1025` refused, `a` of 600 with `b BETWEEN` | ||
| /// 1 and 600 refused and with 1 and 424 passes. Not measured: a HASH sum of |
There was a problem hiding this comment.
The wire tests assert both of these cases (HASH sum of exactly 2048, and the hash sentence when both sums are over), and they pass against the service.
There was a problem hiding this comment.
Fixed in 001fe29. The doc comment lists both shapes with the measured ones, and both rows pass against DynamoDB.
| /// - If a `#name` or `:value` of any key clause is not defined, the check | ||
| /// returns `Ok` and the request gets the undefined-reference refusal it | ||
| /// already has, which the service reports ahead of the size. | ||
| /// |
There was a problem hiding this comment.
On a single-attribute schema, pk = :h AND #u > :r with #u undefined is served with Count 0 today. The service refuses it. Returning Ok here is fine, but the sentence about the refusal it already has does not hold for that shape.
There was a problem hiding this comment.
This difference predates the PR. The size check returns Ok for that shape, and main serves the same request with Count 0. 001fe29 and aa30100 rewrite the doc sentence to say that ExtendDB serves the request and DynamoDB refuses it. The sentence cites #1214, which tracks an undefined name in a second key condition clause.
| 2026-10-21 (index ``idx`` with HASH ``h`` and RANGE ``a``, ``b``, ``c``, ``d``, | ||
| all S), the base table rows on 2026-10-22 (HASH ``pk``, RANGE ``sk``, both S), | ||
| and the operator, BETWEEN, binary, LSI, legacy, multi-attribute and two-HASH | ||
| rows on 2026-10-23 (``issues/query-parity/service-435-shapes.jsonl``, |
There was a problem hiding this comment.
issues/query-parity/service-435-shapes.jsonl is not in the repository. The same applies to test_query_key_size_order.py:8, test_query_key_size_values.py:7 and "the issue's fold file" in query_key_size_tests.rs:8.
| def test_between_adds_its_larger_bound_to_the_range_total( | ||
| self, dynamodb_client, gsi_table | ||
| ): | ||
| # a = 600 plus the larger BETWEEN bound: 1 and 600 (1200) is refused, |
There was a problem hiding this comment.
This test holds a refusal and an accept. On MongoDB and Cassandra the accept half skips, so the whole test reports SKIPPED although the refusal ran. Two tests would report each half.
There was a problem hiding this comment.
Split in b116a46. test_between_adds_its_larger_bound_to_the_range_total holds the refusal, and test_between_within_the_range_total_is_accepted holds the accept with require_served.
Query sized an N value in a key condition by its digit string, so an invalid number got the key size sentence. The service checks the number first. Measured 2026-11-20 in us-east-1 on a GSI with HASH n (N), each shape twice: - 2049 or 39 digits answer "Attempting to store more than 38 significant digits in a Number", in KeyConditionExpression and in KeyConditions. - 1 followed by 2100 zeros answers "Number overflow. Attempting to store a number with magnitude larger than supported range". - The service serves 2100 zeros followed by 1. validate_query_key_sizes now passes each N value it reads to validate_and_normalize_number and sizes the normalized digits. Query served a 39-digit value before and refuses it now, as the service does. The doc comment of validate_query_key_sizes no longer lists two shapes as not measured. The wire tests assert both, a HASH sum of exactly 2048 bytes and the aggregated hash sentence over an oversized RANGE value. Both pass against the service. The comment also names a request that ExtendDB serves and the service refuses. The request has an undefined #name in a second clause, on a key schema with one HASH attribute and at most one RANGE attribute.
With no ExclusiveStartKey, Query checked Select=ALL_ATTRIBUTES against the index projection before the other request checks. The service makes that check after the key size check. With a start key, it also comes after the start key checks. Measured 2026-11-20 in us-east-1 on a KEYS_ONLY GSI with Select=ALL_ATTRIBUTES, each shape twice: - A 2049-byte key value answers the size sentence, with and without an ExclusiveStartKey. - A 1-byte value answers the Select sentence. - Without a start key, Limit 0 and a parameter mix each answer their own refusal ahead of the Select sentence. So do an empty or invalid KeyConditionExpression, a missed key schema element, a wrong-typed key value and a filter or projection fault. ProjectionExpression with ALL_ATTRIBUTES and an unused name or value also come first. ExtendDB answered the Select sentence for all of them. The check now runs once, after the size and start key checks. The comment above the size check no longer says that the type check is still to come. The type check runs above it, in resolve_key_schema_with. The engine test comments cite the measurement dates and region, not local files.
…ible - test_query_key_size_values.py: rows on a GSI with HASH n (N) for 2049 digits, 39 digits, 1 followed by 2100 zeros and 2100 zeros followed by 1. Each row runs in KeyConditionExpression and in KeyConditions. - test_query_key_size_order.py: rows on a KEYS_ONLY GSI for Select=ALL_ATTRIBUTES with a 2049-byte and a 1-byte value, with and without an ExclusiveStartKey. The Limit 0 row uses the raw_client fixture from conftest.py in place of its own copy. - This commit removes require_multi_range. Neither of its skips fires on any backend at this head. On a refusal row, a 500 or a classifier change turned the row into a skip. - The BETWEEN row is two tests. The refusal half reports its result on MongoDB and Cassandra, where the accept half skips. - The docstrings cite the measurement dates and region, not local files.
On a KEYS_ONLY GSI with Select ALL_ATTRIBUTES and no ExclusiveStartKey, DynamoDB answers each of these refusals before the Select sentence: - Limit 0 - a key condition on the base table's partition key - an N value on the S key - an unused expression value - an empty KeyConditionExpression - FilterExpression `#` A reviewer measured each shape twice on 2026-11-24. These shapes are now rows of test_select_all_attributes_on_a_keys_only_gsi_is_reported_after. Each row asserts status, code and message by equality, except the `#` row. ExtendDB words that syntax error in its own way (#1419), so the row checks the `Invalid FilterExpression: ` label. The table now sends its requests through raw_client, because the SDK refuses Limit 0. FILTER_LABEL, LIMIT_MESSAGE and MISSED_G_MESSAGE hold the three texts that a new row shares with an existing test. With the Select check moved above the Limit check, the six new rows fail. The two 2049-byte rows of the table and two start key rows in test_query_start_key_partition.py fail too. On SQLite, the three wire files and test_query_start_key_partition.py give 136 passed.
Main is at 80490c6, six commits after the last merge (#398, #428, #544, #567, #584 and #588). Two files conflicted. crates/engine/src/lib.rs: this branch adds query_key_size_tests and #544 adds query_key_values to the module list. The merge keeps both in name order. crates/engine/src/query.rs, two hunks in handle_query: - This branch moves validate_query_select_index_support after the start key checks, and #544 replaces the Limit check with a comment. The merge removes the early Select check and keeps the comment of #544. - Before the ExclusiveStartKey check, this branch adds validate_query_key_sizes and #544 adds validate_key_condition_types. The merge runs the type check first, because the key size comment records a wrong-typed key value ahead of the size (measured 2026-10-23). On a single-attribute key schema #544 checks the type there and not in resolve_key_schema_with, so the key size comment now says "checked above".
demohan
left a comment
There was a problem hiding this comment.
The Select order rows hold at 66b82ec. On a KEYS_ONLY GSI with Select: ALL_ATTRIBUTES and no ExclusiveStartKey, the service answers each of the six faults ahead of the Select sentence, twice each in us-east-1, and the rows assert those texts: the Limit 0 constraint, Query condition missed key schema element: g, Condition parameter type does not match schema type, unused in expressions: keys: {:w}, The expression can not be empty;, and FilterExpression # by its label (#1419 tracks the wording). The order file passes against the service twice, 25 of 25, and a SQLite server built from this head passes the seven Query wire files twice, 294 of 294, where main answers the Select sentence for all six. Moving the Select check one step earlier at a time makes exactly one more of the six rows fail each time, so each row holds its own step.
The fix commit touches only test_query_key_size_order.py, and the other 11 files are as reviewed. fmt, core (1182) and engine (892) tests, and the 1.91.1 check of both crates are clean.
Main is at e8b5f10, three commits past 01556cf: #481, #1137 and #1403. #1403 adds a v1.2.0 entry for #606 at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, where this branch adds its v1.2.0 entry. That is the one conflict. The merge keeps both entries, the entry of main first. Git merged crates/engine/src/lib.rs with no conflict. Main adds a test module there, and this branch adds serialization_exception.
The base merges main at e8b5f10 through #1260, which brings #481, #1137 and #1403. #1403 adds a v1.2.0 entry for #606 at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, above the entry of #1260. Git merged the file with no conflict, so the order is #606, #1260, then the entry of this branch.
Main is at c8e66fb, six commits past 01556cf: #481, #1137, #1403, #1465, #1515 and #1411. #1403 and #1411 add v1.2.0 entries at the top of "Behavior Changes by Release" in docs/manuals/07-upgrade-manual.md, where the entry of this branch goes next. The merge has no conflict. Git merged crates/core/src/types/table.rs and crates/engine/src/lib.rs at other lines. In table.rs, main changes the members of a DELETING table in TableDescription, and this branch adds the ReplicaUpdates member of UpdateTableInput. In lib.rs, main declares a test module, and this branch declares nested_enums and adds enum_constraint. The lines that this branch changes are the same before and after the merge.
The base merges main at c8e66fb, which brings #481, #1137, #1403, #1465, #1515 and #1411, and adds the v1.2.0 entries of #1110 and #1114 to docs/manuals/07-upgrade-manual.md. The merge has no conflict. Git merged two files at other lines. In crates/core/src/types/table.rs, main changes the members of a DELETING table in TableDescription, and this branch changes the doc comment of the SSESpecification member of UpdateTableInput. In crates/storage-mongodb/src/table_engine.rs, main makes the creation time of a table description optional, and this branch records the specification in update_table.
Main is at c8e66fb. This branch last had main at 14ade59. Since then, 33 PRs merged into main, #1482 among them, which fixes the WebAssembly build. Git merged every file with no conflict. Main did not change the three files of this PR: crates/engine/src/query_key_values.rs, crates/engine/src/query_key_values/request_order_tests.rs and tests/test_query_key_value_types.py. #481 changed crates/engine/src/query.rs, which this branch does not change.
Main is at c057660, 35 commits after the last merge (80490c6). Three files conflicted. crates/engine/src/expression_helpers.rs: #1449 moved check_expression_size from this file to crates/core/src/expression/kind.rs. This branch adds check_expression_size_with, which takes the length suffix from the caller, and check_expression_size calls it. The merge puts check_expression_size_with in kind.rs beside check_expression_size, which now calls it, and exports it from extenddb_core::expression. The engine copies of both functions go, so the size check and its message stay in one place. The import list is the list of this branch with the two size checks added. crates/core/src/expression/mod.rs: in the module list, #1449 adds search_filter and search_params, and this branch adds semantics. The merge keeps all three in name order. docs/differences-from-dynamodb.md: this branch adds the row on a table ARN in TableName, and #1411 adds two rows on a DELETING table at the same place. The merge keeps the three rows. Git merged 13 other files that both sides change, with no overlap. In crates/engine/src/query.rs, #481 adds the key size check and moves the Select index check after the ExclusiveStartKey checks. Both checks come after the request-stage checks and the table lookup of this branch. In core, the other files are crates/core/src/expression/evaluator.rs and its tests, and crates/core/src/validation/mod.rs. In the engine, they are crates/engine/src/lib.rs, crates/engine/src/partiql/mod.rs and the two transaction files. In the storage crates, they are crates/storage-cassandra/src/backup_engine.rs, crates/storage-mongodb/src/table_engine.rs, the ddl.rs files of the PostgreSQL and SQLite crates, and crates/storage-sqlite/src/data/query_scan.rs.
…ests #481 adds crates/engine/src/query_key_size_tests.rs, whose run helper parses each key condition with parse_key_condition_expr and gives it only the expression and the limits. On this branch that function also takes the expression maps. It refuses a #name or :value that the request does not define. So the engine tests did not compile after the merge of main at c057660. The helper now builds the maps first. Every placeholder of the tests is in them, so each row still reaches the size check.
Main is at c057660, 20 commits after 5026c89, the main commit of the last merge (009c4c1). No file conflicted. Two files that this branch changes also change on main. Git merged both with no overlap: - crates/engine/src/lib.rs: #481 adds the query_key_size_tests module next to the scan_request module of this branch. - crates/server/src/request_helpers.rs: #1290 changes how extract_operation builds the MissingAuthenticationToken error. This branch changes authorize_request.
Changes since the last review
mainat 80490c6, which adds fix(metrics): bound latency segment memory by summing into fixed time buckets #398, docs(design): describe the query cursor as the row comparison the code emits #428, fix(query): check Query values against the key schema and the number rules #544, fix(expression): report a character outside the grammar without closing the connection #567, docs: describe the PostgreSQL read replica mode as a proposal #584 and fix(query): bound begins_with on a string sort key by the next prefix #588. Two files conflicted with fix(query): check Query values against the key schema and the number rules #544. In the module list ofcrates/engine/src/lib.rs, the merge keepsquery_key_size_testsandquery_key_valuesin name order. Inhandle_query, the merge removes the early Select check, as this PR does. It keeps the comment of fix(query): check Query values against the key schema and the number rules #544 in place of theLimitcheck, which fix(query): check Query values against the key schema and the number rules #544 moves to request time. It runs the type check of fix(query): check Query values against the key schema and the number rules #544 above the key size check. For a 2049-byte S value on an N key, the service answers the type sentence (measured 2026-11-20). On a single-attribute key schema fix(query): check Query values against the key schema and the number rules #544 checks the type in that call, so the key size comment now says "checked above".cargo fmt --checkis clean. Both clippy commands of.github/workflows/clippy.ymlwith-D warningsare clean onextenddb-coreandextenddb-engine, and so iscargo +1.91.1 check --all-targetson the same crates. The lib tests give 1193 passed and 1 ignored in core, and 935 passed in engine.--collect-onlycollects 7176 tests intests/and 777 intests/python, with no error. Against a SQLite server built from 8de48e2, the three key size files and the three Query wire files of fix(query): check Query values against the key schema and the number rules #544 give 434 passed. The clippy step of.github/workflows/wasm.ymlpasses with the two commits of fix(core): read the latency segment clock through web_time #1482 applied. Those commits fix the WebAssembly build ofmain, which fix(metrics): bound latency segment memory by summing into fixed time buckets #398 broke.#row checks theInvalid FilterExpression:label only (A#or:followed by a character that cannot start a name gets ExtendDB's own text, where DynamoDB answers a syntax error at the#or:#1419).Reviewed at ee58827 on 25 November:
Nvalue of ASCII characters that the number rules do not read as a number now gets the service's sentence,The parameter cannot be converted to a numeric value:followed by the value. The empty value gets the colon too. Before, a3f733d sized such a value as 0 bytes. On SQLite at 1e5f4bc the Query then got HTTP 200 with Count 0, orInternalServerErroron an N sort key. A value with a character outside ASCII still adds nothing to the size (Unicode decimal digits in N values: refused on writes, compared as text on reads #565).abc, 2049x," 1", the empty value and1e-131in four key positions.tests/pythonhold no expected failures, and ExtendDB gives the service's 38-digit sentence for 39 or more U+FF11 only with Unicode decimal digits in N values: refused on writes, compared as text on reads #565. The measurements are on Unicode decimal digits in N values: refused on writes, compared as text on reads #565.What
This change adds the key size check on Query, with the service's sentences and ordering.
crates/core/src/validation/key_size.rs: the check, with the limits from the configuration and the sentences naming them. Each key attribute contributes its largest value once. The check reads each N value withnormalize_numberbefore it sizes the value. The check refuses ASCII text that is not a number with the number's sentence. It refuses a value over the 38-digit limit or out of range the same way. A value that is not a number and holds a character outside ASCII adds nothing to the size. The service reads Unicode decimal digits as digits, and these rules do not (Unicode decimal digits in N values: refused on writes, compared as text on reads #565). A refusal here would refuse one U+FF11, which the service reads as the number 1. fix(query): check Query values against the key schema and the number rules #544, now onmain, runs the number rules on everyExpressionAttributeValuesnumber at request time, after it folds Unicode decimal digits. fix(query): check legacy conditions against the key schema #507 runs them on everyKeyConditionsvalue at request time. Once fix(query): check legacy conditions against the key schema #507 merges too, they answer before the table lookup, as the service does, and no value reaches the number refusals insized_clause. Until then aKeyConditionsvalue can reach them, so this PR keeps the refusals, and whichever of this PR and fix(query): check legacy conditions against the key schema #507 merges second removes them. Unit tests invalidation/key_size/tests.rs.handle_querycalls it after the expression validations and before the start key checks. The Select check for a GSI projection now runs once, after the start key checks. Before, it ran first when the request had no ExclusiveStartKey.docs/dynamodb-limits.md: the partition key cell names the HASH sum. The sort key cell says that the check adds up one sort key value per attribute, with aBETWEENcounted by its larger bound.Why
The service refuses a Query whose key condition values exceed the key size limits before it reads anything. ExtendDB ran the Query.
Closes #435.
Pre-existing, measured, not changed here
#489 tracks the first three.
The BETWEEN condition was provided a range where the lower bound is greater than the upper bound). ExtendDB runs it, or answers the range sentence when a bound is over 1024 bytes.pk = :a AND pk = :b: the service answersInvalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per keybefore the table lookup. ExtendDB serves the request, as main does, unless the larger value alone is over the limit. Then the request gets the size sentence. fix(core): refuse a second condition on a key in KeyConditionExpression #484 adds the refusal.Filter Expression can only contain non-primary key attributes: Primary key attribute: pk, also with a 2049-byte key value. ExtendDB serves the request, or answers the size sentence when a key value is over the limit.KeyConditionsNvalue that is not a number or has 39 digits, ExtendDB answersResourceNotFoundException, as main does. The size check needs the key schema, so it runs after the table lookup. The service answers the number sentence before the lookup. fix(query): check Query values against the key schema and the number rules #544, now onmain, gives that answer forExpressionAttributeValues, and fix(query): check legacy conditions against the key schema #507 gives it forKeyConditions. Once fix(query): check legacy conditions against the key schema #507 merges, no value that is not a number reaches the size check. Whichever of this PR and fix(query): check legacy conditions against the key schema #507 merges second can then remove that arm.Nvalue of 39, 683 or 2049 U+FF11: the number rules do not read it as a number. ExtendDB serves the Query, or answersInternalServerErroron an N sort key on SQLite, as main does. The service answers the 38-digit sentence. Unicode decimal digits in N values: refused on writes, compared as text on reads #565 tracks it, with the measurements of 2026-11-24.Overlaps with other PRs
git merge-tree --write-treeof 8de48e2 against each PR open on 2026-11-25 that changes the same files gives this list. For #399 and #507, the check uses their merges of the samemain. Each line is a conflict that this PR causes: the PR merges with main without a conflict in that file.docs/dynamodb-limits.mdcrates/engine/src/query.rsdocs/dynamodb-limits.mddocs/dynamodb-limits.mddocs/dynamodb-limits.mdcrates/engine/src/query.rs,crates/engine/src/lib.rscrates/core/src/validation/mod.rscrates/core/src/validation/mod.rscrates/engine/src/lib.rscrates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rscrates/engine/src/query.rs,crates/engine/src/lib.rsIn
crates/engine/src/lib.rsthe conflict is themod query_key_size_tests;line next to a module line that the other PR changes. Inquery.rsthe conflicts are at the early Select check, which this PR removes, and at the size check's position. With #507 they are at the comment of #544 on theLimitcheck and at the Select check. Both PRs move the Select check below the start key checks. All of these PRs except #507 and #826 also conflict with main, in other files.Related
pk = :v AND #n = :w,#nundefined) is unit level only. ExtendDB has no undefined-name refusal for a sort key clause today. fix(query): refuse a key condition with no HASH equality the way the service does #479 adds it, and with both merged the row matches the service.Index nope not foundinsideIndexNotFound, so the Query sentence readThe table does not have the specified index: Index nope not foundon Cassandra only. fix(query): refuse a Query ExclusiveStartKey the key condition cannot reach #483 fixed this on main on 3 November. This branch carries the same change, and its diff against main no longer touches the Cassandra backend.Order by currently only supports the ordering of columns following their declared order in the PRIMARY KEY), because the data table's clustering key issk_s, sk2_s, ..., base_pkand the Query emitsORDER BY sk_s, base_pk. The refusal surfaces asInternalServerError, with or without a RANGE clause, for any value size. This is not a one-line change, because the single sort key model also drives the pagination restrictions and the start key read. That was the state on 2026-10-24. The Cassandra CI run at d259b6f serves theidxaccept row ona, and the wire files no longer skip onInternalServerError.Testing done
Service measurements
Measured on the service in us-east-1, on 2026-10-23 unless a row says otherwise (every row repeated, identical answers):
One or more parameter values were invalid: Size of hashkey has exceeded the maximum size limit of2048 bytes(no space afterof)One or more parameter values were invalid: Aggregated size of all hash keys has exceeded the size limit of 2048 bytesOne or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytesxxand 341 plusxaccepted#nameor:valuein the key condition with an oversized value1followed by 2100 zeros (measured 2026-11-20)Attempting to store more than 38 significant digits in a Numberfor the digit counts, andNumber overflow. Attempting to store a number with magnitude larger than supported rangefor the zeros. The number rules come before the size check.abc, 2049x," 1"or the empty value (expression or KeyConditions), on a table that does not exist (measured 2026-11-24)The parameter cannot be converted to a numeric value:followed by the value as sent, with nothing after the colon for the empty value, before the table lookup1e-131as a partition key or a sort key value (expression or KeyConditions), on a table that does not exist (measured 2026-11-24)Number underflow. Attempting to store a number with magnitude smaller than supported range, before the table lookuppk = :a AND pk = :bwith 1025 and 1025 bytes or with 2049 and 1 bytes, andpk = :p AND sk = :a AND sk = :bwith 600 and 600 bytes, on a table that does not exist (measured 2026-11-24)Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key, before the table lookupSelect=ALL_ATTRIBUTESon a KEYS_ONLY GSI with a 2049-byte value, with or without ExclusiveStartKey (measured 2026-11-20)The ordering measurements used a 2049-byte value. The service reports filter syntax, unused names and values, index name, ConsistentRead on a GSI and missing table before the size check. It also reports Limit, projection syntax and overlap, the Select conflicts and the filter operand type before it. It runs the ExclusiveStartKey checks after the size check. The Select check for a GSI projection comes after both (the size order measured 2026-11-20, the start key order 2026-10-24).
Without an ExclusiveStartKey, the service also answers each of these faults before the Select sentence on a KEYS_ONLY GSI. In the review of 24 November, demohan measured each one twice:
#Tests
tests/python/test_query_key_size.py,test_query_key_size_values.py,test_query_key_size_order.py(shared fixtures inquery_key_size_support.py): 105 rows. b255fe5 adds 20 of them:abc, 2049x," 1", the empty value and1e-131, each in four key positions. Two positions are on a GSI keyed on an N attribute, one in the expression and one in KeyConditions. The other two are the N partition key and the N sort key of a table. 66b82ec adds 6, the Select order rows on a KEYS_ONLY GSI. Each refusal row asserts the full sentence except five whose label or parser wording differs between ExtendDB and the service (Query: shapes the service refuses that ExtendDB accepts or words differently (measured 2026-10-23) #489, Query with an undefined:valueor#namein its key condition gets other texts than DynamoDB, which answers Invalid KeyConditionExpression and names the reference #1251, A#or:followed by a character that cannot start a name gets ExtendDB's own text, where DynamoDB answers a syntax error at the#or:#1419). Those five assert the text around the difference. The other 79 rows passed against the service on 2026-11-20. The review of 25 November reports that the 20 rows of b255fe5 passed twice against the service. The 6 rows of 66b82ec have not run against the service. Their expected answers are demohan's measurements of 24 November.require_served). CI at ee58827 passed 64 of 64 checks.cargo test --libpasses 1182 tests inextenddb-coreand 892 inextenddb-engine.test_query_start_key_partition.py.n.len()arm, the 2049xand 2049 U+FF11 rows fail. With the old loop, the two rows with a second clause on one attribute fail.abc, 2049x," 1"and the empty value fail. 12 of them get HTTP 200 and the 4 on the N sort key getInternalServerError. With the 0-byte arm put back in the unit code, the unit table fails. With the text ofNumberFault::Empty, the empty value row fails. Without the ASCII condition, the row for one U+FF11 fails.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 Query whose key condition carries a value over the key size limits now gets the service's
ValidationException. Before, ExtendDB served it with no items. A Query whose key condition carries anNvalue of ASCII characters that is not a number now getsThe parameter cannot be converted to a numeric value:followed by the value. Before, ExtendDB served it with no items, or answeredInternalServerErroron an N sort key on SQLite. On a GSI whose projection is not ALL, a Query withSelect=ALL_ATTRIBUTESand a second fault now gets the second fault. Examples areLimit: 0and an oversized key value. Before, without an ExclusiveStartKey, it got the Select sentence. The service answers the second fault. Stored data, the configuration and the API do not change.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.