Skip to content

fix(window): support temporal interval frame parameters and string parsing - #30310

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/1d3b3fb7cab8e5b28fffa6717aefe08b16ded4738067ab21c3e6b5bab351bc49
Oct 16, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
iamlinjunhong:codex/loom/develop/1d3b3fb7cab8e5b28fffa6717aefe08b16ded4738067ab21c3e6b5bab351bc49

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 15, 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:

Please keep both issues open after merge for verification by the reporter.

What this PR does / why we need it:

Temporal RANGE frames currently reject INTERVAL ? SECOND during PREPARE. Window interval strings also diverge from MySQL: full compound SECOND-ending values with an extra fractional field produce a duration, and a nonnumeric simple-unit string becomes a MaxInt64 sentinel that fails during execution.

Keep each prepared interval's source type and original unit in the reusable plan, then normalize fresh frame values for each execution. Boolean parameters use numeric 0/1 offsets through both SQL EXECUTE and binary prepared execution, matching Boolean literals and integer parameters. Numeric SECOND parameters support fractional microseconds; negative, NULL, non-finite and overflowing values fail before input is consumed, including empty inputs and literal, outer-query, CTE and parameterized LIMIT 0 shortcuts. Window-specific string normalization treats excess compound fields as NULL arithmetic and a missing numeric prefix in a simple-unit string as zero. NULL interval arithmetic produces empty frames for non-NULL keys while preserving NULL-key peers. The ordinary, timestamp civil-time and sliding aggregate paths handle these frames consistently. SUM/AVG retain sliding peer state across empty intervals, output chunks and partition transitions, avoiding repeated aggregation of NULL-key peers.

Validation on Go 1.27.1, macOS arm64:

  • Reproduced both issues through the SQL frontend before the fix; literal decimal/integer-compound controls passed.
  • Owning package tests: pkg/container/types, pkg/sql/plan, pkg/sql/colexec/window, and pkg/sql/compile (all four rerun after rebasing this follow-up onto official main).
  • TestWindowTemporalIntervals through the existing embedded one-CN fixture: SQL and binary prepared reuse, decimal128/microsecond boundaries, invalid values and recovery, empty input, LIMIT 0 admission, date/time/datetime/timestamp results, and NULL-key COUNT/SUM/AVG peers; the complete updated fixture passed in 5.99 seconds after rebasing onto official main.
  • Focused window/compile tests with -race -tags matrixone_test -short -count=1, including cancellation, cleanup and reuse.
  • Retained upstream frame-order diagnostics after rebase: negative interval values use a valid temporal ordering domain; numeric ordering and ROWS-domain rejection are checked separately.
  • Boolean-parameter follow-up: typed SECOND/DAY materialization tests distinguish false from SQL NULL and preserve the source plan; SQL/binary prepared reuse, recovery after invalid inputs and LIMIT 0 admission passed. The complete window package passed, and incremental vet/lint for window and SQL integration reported no issues.
  • Incremental go vet, golangci-lint (zero issues), formatting and diff checks.
  • window_interval_parameters.sql passed normal mo-tester comparison twice on the same embedded one-CN instance (36/36 statements each, none skipped), including Boolean literal and prepared offsets. The test database was absent after each round; the SQL/binary integration fixture and these BVT runs completed together in 6.40 seconds.
  • window_frame_order.sql passed normal mo-tester result comparison twice on the same embedded one-CN instance (9/9 statements each, none skipped), using CI runner revision 309a0ca650e0c55e90292767fd61e4976818d66d. The negative-interval oracle now uses temporal ordering; positive and negative interval bounds on numeric ordering retain separate exact domain-error assertions. Other distributed coverage remains subject to CI.
  • BenchmarkNullIntervalRangePeers: one warm-up followed by three measured rounds (-benchtime=10x -count=3), with every sum checked. At 1,024/4,096 NULL-key rows, NULL-bound medians changed from 12.837/212.678 ms before this follow-up to 0.0403/0.1527 ms after it. Scaling for four times as many rows improved from 16.57x to 3.79x; the updated zero-bound control took 0.1471 ms at 4,096 rows. These isolate aggregate work from sorting and are diagnostic samples rather than production throughput estimates. The final benchmark additionally checks output length/NULL status and releases state immediately on assertion failure.

Execution admission validates finite bounds before source initialization; Window.Prepare creates execution-owned runtime frames. Work is bounded by reachable plan size and scalar text length, without per-row parsing. General NormalizeInterval and DATE_ADD behavior are unchanged. Nested parameter expressions such as INTERVAL (? + 1) SECOND remain unsupported; existing numeric literal rounding beyond six fractional digits is outside this change, while new dynamic SECOND bounds truncate to microseconds.

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

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Oct 15, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: f55f486031e8ceaaace9be6b20cbdcf44d17c3ea

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

Assessment: request_changes

Reviewed the complete 13-file delta and affected callers. Preserving source types and normalizing execution-owned frames is reasonable, but two confirmed gaps remain: LIMIT 0 bypasses parameter validation, and NULL interval bounds cause quadratic aggregation over NULL-key peers.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/sql/colexec/window/window.go:163: Prepare SELECT SUM(v) OVER(ORDER BY at RANGE INTERVAL ? SECOND PRECEDING) FROM d LIMIT 0, then execute with -1, NULL, or 9223372036854.775808.
    Impact: Both SQL EXECUTE and binary prepared execution succeed instead of rejecting these invalid bounds, violating the stated validation contract for empty inputs. Ensure validation occurs before the LIMIT 0 shortcut can omit the window operator.
    Evidence: Validation runs only during Window.Prepare, but compile.go:1956 returns an empty scope without constructing that operator. TestReviewWindowLimitZeroValidation reproduced all six invalid executions returning success; literal-negative and valid-recovery controls passed. Constant-false-filter controls also rejected invalid parameters correctly. See limit-zero.log and checks/1792089047532003971-2.json, exit 1.

  • P2 pkg/sql/colexec/window/window.go:850: Evaluate SUM or AVG over a temporal RANGE frame with a NULL-producing interval such as '00:01.5' MINUTE_SECOND and a large NULL ORDER BY peer group.
    Impact: Disabling sliding aggregation globally makes the generic evaluator aggregate the entire NULL peer group separately for every output row, producing quadratic work. Preserve peer-result reuse while retaining empty frames for non-NULL keys.
    Evidence: At 4,096 NULL-key rows, focused operator medians were 295.66 ms on HEAD versus 0.167 ms with the frozen-base window evaluator; HEAD's zero-bound control took 0.179 ms. Increasing rows from 1,024 to 4,096 increased NULL-bound time from 17.75 ms to 295.66 ms. Public SQL confirmed 288.06 ms versus 5.70 ms for the equivalent zero-bound control, with every sum checked. See bench-head.log, bench-base.log and public-boundaries.log; receipts 1792088803529159625-2, 1792088818148506306-2 and 1792088929628102712-2.

Validation:

  • Artifacts are retained under /home/xupeng/.local/state/mo-bot/jobs/0945a8b21491518418b4b0a6/attempt-1. review-evidence-audit.json reconciles 11 command/source/exit receipts with logs and overlay hashes; audit receipt checks/1792089171450663858-2.json exited 0.

  • Full types, window and plan package suites passed: 4,149 passing test roots and two existing skipped subtests. All changed test roots executed. Receipt checks/1792088818593084402-2.json; packages.jsonl.

  • TestWindowTemporalIntervals passed all subtests through the SQL frontend, including prepared reuse, precision boundaries, empty-table validation and NULL peers. Additional prepared compound-reuse and DATE_ADD controls passed.

  • Constant string-expression failures also occurred with the base binder and were excluded from findings.

  • Isolation preflight passed; native recovery verified 192 current inputs, 62 artifacts and successful build-owner receipts. Exact HEAD, complete patch, clean source, formatting and whitespace checks passed.

  • Frozen CI reports 13 successful, 15 skipped and two neutral checks. No CI was rerun.

Limitations:

  • Benchmark comparison replaces only window.go with its frozen-base version; it is not a full-base build. Measurements are focused diagnostic samples, not production throughput estimates.

  • Linked issue bodies and raw author-validation artifacts were not supplied.

  • No local mo-tester comparison or fresh distributed/race suite was run. Public SQL tests exercised the existing one-CN fixture.

@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 35b8fce0d89f9015fa103b1d6ea849619bf49ab5

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: 35b8fce0d89f9015fa103b1d6ea849619bf49ab5

Assessment: approve

Reviewed the complete 18-file delta and affected callers. Shared normalization, execution-owned frames and pre-source validation form a coherent design. Boolean parameters now preserve numeric 0/1 semantics, and the previous LIMIT 0 and quadratic NULL-peer concerns are closed. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • TestWindowTemporalIntervals passed through the real frontend, covering SQL/binary prepared reuse, Boolean values, invalid-input recovery, empty inputs, LIMIT 0 variants and NULL peers. frontend.log and receipt 1792113754706061459-38.json record exit 0.

  • TestWindowIntervalBooleanMaterialization passed all six SECOND/DAY cases, distinguishing TRUE, FALSE and SQL NULL while preserving the source plan. boolean-unit.log and receipt 1792113778182932970-3.json record exit 0.

  • Independently reconciled retained receipts, logs, overlays and relevant source inputs for ten focused test roots, additional source-domain/admission probes and NULL-peer benchmarks. The historical Boolean failures were treated as failed-before controls.

  • Unchanged aggregation benchmarks measured NULL-peer medians of 0.0529 ms at 1,024 rows and 0.2135 ms at 4,096 rows; the 4,096-row zero-bound control measured 0.1797 ms. Admission adds bounded plan traversal and scalar normalization, without per-row parsing.

  • Isolation preflight passed. Native recovery verified 192 current inputs and 62 artifacts before completing the repository build owner. The initial missing-library setup failure ran no product tests.

  • review-evidence-audit.json under /home/xupeng/.local/state/mo-bot/jobs/10052ac1a6518cbf25e7d3bb/attempt-1 reconciles execution evidence and source hashes; audit receipt 1792113863319530898-4.json passed. Source remains unchanged. Supplied exact-head CI reports successful build, unit, static-analysis and multi-CN BVT checks.

Limitations:

  • Linked issue bodies and raw author/CI execution artifacts were not supplied; local_validation was empty.

  • Broad package, race and distributed coverage relies on supplied CI summaries and applicable retained evidence. No fresh mo-tester run or end-to-end SQL performance benchmark was performed; aggregation measurements are diagnostic samples.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 01:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-16 03:25 UTC · at b24d1b311555e0b6f3d56eb37f9a2e9617e9a5b7 · squash

This pull request spent 1 hour 59 minutes 54 seconds in the queue, including 1 hour 3 minutes 42 seconds running CI.

Required conditions to merge

This branch was previously deployed

1 inactive deployment
ci — 2d3b11da Deployed Oct 16, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants