Skip to content

add UUID functions - #24807

Merged
mergify[bot] merged 13 commits into
matrixorigin:mainfrom
daviszhen:0603-add-uuid
Jun 10, 2026
Merged

add UUID functions#24807
mergify[bot] merged 13 commits into
matrixorigin:mainfrom
daviszhen:0603-add-uuid

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

What this PR does / why we need it:

增加uuid函数: is_uuid, uuid_short, uuid_to_bin, bin_to_uuid

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

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

I reviewed this from correctness / behavior-compatibility / coverage angles, and there is one blocking issue:

  • uuid_short() is currently implemented as xxhash.Sum64(uuid.NewV7()). That is not MySQL-compatible. MySQL documents UUID_SHORT() as a 64-bit value built from (server_id << 56) + (startup_time << 24) + incrementing_counter, specifically to preserve uniqueness under documented conditions and to produce increasing values. Hashing a 128-bit UUID down to 64 bits removes both of those properties: collisions become possible by construction, and call order is no longer monotonic.

The official MySQL docs for UUID_SHORT() are explicit about this contract, and the current implementation does not match it. I think this needs either:

  1. a real UUID_SHORT() implementation with server/startup/counter semantics, or
  2. a different function name if the intention is to expose a hashed UUID-derived helper rather than MySQL-compatible behavior.

The current tests also only check uuid_short() is not null / > 0, so they would not catch the semantic mismatch above.

@daviszhen

Copy link
Copy Markdown
Contributor Author

I reviewed this from correctness / behavior-compatibility / coverage angles, and there is one blocking issue:

  • uuid_short() is currently implemented as xxhash.Sum64(uuid.NewV7()). That is not MySQL-compatible. MySQL documents UUID_SHORT() as a 64-bit value built from (server_id << 56) + (startup_time << 24) + incrementing_counter, specifically to preserve uniqueness under documented conditions and to produce increasing values. Hashing a 128-bit UUID down to 64 bits removes both of those properties: collisions become possible by construction, and call order is no longer monotonic.

The official MySQL docs for UUID_SHORT() are explicit about this contract, and the current implementation does not match it. I think this needs either:

  1. a real UUID_SHORT() implementation with server/startup/counter semantics, or
  2. a different function name if the intention is to expose a hashed UUID-derived helper rather than MySQL-compatible behavior.

The current tests also only check uuid_short() is not null / > 0, so they would not catch the semantic mismatch above.

删除了uuid_short. 一是不在issue需求. 二是 mysql的实现方案 在 mo 多cn中不好做.

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

I found one substantive MySQL-compatibility issue in the new swap_flag support for UUID_TO_BIN() / BIN_TO_UUID().

This PR explicitly broadens the accepted swap_flag types to include strings (uuidSwapFlagTypeSupported() accepts MySQL string types), but the string branch in makeBoolParamGetter() uses strconv.ParseFloat on the entire string. That is stricter than MySQL’s coercion rules: values like 1abc / 2xyz are truthy in MySQL because boolean evaluation consumes the leading numeric prefix, but this implementation treats any parse failure as false and returns the unswapped result.\n\nSo right now the function signature says string swap flags are supported, but some supported string inputs do not behave like MySQL. I also do not see coverage for this path in the added SQL or unit tests — current tests cover clean numeric values like 0.4, -0.4, 0.0, but not prefix-numeric strings. I think this should either use MySQL-compatible string-to-number coercion for the boolean evaluation, or reject non-numeric strings explicitly instead of silently treating them as 0.

@daviszhen

Copy link
Copy Markdown
Contributor Author

I found one substantive MySQL-compatibility issue in the new swap_flag support for UUID_TO_BIN() / BIN_TO_UUID().

This PR explicitly broadens the accepted swap_flag types to include strings (uuidSwapFlagTypeSupported() accepts MySQL string types), but the string branch in makeBoolParamGetter() uses strconv.ParseFloat on the entire string. That is stricter than MySQL’s coercion rules: values like 1abc / 2xyz are truthy in MySQL because boolean evaluation consumes the leading numeric prefix, but this implementation treats any parse failure as false and returns the unswapped result.\n\nSo right now the function signature says string swap flags are supported, but some supported string inputs do not behave like MySQL. I also do not see coverage for this path in the added SQL or unit tests — current tests cover clean numeric values like 0.4, -0.4, 0.0, but not prefix-numeric strings. I think this should either use MySQL-compatible string-to-number coercion for the boolean evaluation, or reject non-numeric strings explicitly instead of silently treating them as 0.

mo不支持前缀数字字符串 转成 数字. 现在改为报错.

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

I re-checked the latest update and this looks good to me now.

The key point I cared about before was the swap_flag string path. This version makes the behavior explicit and internally consistent: if a string swap flag cannot be parsed as a numeric value, it now errors instead of being silently treated as false. That is stricter than MySQLs loose numeric-prefix coercion, but as an intentional MO behavior it is coherent, well-covered by the new unit and SQL tests, and much better than the previous silent fallback.

@mergify

mergify Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-06-10 08:54 UTC · Rule: main
  • Checks skipped · PR is already up-to-date
  • Merged2026-06-10 08:55 UTC · at fe091eb456c114b39511416c691bfc283bfd3471 · squash

This pull request spent 42 seconds in the queue, including 7 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • 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 Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • 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 Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

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

Labels

kind/enhancement kind/feature size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants