Skip to content

fix(partiql): refuse a LIMIT as an unsupported clause only after a SELECT - #1406

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1400-limit-after-writes
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1400-limit-after-writes

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

PartiQL refuses a LIMIT as an unsupported clause only after a SELECT, as DynamoDB does.

  • After a SELECT, a LIMIT still gets Unsupported clause: LIMIT, at the token after it. With nothing after it, the LIMIT now gets Statement wasn't well formed, can't be processed: Unexpected term.
  • After an UPDATE, a DELETE, an INSERT or an EXISTS statement, a LIMIT is now a token left over: Statement wasn't well formed, can't be processed: Unexpected token after expression. It is a syntax error, so it comes ahead of the refusals that wait for the statement to parse.

The code:

  • crates/core/src/partiql/parser.rs: the LIMIT arm of Parser::finish runs for a SELECT only, and answers a LIMIT at the end of the statement with term_error. Any other statement reaches the trailing_error arm.
  • The measured statements are one table in parser/tests/statements.rs, a_limit_is_an_unsupported_clause_only_after_a_select.

Why

DynamoDB was measured in us-east-1 on 23 November 2026 with ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, on the table "ets-parityat-missing", which does not exist. Each request went out twice, with the same answer both times. #1400 and its comment give the tables. "Not well formed" stands for the prefix Statement wasn't well formed, can't be processed: .

Statement DynamoDB ExtendDB on main
SELECT * FROM <T> WHERE pk = 'q' LIMIT 1 Unsupported clause: LIMIT at 1:59:1 the same
SELECT * FROM <T> WHERE pk = 'q' LIMIT not well formed: Unexpected term Unsupported clause: LIMIT at 1:53:1
UPDATE <T> SET a = 1 WHERE pk = 'q' LIMIT 1 not well formed: Unexpected token after expression Unsupported clause: LIMIT at 1:62:1
DELETE FROM <T> WHERE pk = 'q' LIMIT 1 not well formed: Unexpected token after expression Unsupported clause: LIMIT at 1:57:1
INSERT INTO <T> VALUE {'pk': 'q'} LIMIT 1 not well formed: Unexpected token after expression Unsupported clause: LIMIT at 1:60:1
EXISTS(SELECT * FROM <T> WHERE pk = 'q') LIMIT 1 not well formed: Unexpected token after expression EXISTS can only be used in ExecuteTransaction write requests.

In BatchExecuteStatement and ExecuteTransaction the UPDATE, DELETE and INSERT rows get the same syntax error. In ExecuteTransaction it comes after Validation failed in TransactStatements[0]: .

Two rows of #1400 put a refused value before the LIMIT: SET a = <<true>> and SET a = {1: 1}. On main the parser refuses those values while it reads them, so finish does not run and the value refusal stays. With this change on the head of #1398, where those refusals wait for the parse, both rows get the syntax error in the three operations. #1400 can close once this PR and #1398 have both merged.

Refs #1400

Testing done

  • cargo test -p extenddb-core --lib --no-fail-fast: 1146 passed, 1 ignored. cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed. cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • With main's parser.rs, the new test fails.
  • A SQLite release build of the commit answered 48 of 48 measured requests as DynamoDB does, in status, error type and message. It also gave DynamoDB's answer to 99 more requests that cover 36 more statements, measured afterwards in the three operations.
  • tests/test_partiql_check_order.py, tests/test_partiql_grammar.py and tests/test_partiql_phase3.py against that build: 1077 passed, 3 skipped.
  • With this diff on the head of fix(partiql): give literal syntax errors and tuple keys the service's texts #1398, cargo test -p extenddb-core --lib gave 1154 passed and 1 ignored.

Production code is +18 -12 lines, and the tests are +25 -1.

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.

…LECT

Measured on DynamoDB on 23 November 2026: a LIMIT after a SELECT is
"Unsupported clause: LIMIT" at the token after it. A SELECT with nothing
after its LIMIT gets "Unexpected term". After an UPDATE, a DELETE, an
INSERT or an EXISTS statement, the LIMIT is a token left over:
"Unexpected token after expression".

Parser::finish gave the unsupported clause refusal after every
statement. It now gives it after a SELECT only, gives "Unexpected term"
when the statement ends at the LIMIT, and answers the other statements
with the trailing token error.

On main a bag of BOOL or a number map key in an UPDATE value is refused
while the statement parses, so those two rows of #1400 keep their value
refusals. At the head of #1398, where those refusals wait for the parse,
they get the syntax error.

Refs #1400

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

A LIMIT is refused as an unsupported clause only after a SELECT at 1731ff6, and nothing main answers as the service does changes. Of 365 shapes sent twice to us-east-1 and to this head and main on SQLite and PostgreSQL, in ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, 151 move from main's answer to the service's and the two backends agree everywhere. Five controls fail as they should, fmt, clippy, the 1.91.1 check and the core and engine tests are clean, and CI is green on 64 of 64. It merges onto main at 222d80a without conflict, passes the 1.94.0 check and the tests there, and answers all 365 shapes as this head; merged with #1112 as well, it also answers them all alike, so the two do not conflict in order. No merged PR fixes #1400.

I will approve once a SELECT's LIMIT followed by any token that cannot start a term gets the service's term error, and BatchExecuteStatement and ExecuteTransaction have rows in the tests.

if s.eq_ignore_ascii_case("LIMIT") && matches!(stmt, Statement::Select(_)) =>
{
self.bump();
if matches!(self.peek().kind, TokenKind::Eof) {

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 gives the term error only when the LIMIT is the last token; the service gives it for any token that cannot start a term. In all three operations, ... LIMIT; and ... LIMIT ; get Unexpected term from the service and Unsupported clause: LIMIT at 1:57:1 here, though the body names that case as "nothing after it"; LIMIT = gets Unexpected operator, LIMIT ) Unexpected term, and LIMIT LIMIT and SELECT ... LIMIT WHERE ... Unexpected keyword from the service. Main answers these as this head does. Calling term_error for the end, a semicolon, a closing token, an operator or a keyword, or reading the value with operand() and then requiring the end as insert_without_value does, would match. The comment's "after any other statement it is a token left over" does not hold for a DELETE without WHERE: DELETE FROM T LIMIT 1 and its variants get Where clause does not contain a mandatory equality... here and on main (the missing WHERE is refused at statements.rs:421 before this runs), where the service gives Unexpected token after expression.

);
// After any other statement a LIMIT is a token left over.
let leftover = wf("Unexpected token after expression");
for sql in [

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.

These rows call only parse_for_execute_statement. BatchExecuteStatement and ExecuteTransaction go through parse_for_request, and restoring main's answer for those two alone (matches!(stmt, Statement::Select(_)) || !self.refuse_exists) passes all 1146 core and 871 engine tests. Rows for those two operations, EXISTS(...) LIMIT 1 above all, would hold them.

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.

2 participants