matrixorigin / matrixorigin/matrixone

[Bug]: UNION with DATE discards DATETIME fractional-second precision

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

Description

## 问题

`UNION`/`UNION ALL` 合并 `DATETIME(6)` 与 `DATE` 时,MatrixOne 丢失 DATETIME 分支的微秒,并将大于等于半秒的值舍入到下一秒。CTAS 会将已经改变的值落盘,同时元数据出现 `COLUMN_TYPE=DATETIME(6)` 与 `DATETIME_PRECISION=0` 相互矛盾的状态。

## 环境

- MatrixOne: official `main`
- commit: `e7bb0572235ec4bac81eb098eb0ad8900f0065ab`
- comparison: MySQL 8.3

## 复现

```sql
create database union_temporal_fsp_repro;
use union_temporal_fsp_repro;

create table t(
id int primary key,
d date,
dt datetime(6)
);
insert into t values
(1,'2024-01-01','2024-01-01 01:02:03.123456'),
(2,'2024-01-02','2024-01-02 02:03:04.654321');

select v,microsecond(v) from (
select dt as v from t where id=2
union all
select d from t where id=1
) q order by v;

create table copied as
select dt as v from t where id=2
union all
select d from t where id=1;

select column_type,datetime_precision
from information_schema.columns
where table_schema='union_temporal_fsp_repro'
and table_name='copied'
and column_name='v';
```

MatrixOne 返回:

```text
2024-01-01 00:00:00 | 0
2024-01-02 02:03:05 | 0

COLUMN_TYPE = DATETIME(6)
DATETIME_PRECISION = 0
```

作为边界对照,`DATETIME(6)` 与显式 `CAST(NULL AS DATETIME)` 的 UNION 会保留 `654321` 微秒,说明问题发生在 DATE/DATETIME 公共类型合流。

MySQL 8.3 保留:

```text
2024-01-02 02:03:04.654321 | 654321
```

CTAS 元数据为 `DATETIME(6)` / precision 6。

## 期望

集合运算的公共时间类型采用参与分支中的最大 FSP,保留 DATETIME(6) 的微秒值;CTAS 的 column type 与 `DATETIME_PRECISION` 保持一致。

该场景重复执行 3 次,结果稳定。

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.