Skip to content

fix(plan): push outer pagination into derived-table sorts - #32230

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
ck89119:issue-32014-main
Nov 5, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
ck89119:issue-32014-main

Conversation

@ck89119

@ck89119 ck89119 commented Nov 5, 2026 •

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:

Closes #32014

What this PR does / why we need it:

An outer LIMIT on an ordered derived table stays on its PROJECT, leaving the inner SORT unbounded and missing the existing Top-N path.

  • Compose outer LIMIT/OFFSET with eligible SORT pagination using the existing pagination helper.
  • Restrict the rewrite to column-only ordering and projections; preserve filters, grouping/window boundaries, computed ordering, and specialized vector-search candidate budgets.
  • Preserve outer literal LIMIT 0 so compilation omits all producer steps, rather than dropping only the consumer and hanging recursive CTE queries.
  • Add planner, physical-operator, and SQL regressions for nested/prepared pagination, unsafe rewrite boundaries, and multi-step zero demand.

Validation (Go 1.27.1):

  • Full pkg/sql/plan and pkg/sql/compile suites pass through mo-cgo-test; both modified functions have 100% statement coverage.
  • gofmt, incremental go vet, and golangci-lint 2.14.0 pass.
  • The new recursive-CTE compilation regression passes 100 repetitions under -race.
  • offset_without_limit.sql: 56/56 checks in two standalone runs and a two-CN run, including prepared LIMIT values 2 → 0 → 1 → 0.
  • Live SQL checks produce identical Top-N plans and rows for the derived and direct forms. No million-row latency benchmark was run.

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

@XuPeng-SH

XuPeng-SH commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dcf4195b63866ffdfda33e11dedf38687c1f68fa

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: dcf4195b63866ffdfda33e11dedf38687c1f68fa

Assessment: approve

The rewrite reuses existing pagination and Top-N machinery while preserving semantic boundaries and recursive zero-limit handling. No actionable defects found.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Reviewed the complete delta, affected consumers, linked issue and all discussion; saved review records.

  • Supplied frozen-head CI reports successful UT, static analysis, coverage and both multi-CN BVT groups.

  • Local audit passed source identity, diff/gofmt and independent expected-row checks for 31 queries across 56 SQL statements. Receipt: checks/1793882809279185775-2.json; log: review-audit-v3.log.

Limitations:

  • No local Go or MatrixOne execution; raw CI/author logs were unavailable. The independent SQL oracle validates expected rows, not MatrixOne execution.

  • No million-row latency benchmark; performance conclusions are limited to plan selection and existing Top-N behavior.

@mergify mergify Bot added the queued label Nov 5, 2026
@mergify

mergify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · checks failed

1 h 14 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Thu 5 Nov, 12:50 · rule main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in place
  • 🚫 Left the queue 14:04 · bd623d5

The failure is in this pull request. It failed tested alone on top of main.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — bd623d55 Deployed Nov 5, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: outer LIMIT not pushed into derived table with ORDER BY

3 participants