Repository navigation
fix(partiql): raise the nesting caps to the depths the service reads - #1428
LeeroyHannigan wants to merge 1 commit into
Conversation
Parentheses round an operand nest as a group only. The parser still refuses a WHERE condition such as a = 1 + (b - c) for the +. It reads a run of NOT, CASE or PIVOT words before an operand in a loop. The group cap is 2000 and the operand cap 500. The service read 2000 levels of parentheses and 300 nested calls on 2026-11-24. The parser counts the calls and the + and - operators of the SET values apart from the condition. Past 300 it refuses the statement with the operator count text, which the service gives for 301 nested calls. The parse thread's stack is 128 MiB, about five times what the deepest statement within the length limit uses on a debug build. Closes #885
demohan
left a comment
There was a problem hiding this comment.
The raised caps are safe on the stack at 622684c, but one new count is reported ahead of refusals the service reports first, so ten statements main answered as the service does now answer otherwise. The deepest statement under the length limit needs 27,136 KB of stack in a debug build and 6,272 KB in release, about 4.7 times below the 128 MiB parse thread in debug, 48 other forms at the limit need no more, and debug and release servers on their default 2 MiB request threads answered every deepest statement and stayed up. fmt, clippy, the core and engine tests and the 1.91.1 check are clean, CI is green on 64 of 64, ten of fourteen negative controls fail as they should, and the branch merges with main at 222d80a and builds and passes there. No later merged PR fixes #885.
I will approve once the SET values' operator count comes after their other refusals, the deep statements' cost is bounded, and wire tests hold the order and the caps.
crates/core/src/partiql/parser/limits/tests.rs:1
No wire test was added, and the three PartiQL wire files pass the same on main, so none of them holds the change. Four controls pass where they should fail: the count moved after the SET refusals, LARGE_STACK_BYTES back to 64 MiB, the !in_where guard dropped, and the first word's answer kept in a NOT, CASE or PIVOT run. The "983 KB ... engine's translation included" comment does not hold on a table that exists: the engine refuses 151 or more nested calls there.
| }; | ||
| refusal = refusal.or(values); | ||
| refusal = refusal | ||
| .or_else(|| (self.value_operators > MAX_OPERATORS).then(too_many_operators)) |
There was a problem hiding this comment.
The SET values' operator count is reported before the SET values' other refusals. With 301 flat xN = a + 1 assignments beside any of 33 nested lists, y = -a, 1e200, 1e126, y = ? with no parameter, size(a), <<1,'a'>>, "" = 1 or 33 nested maps, the service in us-east-1 (twice each) and main give the other refusal, and this head answers with the operator count of 301, on SQLite and PostgreSQL. Counting after the SET value refusals and before the table lookup would match. The body's "main refuses all 196 differing statements as nested too deep" does not cover these.
| /// Parenthesized groups a condition, an operand, a value or an IN member may | ||
| /// nest. The service read 2000 levels round a name and round a path; the | ||
| /// depths it was measured at are in `measured_depths` in the tests. | ||
| pub const MAX_GROUP_DEPTH: usize = 2000; |
There was a problem hiding this comment.
The service runs more than this. It read 2001 to 2700 groups round a name and round a condition, and 2500 round a path, a SET value, an INSERT value and an IN member, and fails with InternalFailure only from 2800 (3000 for the second set), so the rows at cap+1 in the tests pin a refusal the service does not give. A cap nearer the measured depths, or a differences row for the gap, would say it. Separately, the service read 700 nested size calls in parentheses six times of six, and 1000 levels and 1355 plain calls, so the comment at lines 79-80 and 93-95 and measured_depths do not hold; + and - both count (line 236), and for b = 1 + (c - d) the service names the +, as this head does (walk/tests.rs:140).
| /// 2026-11-05: `SET x = ('a', 'b')` stores a list). The parentheses nest | ||
| /// as a group and not as an operand: the service reads 1001 levels of | ||
| /// them round a name, a string and a SET value (measured 2026-11-24). | ||
| fn operand_in_parentheses(&mut self) -> PResult<Operand> { |
There was a problem hiding this comment.
Each level of an operand in parentheses rescans forward through list_in_parentheses_ahead (predicates.rs:252), so the parse is quadratic in the depth, and this makes 2000 levels reachable: one statement at 2000 levels takes 13 ms, and a 100-statement ExecuteTransaction takes 1.18 to 1.20 s against 123 to 146 ms for the deepest one main accepts, with the parse holding a runtime worker meanwhile. Deciding the list once per group would keep it linear.
LJMart11
left a comment
There was a problem hiding this comment.
Reviewed at 622684c. 2 findings: 1 Important, 1 Docs.
The change raises the PartiQL parser's group cap to 2000 and its operand cap to 500, nests an operand in parentheses as a group only, reads runs of NOT, CASE and PIVOT in a loop, and counts the calls and +/- of the SET values against the 300-operator limit. Confirmed: the SET-value count matches the service when it is the only refusal (300 xN = a + 1 assignments give ConditionalCheckFailedException and 301 give operator count: 301, on the service twice each and on a SQLite server from this head; 150 + 151 across two values gives 301 on both); the NOT/CASE/PIVOT loop gives main's answer on 26 mixed runs in a WHERE condition and a SET value; a = 1 + (b - c) still names the +. Mutations of the count, the call and arithmetic counting, the parentheses hunk and the word loop each fail a test in limits/tests.rs or walk/tests.rs. The head merged with main builds under 1.94.0 and passes the core (1242) and engine (978) lib tests. The core (1147) and engine (871) lib tests pass at the head under 1.91.1.
- Important
crates/core/src/partiql/parser/walk.rs:351— The SET-value operator count is reported ahead of the number, function, nesting and parameter refusals the service reports first, so UPDATEs main answered as the service does now getoperator count: 301. - Docs
docs/manuals/07-upgrade-manual.md:385— After an upgrade, an UPDATE whose SET values hold more than 300 calls and+/-in total, such as 301xN = a + 1assignments, is refused with the operator count text where v1.1.0 ran it, and neither Behavior Changes by Release nor the PR body says so.
Docs — outside the diff
docs/manuals/07-upgrade-manual.md:385
Docs
After an upgrade, an UPDATE whose SET values hold more than 300 calls and +/- in total is refused (limits.rs:238-242, walk.rs:351), and Behavior Changes by Release has no entry for it. 301 assignments xN = a + 1, or 150 and 151 + in two values, get The expression contains too many operators; operator count: 301; the previous parser accepted both. The service refuses them too, but a workload that ran before now fails. The body says the parser refuses fewer statements and that main refuses all 196 differing random statements as nested too deep; neither covers this.
Fix: add a Behavior Changes entry for the SET-value operator count and list it under the body's breaking changes.
Evidence: the parser on UPDATE "tbl" SET x0 = a + 1, ..., x300 = a + 1 WHERE pk = 'q' answers OK at main and operator count: 301 here. A SQLite server from this head answers 400 ValidationException with that text, and 300 assignments get ConditionalCheckFailedException, as the service does (2 of 2 trials each).
| }; | ||
| refusal = refusal.or(values); | ||
| refusal = refusal | ||
| .or_else(|| (self.value_operators > MAX_OPERATORS).then(too_many_operators)) |
There was a problem hiding this comment.
Important
The SET-value operator count at walk.rs:351 comes before every other SET-value refusal, but the service reports several of those refusals ahead of the count. With 301 xN = a + 1 assignments plus one more assignment, the service answers Number overflow ... for y = 1e200, The function is not allowed in an update expression; function: size for y = size(a), Nesting Levels have exceeded supported limits under root[0]... for 33 nested lists, and Number of parameters in request and statement don't match. for y = ?. It gives those answers whether the extra assignment is written first or last. A SQLite server built from this head answers 400 ValidationException: The expression contains too many operators; operator count: 301 for all of them, on a table that exists and on one that does not. At main the parser accepts these statements, or gives the nesting text for the lists. A client that branches on the message gets a different answer, and nothing in the logs shows the reordering.
The service orders the unary - arity refusal by where it is written. y = -a written after the 301 assignments gets operator count: 301, which this head matches and main does not. Written first, it gets Incorrect number of operands ...; operator or function: -, number of operands: 1. Moving the count after .or(values) matches the service for the lists and for -a written first. It breaks -a written last, and it still answers the count for 1e200, size(a), <<1,'a'>> written last and ?.
Fix: report the count after the number-range, update-function, literal-nesting, bag and parameter-count checks. Order it against the sign refusal by token position, keeping the position where the count passed 300. Pin the 12 statements below in limits/tests.rs. The rows at limits/tests.rs:513-518 (nesting_forms) and the 301/440 rows of measured_depths (:684-690) are the ones the move touches.
Evidence: walk.rs:350-352 reads refusal = refusal.or_else(|| (self.value_operators > MAX_OPERATORS).then(too_many_operators)).or(values);. Live DynamoDB, UPDATE "noarev-1428-missing" SET x0 = a + 1, ..., x300 = a + 1, y = 1e200 WHERE pk = 'q' AND zz = 'never': Number overflow. Attempting to store a number with magnitude larger than supported range under root. This head on SQLite: 400 ValidationException: The expression contains too many operators; operator count: 301. With the count moved after .or(values), cargo test -p extenddb-core --lib partiql still passes (263 tests).
What
The PartiQL parser refuses fewer statements as nested too deep, up to the depths DynamoDB reads:
MAX_GROUP_DEPTH) is 2000, from 1000. Parentheses round an operand nest as a group only, so they no longer count against the operand cap.MAX_OPERAND_DEPTH) is 500, from 100.NOT,CASEorPIVOTwords before an operand in a loop. The answer is the last word's, as before, and the run costs no operand level.+and-operators of the SET values, apart from those of the condition. Past 300 it refuses the statement with the existing operator count text. The count is separate because DynamoDB runs 300 nested calls in a SET value with three more operators in the WHERE condition.LARGE_STACK_BYTES, the stack of the thread that parses a deep statement, is 128 MiB, from 64 MiB.The code:
crates/core/src/partiql/parser/limits.rs: the caps, the stack size,count_value_operator, and the module comment with the stack figures.crates/core/src/partiql/parser/operands.rs:operand_in_parenthesesnests as a group, and keeps its own part of the condition's walk, soa = 1 + (b - c)still names the+.crates/core/src/partiql/parser/terms.rs: the loop over a run ofNOT,CASEandPIVOTwords.crates/core/src/partiql/parser/walk.rsandparser.rs: the counter, and its refusal at the head of the SET part.No error text is new.
Why
DynamoDB was measured in us-east-1 on 24 November 2026 with ExecuteStatement, each statement twice. The SELECT statements named a table that does not exist. The UPDATE statements went to a table that does not exist, and to a table that exists. On the second table they named a key that no item has and a false condition, so no statement wrote an item. #885 gives the rows of 6 November.
RNFE stands for
ResourceNotFoundException, CCF forConditionalCheckFailedException. Both mean that the statement passed every check. On main the caps refuse each of these statements withStatement wasn't well formed, can't be processed: expression nesting depth exceeded.SELECT * FROM <T> WHERE pk = 'q' AND a =2000 parentheses roundbSELECT * FROM <T> WHERE pk = 'q' AND2000 parentheses rounda, then= 1bUPDATE <T> SET x =300 nestedif_not_existscallsThe expression contains too many operators; operator count: 301, on both tablesTesting done
cargo test -p extenddb-core --lib --no-fail-fast: 1147 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed. One backup restore test failed once under load. It passed in the next full run and in 5 runs alone, and this PR does not touch backup code.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.tests/test_partiql_grammar.py,tests/test_partiql_write.pyandtests/test_partiql_limits.pyagainst that build: 1414 passed, 3 skipped.Production is +106 -43 lines, 29 and 6 of them code. The tests are +227 -36.
The rows that still differ from DynamoDB:
NOTwords before a SET value, and 100: the parser reads them to the end and answersUnexpected operator, where DynamoDB names theNOT. fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410 gives that text.CASEwords, and 100:Unexpected keyword, where DynamoDB expects aWHEN. PartiQL (#411): ExtendDB refuses SET a = a + 1 + 1, and other parser forms and syntax texts differ #887 covers theCASEtexts.(size(a)):Expected a comparison operator. fix(partiql): read a condition function as an operand in a WHERE #1436, the fix for PartiQL WHERE: ExtendDB gives a syntax error after an unquoted size call, where DynamoDB reads the call as an operand #1415, reads these calls as operands. DynamoDB refuses the innersizefor its operand type, which PartiQL WHERE: a call as the operand of size or begins_with is not checked for its type, where DynamoDB refuses it #1434 tracks.sizecalls and 1,354 levels off(j[in a bracket stay above the operand cap. PartiQL: the operand cap of 500 refuses 1,355 nested size calls, which DynamoDB reads to the end #1425 tracks them.expression nesting depth exceeded, and DynamoDB runs these values. Expression depth limit refuses PartiQL if_not_exists the service runs, and the per-call reset is untested (follow-up to #1000) #1057 tracks this.Conflicts with the open PRs that change the parser:
limits.rswith fix(partiql): give call statements, nested queries and bag inserts the service's texts #1070, fix(partiql): read @ as an operator that takes a name #1386, fix(partiql): refuse AT or BY with no name after a FROM table #1389, fix(partiql): refuse quoted names and paths in literals as DynamoDB does #1393, fix(partiql): give literal syntax errors and tuple keys the service's texts #1398 and fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410: both sides rewrite the first paragraph of the module comment. Keep both sentences.walk.rswith the same PRs: both sides add a name to theuse super::limits::{...}line. Keep both.walk.rswith fix(core): refuse EXISTS outside a transaction ahead of other faults #1112: keep its rewrite of the paragraph of measured orders, and add the operator count of the SET values to its "Not measured" sentence.limits/tests.rs: those PRs move the stack tests intolimits/tests/stack.rs. This PR's edits toworst(),nesting_forms,measured_depthsanddeepest_that_parsemove with them.terms.rswith fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410: fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410'sNOTarm for a SET value reads oneNOTbefore the operand. So a run of 2031 would be refused as nested too deep again. The new arm must read the whole run withwhile self.eat_keyword("NOT") {}, and the old arm must skip such aNOTwhen it keeps the last word's answer. Over 19,839 runs of the three words, that merge answers as fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410 alone does, except 35 runs that fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410 alone refuses as nested too deep. With it, 2031NOTwords get DynamoDB's text.!self.in_insert) until DynamoDB's count for an INSERT is measured.Closes #885
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
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.