Skip to content

[Bug]: MIN MAX value error #3344

Closed
Closed

Description

@dengn

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Environment

- Version or commit-id (e.g. v0.1.0 or 8b23a93): 6dedae20180c9e7ad4159ef0c7ad0f8e8c358dee
- Hardware parameters: MAC M1 ARM 16GB
- OS type: OSX
- Others:

Actual Behavior

create table t1 (grp int, a bigint unsigned, c char(10) not null);
insert into t1 values (1,1,"a");
insert into t1 values (2,2,"b");
insert into t1 values (2,3,"c");
insert into t1 values (3,4,"E");
insert into t1 values (3,5,"C");
insert into t1 values (3,6,"D");
select sum(all a),count(all a),avg(all a),std(all a),variance(all a),bit_or(all a),bit_and(all a),min(all a),max(all a),min(all c),max(all c) from t1;

[SQL STATEMENT]: select sum(all a),count(all a),avg(all a),std(all a),variance(all a),bit_or(all a),bit_and(all a),min(all a),max(all a),min(all c),max(all c) from t1;
[EXPECT RESULT]:
sum(all a) count(all a) avg(all a) std(all a) variance(all a) bit_or(all a) bit_and(all a) min(all a) max(all a) min(all c) max(all c)
21 6 3.5000 1.707825127659933 2.9166666666666665 7 0 1 6 a E
[ACTUAL RESULT]:
sum(all a) count(all a) avg(all a) std(all a) variance(all a) bit_or(all a) bit_and(all a) min(all a) max(all a) min(all c) max(all c)
21 6 3.5 1.707825127659933 2.916666666666666 7 0 1 6 C c

Expected Behavior

No response

Steps to Reproduce

No response

Additional information

No response

Activity

  1. added
    kind/bug
    on Jun 24, 2022
  2. added this to the v0.5.0 milestone on Jun 24, 2022
  3. modified the milestones: v0.5.0, v0.6.0 on Jun 24, 2022
  4. fengttt commented on Jun 24, 2022

    @fengttt
    Contributor

    There are multiple problems -- precision of avg, std, etc, which should be considered OK.
    min/max has a collation problem, which we will punt to 0.6.

  5. added
    bvt
    on Jun 24, 2022
  6. dengn commented on Jun 30, 2022

    @dengn
    ContributorAuthor

    New collation support can be in 0.6, but we may just specify in documentation what's our collation and string comparison order.

  7. added
    severity/s0
    on Aug 10, 2022
  8. daviszhen commented on Sep 19, 2022

    @daviszhen
    Contributor

    it only can be fixed after the #3616 (p1) is done.

  9. removed
    severity/s0
    on Nov 4, 2022
  10. 49 remaining items

  11. added
    ai-easy
    ai-light
    and removed
    ai-easy
    on Aug 10, 2026
  12. assigned and unassigned on Aug 12, 2026
  13. slyunnn commented on Aug 24, 2026

    @slyunnn

    Regression and extended verification for #3344 (2026-08-24)

    Verification Environment

    • MatrixOne origin/main: a4465b3846c770b8f3e2c313a624afd8534427da — fix: restore IVFFlat storage Top-K (#27494).
    • Latest main was built locally as mo-service with embedded commit a4465b3846.
    • Related fix PR: fix: honor text collation in min and max #26627, merge commit 866517223d58e805884dad9a095a76d540a1d03f — fix: honor text collation in min and max (#26627).
    • Topology: Log service + TN + CN1 + CN2 + Proxy.
    • Endpoints: CN1 127.0.0.1:16001, CN2 127.0.0.1:16002, Proxy 127.0.0.1:6009.
    • Client protocol: MOTR and mysql CLI through the MySQL text protocol.

    What Was Covered

    • OK — Original scenario: mixed-case CHAR(10) values return MIN='a' and MAX='E' under the default text collation.
    • OK — Happy path: VARCHAR(10) returns the same text-collation-aware MIN and MAX values as CHAR(10).
    • OK — Numeric aggregate control: SUM, COUNT, AVG, STD, VARIANCE, BIT_OR, BIT_AND, numeric MIN, and numeric MAX retain the expected results.
    • OK — Compatibility control: utf8mb4_bin deliberately follows byte order and returns MIN='C', MAX='c'.
    • OK — Boundary/null path: mixed NULL and text values ignore NULL; all-NULL input returns NULL for both MIN and MAX.
    • OK — Recorded/replayed through Proxy, CN1 direct, and CN2 direct endpoints.
    • Not covered — Non-default non-binary locale-specific collations; this regression focuses on the default text and explicit binary collation distinction reported by the issue.

    Findings

    The historical collation bug is fixed. Text MIN/MAX no longer use physical byte order for default text columns, while explicit utf8mb4_bin retains binary ordering by design.

    Large-data regression is not required: the defect is a scalar comparison/collation contract and does not depend on row count, block/batch boundaries, memory/spill, concurrency, skew, network transfer, or resource scale.

    MOTR / BVT Coverage

    • Added suites/14_issue_regression/t/issue_3344_min_max_collation.test.
    • Added suites/14_issue_regression/r/issue_3344_min_max_collation.result.
    • Proxy record and replay passed: 14/14.
    • CN1 direct replay passed: 14/14.
    • CN2 direct replay passed: 14/14.
    • MOTR branch: test/issue-3344-min-max-collation.
    • MOTR commit: ba04940 — test: add MOTR regression for #3344.
    • Independent branch push is pending because the repository connection did not complete; no issue-specific PR was created.

    Final Conclusion

    Fixed. Default text-collation MIN/MAX now produce semantically ordered results, explicit binary collation keeps byte ordering, and NULL behavior remains correct. Large-data regression is not needed because data volume does not affect this comparison contract.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-lightbvtkind/bugphase/testingpriority/p0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions