Skip to content

fix(sql): bind YEAR keys for numeric RANGE window frames - #33446

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-33171-33396
Nov 29, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-33171-33396

Conversation

@aptend

@aptend aptend commented Nov 29, 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:

Fixes #33171
Fixes #33396

What this PR does / why we need it:

Bind bounded numeric RANGE frames over YEAR in a signed integer domain while preserving YEAR result metadata. Reduce literal and prepared fractional offsets in the direction that preserves frame membership, including wide DECIMAL offsets. Reject a negative prepared offset before ceiling can turn it into zero. Reject YEAR INTERVAL bounds during planning for SELECT and EXPLAIN while preserving supported temporal intervals.

Validation

  • Native wire tests passed all nine subtests. The same prepared statement rejected -0.1 with error 20301 on an ending PRECEDING bound, then returned [NULL, 10] for 0.75 and [NULL, NULL] for 1.25.
  • Focused planner tests passed through mo-cgo-test. The signed RANGE BVT compared 35 of 35 statements successfully with mo-tester -n -g on the final native binary.
  • The pinned selector chose 111 affected packages against upstream main 6540533196. make static-check-selected STATIC_CHECK_PACKAGES="<selector output>" exited 0 with zero findings in default mode and with GOFLAGS=-tags=integration.

@aptend
aptend requested a review from XuPeng-SH as a code owner November 29, 2026 07:32
@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 →

@mergify

mergify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 1a0a35378efe419a7fced796e79089ecce458e08

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: 1a0a35378efe419a7fced796e79089ecce458e08

Assessment: request_changes

The change fixes the reported integer YEAR frames and rejects YEAR interval frames during binding. Reusing the signed-integer executor also narrows fractional RANGE offsets, however, causing incorrect window results. The existing signed-cast control shares that preexisting limitation and does not establish correct fractional behavior.

Model: gpt-6.1-terra / max

Session: 01a2230f-39de-7f00-bf9a-e19ded95bd85 · slot 0 · generation 39

  • P2 pkg/sql/plan/window_binder.go:1160: A bounded numeric RANGE frame orders by a YEAR column and uses a fractional offset, such as 0.75 PRECEDING.
    Impact: The frame can include rows outside the requested value range, silently producing incorrect window aggregates.
    Evidence: The YEAR key is cast to int64, and that type is also used to fold the offset; the decimal-to-signed conversion rounds 0.75 to 1. An isolated SQL wire probe with rows (2020, 10) and (2021, 20) returned [10, 30] for the YEAR key with 0.75 PRECEDING, while an equal-valued DECIMAL key returned [10, 20]. The retained log is year-fraction-wire-probe.log and its receipt is checks/1795945156418043684-2.json. The signed-cast control also has the existing narrowing behavior, but numeric RANGE offsets represent value differences under the MySQL frame specification. Preserve fractional offsets when selecting the arithmetic domain, including for prepared bounds, and add a regression test.

Validation:

  • The isolation preflight and git diff --check passed; receipts are checks/1795944437883840748-2.json and checks/1795944437826541106-2.json.

  • The repository's make cgo target built native prerequisites from an archive of the frozen head; receipt checks/1795944925392169292-2.json and native-build.log.

  • Both added planner tests and all four added SQL wire subtests passed; receipt checks/1795945218186651256-2.json and authored-focused-tests.log.

  • A decimal scaling probe passed and confirmed 0.75 rounds to 1 when converted to the integer domain; receipt checks/1795944997463761442-2.json and decimal-rounding-probe-native.log. The independent fractional SQL probe failed its expected-result assertion as described in the finding.

Limitations:

  • Local validation was focused and used an embedded single-node cluster. The full suite was not rerun locally; the frozen CI snapshot reports successful x86 unit tests and enabled multi-CN BVT checks.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: ee4f19a2d42df40dc16cf04e20401eb590d28292

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: ee4f19a2d42df40dc16cf04e20401eb590d28292

Assessment: request_changes

The earlier positive fractional-offset defect is addressed, and reusing the signed RANGE executor avoids a separate execution path. The new reduction accepts some invalid negative prepared offsets, and the change lacks the repository-required SQL BVT coverage.

Model: gpt-6.1-terra / max

Session: 01a22736-9882-7602-8165-f046f8cac12a · slot 0 · generation 40

  • P2 pkg/sql/plan/window_binder.go:1334: Execute an ascending YEAR RANGE frame such as BETWEEN UNBOUNDED PRECEDING AND ? PRECEDING with a prepared offset of -0.1.
    Impact: The invalid negative offset is accepted as zero, so the query returns window aggregates instead of rejecting the frame.
    Evidence: The YEAR path applies CEILING before the executor validates the bound; CEILING(-0.1) becomes zero, which passes the non-negative check in pkg/sql/colexec/window/window.go:224. The exact-head SQL probe returned aggregates 10 and 30 with no error. A DECIMAL(30,2) key rejected the same parameter, a YEAR offset of -1 was rejected, and a positive YEAR offset succeeded. See model-switch-1795957170740134145/negative-bound-probe.log and checks/1795957377102983905-3.json. Validate the original prepared value before reducing it, while retaining the directional rounding for valid offsets.

  • P2 pkg/tests/sqlintegration/window_year_range_wire_test.go:37: The PR changes SQL-visible YEAR numeric RANGE results and YEAR INTERVAL errors but adds only planner and Go wire tests.
    Impact: The maintained mo-tester BVT suite has no regression for either changed YEAR behavior.
    Evidence: The pinned .agents/skills/mo-dev/references/testing-contract.md:25 requires BVT public-path proof for SQL-visible results and errors; line 141 defines BVT under test/distributed/cases. Existing YEAR and window cases do not exercise a bounded RANGE on a YEAR key. Add focused YEAR numeric-frame and INTERVAL-rejection coverage to an appropriate existing window BVT case, update its expected results, and run it in comparison mode.

Validation:

  • Isolation preflight passed on the frozen head; native build inputs matched the assigned source.

  • Both selected planner tests passed: model-switch-1795957170740134145/planner-focused.log and checks/1795957450885692322-3.json.

  • All eight authored wire subtests passed within the combined run; that command exited 1 because the separate review probes failed. See model-switch-1795957170740134145/year-range-probe.log and checks/1795957298011427896-3.json.

  • The corrected negative-offset probe failed while its three controls passed: model-switch-1795957170740134145/negative-bound-probe.log and checks/1795957377102983905-3.json.

  • Receipt and discussion-key coverage reconciliation passed in model-switch-1795957170740134145/receipt-audit-final.log.

Limitations:

  • No mo-tester BVT or full package suite was run locally. The PR reports broader validation, but its detailed logs were not supplied.

  • The current sandbox does not permit writes to the assigned attempt-1 directory. The updated review plan and discussion-assessment.json are in model-switch-1795957170740134145; the assessment covers all five discussion keys.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 98eb4f10c600a3784a226e45482394dfde47f555

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: 98eb4f10c600a3784a226e45482394dfde47f555

Assessment: approve

The change reuses the signed RANGE executor while reducing YEAR offsets in the direction needed to preserve fractional frame membership. The earlier fractional-offset and negative prepared-offset concerns are addressed, and the added SQL regression case covers numeric YEAR frames and YEAR INTERVAL rejection.

Model: gpt-6.1-terra / max

Session: 01a227fa-9be9-7372-8896-a8b81f9696c9 · slot 0 · generation 43

Validation:

  • The authored SQL wire suite passed all nine subtests. An additional frontend probe passed unsigned and fractional prepared parameters on both frame edges. See year-bound-test.log and checks/1795972712619158809-2.json in the diagnostic directory.

  • Private /tmp and loopback preflight passed; native inputs matched the frozen source. See preflight.log and native-inputs.log with receipts checks/1795972377544333376-2.json and checks/1795972408741989732-2.json.

  • git diff --check passed: diff-check.log and checks/1795972585628345698-2.json.

  • The frozen CI snapshot reports successful x86 unit tests and multi-CN BVT.

Limitations:

  • Local frontend validation used an embedded cluster. The author reported a successful comparison of the changed BVT case, but its raw log was not supplied in local_validation.

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

mergify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

11 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Sun 29 Nov, 17:21 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 17:31 · a7e430b

Reason

Pull request #33446 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.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, 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
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/L Denotes a PR that changes [500,999] lines

Projects

None yet

3 participants