You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
v2.2 part 1 — parameterized TOP / OFFSET / FETCH NEXT
The v2.1 parser required integer literals in paging slots; v2.2 admits
any scalar expression. Primary unlock: consumers can supply the page
size as a parameter rather than string-interpolating it into the SQL.
This was blocking 8 paging stored procs in CosmoMailServer's Phase C
migration plus the UPDATE TOP(n) claim-pending rewrites.
Surface:
SELECT TOP @n … ORDER BY id
SELECT TOP (@A + @b) … ORDER BY id -- arithmetic via parens
SELECT … ORDER BY id OFFSET @offset ROWS FETCH NEXT @limit ROWS ONLY
UPDATE TOP(@Batch) …
DELETE TOP(@n) …
AST: SelectStatement.Top/Offset/Fetch, UpdateStatement.Top, and
DeleteStatement.Top change from `long?` to `Expression?`. Literal TOPs
now wrap to LiteralExpression(SqlValue.From(n)).
Parser: SELECT's bare-form `TOP n` keeps a tight `ParseUnary()`-only
grammar to avoid the `SELECT TOP 10 * FROM t` wildcard-vs-multiplication
ambiguity. The paren form `TOP (n)` opens up to full ParseExpression,
matching T-SQL's spec — for non-trivial paging expressions you must
parenthesise. OFFSET / FETCH and UPDATE/DELETE TOP(n) all accept full
expressions (no wildcard ambiguity in those positions).
Executor: a shared EvaluatePagingExpression helper resolves the
Expression to a non-negative long using a dummy empty-row RowContext
(same pattern as the no-FROM SELECT path). Called once per statement
outside the scan loop so the cost is constant regardless of row count.
Phase 9 tests (9 cases): parameter-driven TOP/OFFSET/FETCH, arithmetic
in TOP-parens, UPDATE TOP(@Batch) for claim-pending, DELETE TOP(@n),
negative-parameter rejection, string-parameter rejection, and the
literal-TOP regression path. Full suite stable: 240/240 across 3 runs
(231 v2.1 + 9 new).
Unblocks: 8 of the 16 procs that throw NotSupportedException in
CosmoMailServer's CosmoKvCompatibilitySqlDatabase. Phase C resumes
once 2.2.0 ships.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments