Skip to content

fix: honor text collation in min and max - #26627

Merged
XuPeng-SH merged 29 commits into
matrixorigin:mainfrom
iamlinjunhong:m-3344
Aug 10, 2026
Merged

XuPeng-SH merged 29 commits into
matrixorigin:mainfrom
iamlinjunhong:m-3344

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

What this PR does / why we need it:

fix: honor text collation in min and max

@iamlinjunhong
iamlinjunhong requested a review from a user August 3, 2026 07:43
@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 Aug 3, 2026

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

Codex automated review

No existing review, issue comment, or inline thread raised these defects. The implementation still produces incorrect collation results and loses or misrepresents binary text collation metadata.

P1 - Use utf8mb4_general_ci weights instead of UCA Loose (pkg/sql/colexec/aggexec/minmax2.go:483)

language.Und with collate.Loose implements UCA/CLDR equivalence, not MySQL's legacy utf8mb4_general_ci. For example, x/text treats ß and ss as equal, while MySQL documents that general_ci maps ß to one s and does not support expansions. Consequently, MAX over values inserted as ('ß'), ('ss') retains ß, whereas general_ci must return ss. The new tests cover case/accent/width only and miss this class of incorrect weights.

P1 - Do not advertise utf8mb4_bin VARCHAR columns as binary data (pkg/frontend/util.go:1603)

A VARCHAR COLLATE utf8mb4_bin now has typ.Charset == CharsetBinary, causing its result metadata to use collation ID 63. This field is a protocol collation ID; the repository's own table maps 46 to utf8mb4_bin and 63 to the distinct binary character set. MySQL also explicitly distinguishes nonbinary _bin text from binary strings. Clients can therefore expose ordinary UTF-8 VARCHAR results as raw binary or skip character conversion. Preserve the UTF-8 collation identity; reserve ID 63 for actual binary types.

P2 - Resolve table charset and collation independently of option order (pkg/sql/plan/build_ddl.go:1271)

The loop lets whichever table option appears last overwrite tableCharset. Thus CREATE TABLE t(v VARCHAR(10)) COLLATE utf8mb4_bin CHARACTER SET utf8mb4 ends with CharsetUTF8, even though both clauses specify the compatible utf8mb4_bin collation. MIN(v) then uses the case-insensitive comparator rather than binary ordering. Table options are parsed as an unordered list, and the contract when both are present is to use the explicit charset and explicit collation, not discard one according to textual order.

P1 - Persist the table collation for columns added later (pkg/sql/plan/build_ddl.go:1267)

tableCharset exists only while planning the initial CREATE and is copied only into columns present then; no table-level default is persisted. ALTER TABLE t ADD COLUMN v VARCHAR(10) consequently creates a general-ci column even when t was created with COLLATE utf8mb4_bin. The changed aggregate will silently use different ordering for initial and subsequently added columns in the same table. Column collation rules require a column without explicit clauses to inherit the table default.

@mergify

mergify Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-10 08:17 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-10 10:33 UTC · at 322c964ca741913f46bd885fe3dcfca55cece79f

This pull request spent 2 hours 15 minutes 58 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
  • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • check-success = Matrixone CI / UT Test on Ubuntu/x86
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • 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

Reason

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

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants