Skip to content

fix: canonicalize CHAR window keys - #28106

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:m-28023
Sep 4, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
iamlinjunhong:m-28023

Conversation

@iamlinjunhong

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

What this PR does / why we need it:

fix: canonicalize CHAR window keys

@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/M Denotes a PR that changes [100,499] lines label Sep 4, 2026

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

Reviewed exact head e3a940f.

The window-only CHAR key canonicalization preserves projected values while aligning PARTITION BY, peer ranking, and RANGE ordering with PAD SPACE semantics. The comparison cast remains covered by the mixed-version MORPC gate, and the optimizer total-cast extension is non-shrinking and charset-preserving.

Validation: git diff --check; go test ./pkg/sql/plan -count=1; focused comparison-cast tests in ./pkg/sql/plan/function; go vet ./pkg/sql/plan; clean merge-tree against current main.

@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

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

Blocking: please remove the unrelated singleRowCastIsTotal expansion at pkg/sql/plan/opt_misc.go:1846-1852, or split it into a separately justified and tested change.

This PR's contract is window-key canonicalization, but this hunk independently broadens primary-key GROUP BY aggregate elimination for every non-shrinking CHAR/VARCHAR/TEXT cast. singleRowCastIsTotal is a safety proof used when replacing a blocking Aggregate with a streaming Project, so a new true domain needs its own positive and nearest-negative coverage (source/target OID, width boundary, charset mismatch, unbounded width, and TINYTEXT byte-width behavior). The new return true at line 1852 is not executed even by the full ./pkg/sql/plan suite.

The hunk is also not needed for this fix: I temporarily removed only these eight lines and both the exact window regression and the complete owning-package suite still passed. Keeping an unneeded optimizer semantic expansion in a correctness fix makes its risk and regression contract invisible.

The window-specific part otherwise held under counterexamples for direct/derived/CTE/named-window/explicit-CHAR keys, preserved width/charset/nullability, and left a plain VARCHAR control unwrapped. Existing exact-head CI is green.

Validation performed: git diff --check; focused changed tests; full ./pkg/sql/plan; line coverage inspection; temporary counterexample tests (all through the repository CGo wrapper). The review worktree was restored clean afterward.

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

Verified the direct CHAR counterexample against the issue contract. The window-only PAD SPACE key cast preserves ordinary predicate binding, covers partition, rank, and RANGE peers, and the public control matches GROUP BY and explicit VARCHAR behavior. CI is complete and green.

@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 536e4f7b2ff60487c0d0e8656b284d1a6ef1ca03 after the prior changes request. The new commit removes the unrelated singleRowCastIsTotal optimizer expansion in full; the window-only CHAR PAD SPACE canonicalization is otherwise unchanged. Direct and promoted CHAR keys are covered across PARTITION BY, ranking peers, and RANGE frames, with GROUP BY and explicit VARCHAR controls. The cast is scoped to window keys, preserves the projected value path, and adds only constant planner work per key. Exact-head CI is complete and green.

@mergify mergify Bot added the queued label Sep 4, 2026
@mergify

mergify Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-04 08:05 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-04 08:05 UTC · at 414e0433862214c9eb5a10cf7df6d6197c027741 · squash

This pull request spent 13 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 414e043 into matrixorigin:main Sep 4, 2026
27 of 28 checks passed
@mergify mergify Bot removed the queued label Sep 4, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026

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

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants