Repository navigation
fix(sql): bind YEAR keys for numeric RANGE window frames - #33446
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
1a0a353 to
ee4f19a
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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 asBETWEEN UNBOUNDED PRECEDING AND ? PRECEDINGwith 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.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
🚫 Left the queue · pull request dequeued11 min in the queue, with no time running CI. So far
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.
To get back in the queue
Merge conditions not met when it left the queue
Tick the box to put this pull request back in the merge queue (same as
2 merge conditions met
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
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
-0.1with error 20301 on an ending PRECEDING bound, then returned[NULL, 10]for0.75and[NULL, NULL]for1.25.mo-cgo-test. The signed RANGE BVT compared 35 of 35 statements successfully withmo-tester -n -gon the final native binary.6540533196.make static-check-selected STATIC_CHECK_PACKAGES="<selector output>"exited 0 with zero findings in default mode and withGOFLAGS=-tags=integration.