Skip to content

fix(query): refuse key condition values over the key size limits - #481

Merged
LeeroyHannigan merged 26 commits into
mainfrom
fix/435-query-key-size
Dec 2, 2026
Merged

LeeroyHannigan merged 26 commits into
mainfrom
fix/435-query-key-size

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

Reviewed at ee58827 on 25 November:

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 with normalize_number before 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 on main, runs the number rules on every ExpressionAttributeValues number at request time, after it folds Unicode decimal digits. fix(query): check legacy conditions against the key schema #507 runs them on every KeyConditions value 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 in sized_clause. Until then a KeyConditions value 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 in validation/key_size/tests.rs.
  • handle_query calls 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 a BETWEEN counted 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.

Overlaps with other PRs

git merge-tree --write-tree of 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 same main. Each line is a conflict that this PR causes: the PR merges with main without a conflict in that file.

PR File
#491 docs/dynamodb-limits.md
#507 crates/engine/src/query.rs
#523 docs/dynamodb-limits.md
#530 docs/dynamodb-limits.md
#537 docs/dynamodb-limits.md
#562 crates/engine/src/query.rs, crates/engine/src/lib.rs
#595 crates/core/src/validation/mod.rs
#826 crates/core/src/validation/mod.rs
#850 crates/engine/src/lib.rs
#854 crates/engine/src/lib.rs
#1260 crates/engine/src/query.rs, crates/engine/src/lib.rs
#1313 crates/engine/src/query.rs, crates/engine/src/lib.rs
#1355 crates/engine/src/query.rs, crates/engine/src/lib.rs
#1364 crates/engine/src/query.rs, crates/engine/src/lib.rs
#1368 crates/engine/src/query.rs, crates/engine/src/lib.rs
#1370 crates/engine/src/query.rs, crates/engine/src/lib.rs

In crates/engine/src/lib.rs the conflict is the mod query_key_size_tests; line next to a module line that the other PR changes. In query.rs the 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 the Limit check 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

  • The undefined-name row (pk = :v AND #n = :w, #n undefined) 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.
  • Cassandra, two things the new rows exposed, both reproduced on a cassandra:4.1 node:
    • The Cassandra backend wrapped a missing index name as Index nope not found inside IndexNotFound, so the Query sentence read The table does not have the specified index: Index nope not found on 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.
    • The Cassandra backend cannot read a multi-RANGE index at all. The node refuses every Query on such an index (Order by currently only supports the ordering of columns following their declared order in the PRIMARY KEY), because the data table's clustering key is sk_s, sk2_s, ..., base_pk and the Query emits ORDER BY sk_s, base_pk. The refusal surfaces as InternalServerError, 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 the idx accept row on a, and the wire files no longer skip on InternalServerError.

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):

Shape Service answer
HASH value of 2049 bytes (table, LSI, GSI, legacy KeyConditions) One or more parameter values were invalid: Size of hashkey has exceeded the maximum size limit of2048 bytes (no space after of)
HASH value of 2048 bytes accepted
Two HASH attributes, 1025 + 1024 bytes, or 2048 + 2048 One or more parameter values were invalid: Aggregated size of all hash keys has exceeded the size limit of 2048 bytes
Two HASH attributes, 1024 + 1024 bytes (measured 2026-11-20) accepted
Two HASH attributes, one value of 2049 bytes the single hash sentence
RANGE value of 1025 bytes, any operator; or RANGE values adding up to 1025 (512 + 513, 600 + 1 + 600, 600 + BETWEEN with a 600-byte larger bound) One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes
RANGE total of exactly 1024 bytes; BETWEEN with two 600-byte bounds accepted (BETWEEN contributes its larger bound)
Oversized HASH and RANGE in one request (with the aggregated sentence, measured 2026-11-20) the hash sentence (single or aggregated)
683 U+20AC characters (2049 bytes) in a HASH value; 342 (1026 bytes) in a RANGE value refused by UTF-8 byte length; 682 plus xx and 341 plus x accepted
Undefined #name or :value in the key condition with an oversized value the undefined-reference sentence first
An N value with 2049 or 39 digits (expression or KeyConditions), or 1 followed by 2100 zeros (measured 2026-11-20) Attempting to store more than 38 significant digits in a Number for the digit counts, and Number overflow. Attempting to store a number with magnitude larger than supported range for the zeros. The number rules come before the size check.
An N value written in U+FF11, or in U+0967 U+0968 (expression or KeyConditions, measured 2026-11-20) served: HTTP 200, Count 0
An N value of abc, 2049 x, " 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 lookup
An N value of 2049 U+FF11 (expression), or of 39, 683 or 700 U+FF11 (expression or KeyConditions), on a table that does not exist (measured 2026-11-24) the 38-digit sentence, before the table lookup
An N value of 1e-131 as 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 lookup
pk = :a AND pk = :b with 1025 and 1025 bytes or with 2049 and 1 bytes, and pk = :p AND sk = :a AND sk = :b with 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 lookup
Select=ALL_ATTRIBUTES on a KEYS_ONLY GSI with a 2049-byte value, with or without ExclusiveStartKey (measured 2026-11-20) the hash sentence. With a 1-byte value, the Select sentence.

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:

  • Limit 0
  • a key condition on the base table's partition key
  • an N value on the S key
  • an unused value
  • an empty KeyConditionExpression
  • FilterExpression #

Tests

  • tests/python/test_query_key_size.py, test_query_key_size_values.py, test_query_key_size_order.py (shared fixtures in query_key_size_support.py): 105 rows. b255fe5 adds 20 of them: abc, 2049 x, " 1", the empty value and 1e-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 :value or #name in 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.
  • CI at 31159a2: PostgreSQL 79 passed, SQLite 79 passed, MongoDB and Cassandra 77 passed and 2 skipped each. The skips are the two accept rows with a condition on a later RANGE attribute, which those backends refuse (require_served). CI at ee58827 passed 64 of 64 checks.
  • At 66b82ec: the three files on SQLite give 105 passed. cargo test --lib passes 1182 tests in extenddb-core and 892 in extenddb-engine.
  • Mutants against the wire files, each of which fails at least one row:
    • character-count sizing
    • BETWEEN by one bound only
    • the HASH sum removed
    • the aggregated sentence checked before the single one
    • the check moved above the filter parse or below the start key check
    • the Select check moved above the Limit check. The 6 rows of 66b82ec fail, and so do the two 2049-byte rows of their table and two start key rows in test_query_start_key_partition.py.
  • Controls for a3f733d and 482bf8a: with the old n.len() arm, the 2049 x and 2049 U+FF11 rows fail. With the old loop, the two rows with a second clause on one attribute fail.
  • Controls for 1fe3f0c: 1e5f4bc sizes a value that is not a number as 0 bytes. On a SQLite build of 1e5f4bc, the 16 wire rows for abc, 2049 x, " 1" and the empty value fail. 12 of them get HTTP 200 and the 4 on the N sort key get InternalServerError. With the 0-byte arm put back in the unit code, the unit table fails. With the text of NumberFault::Empty, the empty value row fails. Without the ASCII condition, the row for one U+FF11 fails.

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 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 an N value of ASCII characters that is not a number now gets The parameter cannot be converted to a numeric value: followed by the value. Before, ExtendDB served it with no items, or answered InternalServerError on an N sort key on SQLite. On a GSI whose projection is not ALL, a Query with Select=ALL_ATTRIBUTES and a second fault now gets the second fault. Examples are Limit: 0 and 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.

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.
… 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 demohan self-assigned this Nov 19, 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.

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.

  1. An invalid Number in the key condition gets the size sentence. The service sends its number sentence.
  2. With no ExclusiveStartKey, the Select check for a GSI projection runs before the size check. The service reports the size first.
  3. require_multi_range skips 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(),

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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:

  • abc and 2049 x answer The parameter cannot be converted to a numeric value: followed by the value, in KeyConditionExpression and in KeyConditions.
  • 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]

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Replaced in 001fe29 by number_values_get_the_number_rules_before_any_size, a table of N rows. It expects the number sentences for 2049 digits, 39 digits and 1 followed by 2100 zeros. It expects no refusal for 2100 zeros followed by 1, and, from 31159a2, for U+FF11 and for U+0967 U+0968.

Comment thread tests/python/query_key_size_support.py Outdated
err = exc.response["Error"]
if err["Message"] == MISSING_HASH_MESSAGE:
pytest.skip("multi-attribute range conditions need the #429 change")
if err["Code"] == "InternalServerError":

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 9061b23. The comment now says the type check runs above the size check, in resolve_key_schema_with.

Comment thread crates/core/src/validation/key_size.rs Outdated
/// 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

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 001fe29. The doc comment lists both shapes with the measured ones, and both rows pass against DynamoDB.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

001fe29 fixed the doc comment only. Two unit test comments still said "Not measured" for these rows. 762d4a8 moves both rows into the equality table of key_size/tests.rs, under the comment "Measured 2026-11-20 on two-hash".

/// - 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.
///

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread tests/python/test_query_key_size.py Outdated
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``,

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in b116a46 (the Python docstrings) and 9061b23 (the engine test comments). They cite the measurement date and the region, us-east-1, and no file outside the repository.

Comment thread tests/python/test_query_key_size.py Outdated
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,

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 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.

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.

@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit ac0c581 Dec 2, 2026
72 of 75 checks passed
@LeeroyHannigan
LeeroyHannigan deleted the fix/435-query-key-size branch December 2, 2026 21:54
LeeroyHannigan added a commit that referenced this pull request Dec 2, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 2, 2026
The base merges main at e8b5f10, which brings #481, #1137 and #1403.
The merge has no conflict. No file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 2, 2026
The base merges main at e8b5f10 through #1260, which brings #481,
#1137 and #1403. The merge has no conflict. No file has changes on
both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 2, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 2, 2026
The base merges main at e8b5f10 through #1260, which brings #481,
#1137 and #1403. The merge has no conflict. Main adds a test module to
crates/engine/src/lib.rs, where this branch adds single_write_refusal,
at other lines.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
The base merges main at c8e66fb, which brings #481, #1137, #1403,
#1465, #1515 and #1411, and adds the v1.2.0 entry of #1110 to
docs/manuals/07-upgrade-manual.md. The merge has no conflict, and no
file has changes on both sides.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
…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.
LeeroyHannigan added a commit that referenced this pull request Dec 3, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query does not enforce the key value size limits: 2048 bytes for the hash key, 1024 bytes for all range keys together

3 participants