matrixorigin / matrixorigin/matrixone

[Compatibility]: UUID_TO_BIN and BIN_TO_UUID swap flags handle NULL and nonnumeric strings differently from MySQL

Open
#28,251 1 comment 0 reactions 1 assignee Claimed by @XuPeng-SH View on GitHub
area/compatibility kind/bug needs-triage
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

### 问题描述

`UUID_TO_BIN(uuid, swap_flag)` 和 `BIN_TO_UUID(binary, swap_flag)` 的 swap flag 强制转换与 MySQL 不兼容。MySQL 把 NULL 和不能解析为数字的字符串按 0 处理,执行非 swap 路径;MatrixOne 对 NULL 直接返回 NULL,对非数字字符串报布尔转换错误。

这使应用中来自 nullable 列或字符串参数的 flag 在两端得到不同结果。函数的 UUID 编解码与 swap 字节布局本身是正确的,问题限定在第二参数转换。

### 环境

- MatrixOne latest `main`, commit `e7bb0572235ec4bac81eb098eb0ad8900f0065ab`
- MySQL 8.3.0(对照)

### 复现

```sql
set @u = '6ccd780c-baba-1026-9564-5b8c656024db';

select hex(uuid_to_bin(@u, null));
select hex(uuid_to_bin(@u, 'abc'));

select bin_to_uuid(uuid_to_bin(@u), null);
select bin_to_uuid(uuid_to_bin(@u), 'abc');
```

### MatrixOne 行为

- 两个 NULL flag 调用均返回 NULL。
- 两个 `'abc'` flag 调用均返回:

```text
ERROR 20301: invalid input: 'abc' cannot be converted into boolean value
```

### MySQL 8.3.0 行为

四个调用都按 `swap_flag=0` 执行:

```text
hex(uuid_to_bin(@u, null)) -> 6CCD780CBABA102695645B8C656024DB
hex(uuid_to_bin(@u, 'abc')) -> 6CCD780CBABA102695645B8C656024DB

bin_to_uuid(..., null) -> 6ccd780c-baba-1026-9564-5b8c656024db
bin_to_uuid(..., 'abc') -> 6ccd780c-baba-1026-9564-5b8c656024db
```

### 已确认边界

- flag 0 使用原始字节顺序,任意非零整数(含 -1、2)启用 swap,两端一致。
- 浮点和数字字符串也按零/非零转换:0 为 false,0.4/1.2 为 true,两端一致。
- UUID canonical/no-dash/braced 形式、大小写、非法输入错误、16 字节长度校验、prepared statement、生成列索引均一致。

### 期望行为

第二参数应按 MySQL 数值/布尔强制转换规则处理。特别是 NULL 与非数字字符串都应产生 false/0 flag,而不是传播 NULL 或抛出严格布尔转换错误。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.