Repository navigation
Description
Bug summary
SELECT ... INTO OUTFILE loses precision when exporting an unscaled DOUBLE. Loading the generated CSV back into a DOUBLE column can therefore change the value and break an exact round trip.
This is reproducible on both:
main:7821d21c723372e45a8f65da3bbb896a157b10364.1-dev:7c060bd1292664acc0892525d2fd66581f893c97
Reproduction
drop table if exists t_rt_src;
drop table if exists t_rt_dst;
create table t_rt_src (
id bigint primary key,
f double,
d date,
s varchar(200)
);
insert into t_rt_src values
(1, 3.14159265358979, '2024-01-15', 'hello "world"'),
(2, null, null, null);
select * from t_rt_src into outfile '/tmp/rt_test.csv';
create table t_rt_dst like t_rt_src;
load data infile '/tmp/rt_test.csv'
into table t_rt_dst
fields terminated by ',' enclosed by '"'
lines terminated by '\n'
ignore 1 lines;
select s.id, s.f as src_f, d.f as dst_f, s.f = d.f as f_equal
from t_rt_src s join t_rt_dst d on s.id = d.id
order by s.id;The non-NULL row does not compare equal after the round trip. The original value is 3.14159265358979, while formatting it with float32 precision produces 3.1415927 (parsed as approximately 3.1415927410125732).
Expected behavior
An exported DOUBLE should retain sufficient precision to round-trip back to the same DOUBLE value.
Actual behavior
Only the all-NULL row remains an exact match. The MOTR regression therefore reports an exact-match count of 1 instead of 2:
Root cause
In pkg/frontend/export.go, the types.T_float64 default formatting path passes bitSize=32 to strconv.FormatFloat:
case types.T_float64:
val := vector.GetFixedAtNoTypeCheck[float64](vec, i)
if vec.GetType().Scale < 0 || vec.GetType().Width == 0 {
formatOutputString(ep,
[]byte(strconv.FormatFloat(float64(val), 'f', -1, 32)),
symbol[j], closeby, flag[j], buffer)
}Source:
matrixone/pkg/frontend/export.go
Lines 472 to 477 in 7821d21
| case types.T_float64: | |
| val := vector.GetFixedAtNoTypeCheck[float64](vec, i) | |
| if vec.GetType().Scale < 0 || vec.GetType().Width == 0 { | |
| formatOutputString(ep, []byte(strconv.FormatFloat(float64(val), 'f', -1, 32)), symbol[j], closeby, flag[j], buffer) | |
| } else { | |
| formatOutputString(ep, []byte(strconv.FormatFloat(float64(val), 'f', int(vec.GetType().Scale), 64)), symbol[j], closeby, flag[j], buffer) |
Suggested fix
Use bitSize=64 for types.T_float64 and add a regression that exports and reloads a high-precision DOUBLE, then verifies exact equality. The fix should also be backported to 4.1-dev.
Activity
daviszhen commentedon Jul 30, 2026
fixed
Ariznawlll commentedon Jul 30, 2026
测试版本
main(截至 2026-07-30 16:30,Asia/Shanghai)41332062a6740978f269088a92ee362a888c7bd7etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口127.0.0.1:6001原问题验证
执行
SELECT ... INTO OUTFILE后再 LOAD DATA 回同构表,以<=>逐行精确比较 DOUBLE、DATE、字符串与 NULL;5/5 行完全一致,完整黑盒 3/3 通过。Happy Path 覆盖
3.14159265358979与-1.2345678901234567精确回环。1.7976931348623157e308和最小 subnormal5e-324精确回环。Unhappy Path 覆盖
白盒验证
TestConstructByteFormatsUnscaledFloat64WithFullPrecision连续 3 轮通过。回归测试
修复提交
8694a8d26已扩展test/distributed/cases/load_data/load_data.sql。测试证据
完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与
-race输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b测试结论
测试通过。
Ariznawlll commentedon Jul 30, 2026
测试版本
main41332062a6740978f269088a92ee362a888c7bd72 CN + 1 TN + Proxy,经 Proxy 执行客户端 SQL原问题验证
使用
SELECT ... INTO OUTFILE导出同构表,再由LOAD DATA导回新表。以主键关联后分别对 DOUBLE、DATE、VARCHAR 使用<=>精确比较:5 行的比较结果为(总行数, DOUBLE 相等数, DATE 相等数, VARCHAR 相等数) = (5, 5, 5, 5)。Happy Path 覆盖
3.14159265358979、负值-1.2345678901234567、最大有限 DOUBLE1.7976931348623157e308以及最小 subnormal5e-324,导出/导入后均与源值精确相等。Unhappy Path 覆盖
LOAD DATA被拒绝;随后读取目标表,行数仍为 0,确认失败没有写入部分数据。白盒验证
不适用。本次新增的是客户端可见的导出/导入回环回归;源码中的 float64 格式化定向 UT 已在此前验证中覆盖。
回归测试
./motr --repeat 3 14_issue_regression.issue_25605_outfile_load_roundtrip -v,3/3 通过。./motr --suite 14_issue_regression -j 6 -v,125 通过、0 失败、2 个 opt-in 场景跳过。测试证据
测试结论
测试通过。