Repository navigation
fix: honor text collation in min and max - #26627
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? |
gouhongshen
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 2 hours 15 minutes 58 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull 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.
Failing checks: HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #3344
What this PR does / why we need it:
fix: honor text collation in min and max