Skip to content

fix(engine): charge a batch UPDATE that refers to an absent attribute - #1217

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1178-batch-update-absent-charge
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1178-batch-update-absent-charge

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

In a BatchExecuteStatement, ExtendDB did not charge an UPDATE that fails at its item with The provided expression refers to an attribute that does not exist in the item. DynamoDB charges the write units of the stored item for this error. This change adds the text to UPDATE_FAILURES in crates/engine/src/partiql/batch.rs, the list of update errors that is_charged_failure charges.

The new entry is a literal, as the two entries before it are. The evaluator writes the same text as a literal in three places in crates/core/src/expression/update_evaluator.rs. A shared constant would change that file, which #1180 rewrites, so the copy stays.

Why

DynamoDB's answers, measured in us-east-1 on 19 and 20 November 2026 with "ReturnConsumedCapacity": "TOTAL" where the row does not name another value. Each request went out twice and got the same answer both times.

  • Table P has pk (S) as its key. Its item em-upd-operand holds a string s and a list k of 2 elements, and no attribute z.
  • Table G has pk and sk (S) as its key and the GSI gsi with an ALL projection, as tests/partiql_gsi_table.py creates it.
BatchExecuteStatement DynamoDB ExtendDB on main
P: SET a = 9 on em-upd-ok 1.0 1.0
P: the same, then SET a = z + s on em-upd-operand 2.0, with the absent text in the second response 1.0
P: SET a = z + s on em-upd-operand alone no ConsumedCapacity no ConsumedCapacity
P: SET a = 9 on em-upd-ok, then SET a = k[5] on em-upd-operand 2.0, with the absent text 1.0
G: SET a = 9 on one item, then SET a = z + gs on another 3.0 2.0
G: the same at INDEXES CapacityUnits 3.0, Table 1.0, gsi 1.0 2.0, Table 1.0, gsi 1.0
G: SET a = 9 on one item, then SET a = z + gs on an item of 3 KB 5.0 2.0

With this change, ExtendDB answers each row with DynamoDB's ConsumedCapacity. At INDEXES, the unit of the failed UPDATE goes to CapacityUnits alone. DynamoDB cancels an ExecuteTransaction with the same statements and returns no ConsumedCapacity. ExtendDB also cancels it with no ConsumedCapacity, and this change does not touch that path.

Fixes #1178

Testing done

  • cargo test -p extenddb-engine --lib: 870 passed. cargo test -p extenddb-core --lib: 1146 passed.
  • cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • The engine test failures_at_the_item_are_charged gets a row for the new entry.
  • Against ExtendDB on SQLite, tests/test_partiql_batch.py passed 171 tests, tests/test_partiql_requests.py 68 and tests/test_partiql_transaction.py 197, with 2 expected failures. The new row absent-attribute of test_a_failed_write_is_charged_on_its_table sends the first G request of the table. It fails on main's server, with 2.0 where it expects 3.0.

Line counts: production +4 -2, tests +5.

Not in this PR:

This PR adds no conflict with an open PR.

Checklist

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

ADR / RFC: n/a


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.

In a BatchExecuteStatement, DynamoDB charges the write units of an
UPDATE that fails because it refers to an attribute its item does not
have. ExtendDB returned the same error but did not charge the UPDATE.

DynamoDB gave the answers below in us-east-1 on 19 and 20 November
2026. Each request went out twice, with ReturnConsumedCapacity set to
TOTAL. The table has the partition key pk and holds an item with a
string s and no attribute z.
SET a = 9 on another item, then SET a = z + s on that item, cost 2.0
units. ExtendDB answered 1.0 before this change. SET a = 9 alone cost
1.0 on DynamoDB and on ExtendDB. Neither returned ConsumedCapacity for
SET a = z + s alone.

This change adds the error text of an absent attribute to
UPDATE_FAILURES, the list of update errors that is_charged_failure
charges. The charge is the write units of the stored item. On 20
November, DynamoDB charged 3 units for this error on an item of 3 KB.

Fixes #1178.

@navareamol navareamol 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 description says the evaluator writes the absent text "in three places" in crates/core/src/expression/update_evaluator.rs. I find it twice at this head and on main: line 137 (a SET value whose path has no value) and line 565 (a list index past the end in set_nested). Could you correct the count?

The new row in failures_at_the_item_are_charged builds its error from UPDATE_FAILURES[2], so it compares the list with itself. I changed the new entry's text in batch.rs and kept the array size: the engine lib tests still pass (978 of 978), and only the wire row absent-attribute fails. I think writing the literal text in the unit row would let the unit test catch a typo here, or a later change to the evaluator's text.

The charge is decided by the text alone, so every UPDATE that fails with the absent text is now charged. On SQLite with this branch merged with main, SET g = z on the GSI table (where g is the index key) is charged one unit (batch total 3.0, 2.0 on main), and so are SET a = z and SET a = list_append(z, [1]). The row index-key-type-is-not-charged shows DynamoDB does not charge SET g = 1. Has anyone measured whether DynamoDB charges SET g = z? If it does not, this case needs more than the text match; if it does, a row for it would pin that.

The branch merges with current main without conflict, and on the merged tree every row of the description's table reproduces on SQLite, including INDEXES and the 3 KB item. On main the new row fails with 2.0 where it expects 3.0.

I will approve once the count in the description is corrected and the SET g = z question is answered.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BatchExecuteStatement: an UPDATE that fails on an absent attribute is not charged, where DynamoDB charges its write unit

2 participants