Skip to content

fix(parser): support OFFSET without LIMIT - #27021

Merged
XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:m-26769
Aug 14, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:m-26769

Conversation

@iamlinjunhong

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #26769

What this PR does / why we need it:

fix(parser): support OFFSET without LIMIT

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review completed on exact head dc1ae1af8c455a03b31c9cab5ef3c4817a9d412a.

Changes requested:

  • [P1] Preserve OFFSET as an implicit alias. Giving the token precedence with %nonassoc OFFSET makes the parser commit to the pagination clause before it knows the following context. This head rejects existing valid inputs such as select 1 offset, select 1 offset from t, and select * from t offset; the exact base 052b2fdcebce6d8d093624773c03ef3f92afeaef accepts them. This is a backward-compatibility regression while OFFSET is still intentionally listed as an unreserved keyword. Please preserve projection/table alias behavior and add regression controls for both.

  • [P1] Cover offset-only pagination after a parenthesized SELECT query expression. The two select_no_parens alternatives beginning with select_with_parens still accept only limit_clause, so (select 1) offset 1 and with cte as (select 1) (select * from cte) offset 1 fail on this head, while their LIMIT counterparts pass. Please extend those grammar paths and add focused parser cases.

The new direct SELECT ... OFFSET parser test passes, generated parser output is reproducible, and the failures above come from focused counterexample probes.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: query_limit_opt is used for simple SELECTs, but the select_with_parens branches still take limit_clause (including the CTE counterpart). As a result, an existing accepted form such as (SELECT 1) LIMIT 1 has no OFFSET-only counterpart: (SELECT 1) OFFSET 1 fails to parse. Please use query_limit_opt in those branches and cover parenthesized SELECT (and CTE) forms.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review completed on exact head dc1ae1af8c455a03b31c9cab5ef3c4817a9d412a.

  • [P1] Preserve existing implicit aliases named offset. Making OFFSET non-associative at pkg/sql/parsers/dialect/mysql/mysql_sql.y:347 makes the parser commit to pagination before the following context is known. This head rejects select 1 offset, select 1 offset from t, and select * from t offset; the exact base 052b2fdcebce6d8d093624773c03ef3f92afeaef accepts all three. OFFSET remains an unreserved keyword, so this is a backward-compatibility regression. Please preserve both projection and table implicit-alias paths and add base-vs-candidate regression controls.

  • [P1] Close the parenthesized-query grammar paths. The select_with_parens alternatives at lines 6388 and 6400 still consume limit_clause instead of query_limit_opt, so (select 1) offset 1 and with cte as (select 1) (select * from cte) offset 1 fail even though the corresponding LIMIT forms work. Please update both plain and WITH branches and add focused parser tests.

I reproduced both failures with isolated parser probes; the alias controls pass on the exact base. The existing parser package, new limit-binder tests, git diff --check, and vet pass, which confirms that current green tests do not cover these counterexamples.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

@aptend @aunjgr @XuPeng-SH Thanks for the focused counterexamples. They are addressed on exact head 7c46521f57aa8c61d3b132884ebaf22bb1d91865:

  • The contextual scanner keeps OFFSET non-reserved when it is an implicit projection/table alias. Regression coverage includes SELECT 1 offset, SELECT 1 offset FROM t, SELECT * FROM t offset, comment-separated aliases, and derived-table aliases.
  • Both plain and WITH parenthesized-query paths now accept offset-only pagination, including (SELECT 1) OFFSET 1, WITH cte AS (SELECT 1) (SELECT * FROM cte) OFFSET 1, and outer ORDER BY variants.
  • Compatibility controls also cover offset(1) as a function name, offset as a table name, prepared OFFSET ?, and OFFSET (1).

Fresh verification on this exact head:

.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s ./pkg/sql/parsers/dialect/mysql -run "Test(OffsetWithoutLimit|ScannerContextualOffset)$"

Result: PASS (ok github.com/matrixorigin/matrixone/pkg/sql/parsers/dialect/mysql 1.013s). The exact-head Ubuntu UT, coverage, and BVT checks are also green. Please re-review the current head when convenient.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep review completed on exact head 7c46521f57aa8c61d3b132884ebaf22bb1d91865 against base bdbd613fdece966769eb68481a3e58bfbc36b30c.

Changes requested:

  • [P1] Finish preserving implicit aliases named offset across every legal follower. The contextual lookahead in scanner.go:903-908 has an ad-hoc terminator list that omits at least BY, INTERVAL, and FULL. Exact-base controls demonstrate the regressions:

    • SELECT 1 offset BY RANK WITH OPTION 'nprobe=1' parses on base as select 1 as offset by rank ..., but this head returns a syntax error.
    • SELECT * FROM t offset FULL JOIN u ON t.a = u.a parses on base with table alias offset, but this head returns a syntax error (same for FULL OUTER JOIN).
    • SELECT 1 offset INTERVAL(ts, 1, day) has Limit == nil and a non-nil time window on base; this head silently changes it to a non-nil Limit.Offset and no time window.

    Please make the decision cover the grammar's complete alias follow set (rather than a partial token list) and add these base-compatibility controls.

  • [P1] Preserve the implicit derived-table alias column-list form with whitespace. SELECT * FROM (SELECT 1) offset (c) is accepted on the exact base as select * from (select 1) as offset(c) with no query limit. On this head it is silently reinterpreted as query pagination (Limit.Offset != nil) and formats as select * from (select 1) offset (c). The new test covers AS offset(c), but that does not protect the existing optional-AS form. Please resolve this ambiguity without changing the pre-existing alias AST and add a focused regression.

The author's previously reported projection/table alias and parenthesized-query cases now pass. I also verified the full MySQL parser and plan packages, reproducible zero-conflict parser generation, build, vet, and git diff --check; the findings above are focused counterexamples not covered by the green suite.

@iamlinjunhong

Copy link
Copy Markdown
Contributor Author

@XuPeng-SH Addressed the current-head findings in a58c111ad05893a00f1b588477f0b310db8aa0dd:

  • Replaced the partial follower check with a grammar-grouped complete alias follow set, including BY, INTERVAL, FULL, plus the related query suffix, join, UPDATE SET, index-hint, and terminator paths.
  • Preserved FROM (SELECT ...) offset (c) using a single-pass lexer table-factor/parenthesis context, rather than treating every ) OFFSET (identifier) as an alias. Controls confirm SELECT (1) OFFSET (c) and (SELECT 1) OFFSET (c) remain pagination.
  • Added nested/comma derived-table, parser-reuse/reset, ANSI-quote, malformed-expression, rank, interval, and FULL/FULL OUTER JOIN controls.

Fresh verification after the final edit:

  • deterministic build + vet: PASS
  • full MySQL parser package: PASS
  • full pkg/sql/plan: PASS
  • parser generation twice: zero conflicts, identical f75229e0584a2c0d24962482be711f737841243c
  • git diff --check: PASS

@mergify mergify Bot added the queued label Aug 14, 2026
@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 03:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-08-14 04:09 UTC · at bed4f35dc8d3b27940828c6de94e76c8cd1df270

This pull request spent 44 minutes 36 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
  • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • check-success = Matrixone CI / UT Test on Ubuntu/x86
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 05:04 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-14 08:39 UTC · at d15e3c5d28932a9beaa54ec03a8ad3f6e62ab156

This pull request spent 3 hours 34 minutes 59 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
  • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • check-success = Matrixone CI / UT Test on Ubuntu/x86
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

Reason

Pull request #27021 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@mergify mergify Bot removed the dequeued label Aug 14, 2026
@XuPeng-SH
XuPeng-SH merged commit 2909687 into matrixorigin:main Aug 14, 2026
25 of 26 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 14, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants