Skip to content

fix sub-second units - #27017

Merged
XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
daviszhen:0812-fix-sub-second
Aug 14, 2026
Merged

XuPeng-SH merged 22 commits into
matrixorigin:mainfrom
daviszhen:0812-fix-sub-second

Conversation

@daviszhen

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 #26983

What this PR does / why we need it:

此分支主要支持 Time Window 的 MICROSECOND 亚秒窗口。

修改内容:

  • Time Window 执行器支持 MICROSECOND 单位。
  • interval() helper 支持微秒换算。
  • mo_win_divisor() 改为按微秒计算 sliding 对齐粒度。
  • sliding window 的内部 truncate helper 改为使用 MICROSECOND 单位。
  • mo_win_truncate 保留 timestamp(6) / datetime(6) 的 scale,避免分桶时丢失小数秒。
  • 新增 UT 覆盖微秒换算、truncate、sliding 边界和聚合结果。
  • 新增 BVT 覆盖:
    • INTERVAL(..., MICROSECOND)
    • SLIDING(..., MICROSECOND)
    • GAPFILL(PARTITION) + FILL(VALUE, ...)
    • TIMESTAMP(6) / DATETIME(6) 微秒边界。

@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 re-review completed on exact head 90a79c3. The prior scale-0 metadata and low-scale microsecond-collapse blockers are closed end to end: MICROSECOND windows promote boundary FSP to 6, planner/TIME_WINDOW/FILL projections agree, runtime boundary vectors preserve the timestamp/datetime type and scale, and public scale-0/3/6 plus CTAS coverage verifies one-microsecond width and materialized DATETIME(6). Focused planner, timewin, and function tests pass with the required CGO/thirdparties setup; current CI is green and git diff --check is clean. The unrelated comprimary_key.result refresh remains a non-blocking cleanup item.

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

Reviewed exact head 90a79c3. The microsecond interval conversion, timestamp boundary representation, FSP promotion, zero and NULL handling, and planner to runtime metadata agree. Focused interval, truncate, time-window executor, planner, CTAS, and function tests pass.

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

Reviewed exact head 90a79c3d8ae3bd4d77bde8989369cec1fe65c76a.

The previous blocking issue is closed: microsecond windows now promote public boundaries to fractional scale 6 for DATETIME/TIMESTAMP inputs at source scales 0/3/6, the runtime boundary vectors preserve the temporal OID and FSP, and CTAS keeps the resulting metadata. I also checked the DATE/TIMESTAMP execution path, interval validation, zero sentinels, sliding/partition behavior, and buffer reuse.

Local verification passed:

  • GOWORK=off go list/build/vet for ./pkg/sql/colexec/timewin, ./pkg/sql/plan/function, ./pkg/sql/plan
  • focused microsecond/scale/runtime/CTAS regression tests
  • full tests for all three affected packages via mo-cgo-test

The unrelated comprimary_key.result refresh should still be removed to keep the PR focused, but I do not see it masking a correctness regression, so it is non-blocking.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are two merge-blocking issues:

  1. [P1] Preserve the reused boundary vector when appending fails (pkg/sql/colexec/timewin/timewin.go:751, :813-814, and the analogous end-vector path). calRes assigns the helper return directly to ctr.startVec/ctr.endVec, while makeWindowBoundaryVec returns (nil, err). On a later flush, a reused vector still owns its existing mpool buffer after CleanOnlyData; if growth fails, the assignment overwrites the only owner with nil and the buffer can no longer be freed by Reset/Free. Please retain/return the vector on error (or keep ownership in the caller) and add a failing-allocation regression.

  2. [P1] Revert the unrelated test/distributed/cases/ddl/comprimary_key.result rewrite. The corresponding SQL is unchanged, but this patch changes the output protocol and even turns negative key values into positive ones (for example around lines 21-35). This will make that independent BVT golden disagree with its real results and is outside the time-window change.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Updated in e8447cf.

Changes made for the latest review:

  1. pkg/sql/colexec/timewin/timewin.go

    • makeWindowBoundaryVec now returns the reused boundary vector together with the append error instead of returning (nil, err).
    • This keeps ownership in ctr.startVec / ctr.endVec when calRes assigns the helper return, so Reset / Free can still release the existing mpool buffer after a failed append.
  2. pkg/sql/colexec/timewin/timewin_test.go

    • Added TestMakeWindowBoundaryVecAppendFailurePreservesOwnership.
    • The test covers both DATETIME and TIMESTAMP boundary vectors with an allocation-account capacity failure, and asserts that the failed append returns the same vector owner and leaves no mpool/account leak.
  3. test/distributed/cases/ddl/comprimary_key.result

    • Reverted the unrelated golden rewrite. It now has no diff against upstream/main.

Validation run locally:

  • go test ./pkg/sql/colexec/timewin -run 'TestMakeWindowBoundaryVecAppendFailurePreservesOwnership|TestTimeWinReplacementFailurePreservesOwnership' -count=1
  • go test ./pkg/sql/colexec/timewin -count=1
  • git diff --check
  • Confirmed git diff upstream/main -- test/distributed/cases/ddl/comprimary_key.result is empty.

Please review again. Thanks.

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

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.

6 participants