Skip to content

[Bug]: saved DATA BRANCH DIFF corrupts text and binary values returned by RESULT_SCAN #31535

Closed

Description

@Ariznawlll

Description

Saving a DATA BRANCH DIFF result silently changes VARCHAR and VARBINARY values into textual byte arrays. The diff displayed to the client is correct, but reading the saved result through RESULT_SCAN returns different values. An INSERT ... SELECT from that saved result succeeds and persists the wrong data.

Environment

  • MatrixOne main: f847803802289b2b2d0df4f0a2f842c2804b823a (git_version() = f847803802)
  • Isolated local standalone, one CN, macOS arm64

Reproduction

CREATE DATABASE branch_saved_repro;
USE branch_saved_repro;
CREATE TABLE b (id INT PRIMARY KEY, v VARCHAR(40), bin VARBINARY(16));
INSERT INTO b VALUES (1, 'old', X'00FF');
DATA BRANCH CREATE TABLE child FROM b;
UPDATE child SET v = '中文', bin = X'FF000A' WHERE id = 1;

SET save_query_result = ON;
DATA BRANCH DIFF child AGAINST b;
-- Direct result has v = '中文', bin = X'FF000A'
SET @qid = last_query_id();
SELECT * FROM result_scan(@qid) AS r;
-- Actual v = '[228 184 173 230 150 135]', bin = '[255 0 10]'

CREATE TABLE copied (id INT PRIMARY KEY, v VARCHAR(40), bin VARBINARY(40));
INSERT INTO copied SELECT id, v, bin FROM result_scan(@qid) AS r;
SELECT id, v, HEX(bin) FROM copied;
-- Actual: 1, '[228 184 173 230 150 135]', '5B32353520302031305D'
-- Expected: 1, '中文', 'FF000A'

Expected

The saved result must contain the same values and types as the diff returned to the client. Reading and inserting that result must preserve the text and binary bytes.

Validation

  • Reproduced in 3/3 fresh databases qbranchreadback_06, _07, _08, and independently with a SQL session variable in _09.
  • A second row with NULL values remained NULL; DECIMAL and integer controls matched. A normal saved SELECT over the same child table round-tripped correctly.
  • The original child table retained 中文 and binary hex FF000A; the copied table held the wrong values after the INSERT. An ALTER on the child did not change the already saved wrong result. Session remained usable.
  • This is a confirmed wrong saved result and downstream wrong persisted copy; it does not overwrite the original source table.

Code analysis

The diff path calls trySaveQueryResult on frontend rows. In convertRowsIntoBatch, the VARCHAR/TEXT case handles strings but formats non-string values using fmt.Sprintf("%v", ...); for a []byte that yields the observed numeric list. The same result metadata conversion maps VAR_STRING to VARCHAR, so binary values also lose their binary type. This is separate from #31534, where JSON/BIT/BLOB cause an explicit unsupported-type error.

Activity

  1. added this to the MO-202610 milestone on Oct 28, 2026
  2. added theissue type on Oct 28, 2026
  3. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:VECF32 的保存结果也发生变化

    在同一 commit f847803802289b2b2d0df4f0a2f842c2804b823a,将分支表的 VECF32(2) 从 [1,1] 更新为 [2,2] 后:

    SET save_query_result = ON;
    DATA BRANCH DIFF c_vector AGAINST b_vector; -- 直接结果为 [2, 2]
    SET @qid = last_query_id();
    SELECT * FROM result_scan(@qid) AS r;       -- 保存结果显示为 [2 2]

    三个新建数据库 qbranchmatrix_07/08/09 均复现;同组 UUID、DECIMAL、ENUM 结果读回一致。该现象与 issue 中的非字符串值经 fmt.Sprintf("%v", ...) 转成文本的代码路径相符,建议回归时一并验证向量的类型和内容。

  4. added
    severity/s0
    ai-easy
    and removed on Nov 5, 2026
  5. gouhongshen commented on Nov 5, 2026

    @gouhongshen
    Contributor

    PR #32269 is trying to fix this issue.

  6. gouhongshen commented on Nov 6, 2026

    @gouhongshen
    Contributor

    PR #32269 has merged and is awaiting manual validation. The issue remains open.

  7. XuPeng-SH commented on Nov 6, 2026

    @XuPeng-SH
    Contributor

    QA 交接(main,待验证,不代表验收通过)

    PR #32269 于 2026-11-06 00:23 UTC 合入 main,merge SHA 2746f81c36644bfe016743a91f3515471fd8e8da。保存 frontend 结果时,VARCHAR/TEXT/VARBINARY 的 string/[]byte 保留原字节,binary charset 的 VAR_STRING/VARCHAR 保留 VARBINARY 类型;vector 复用客户端显示格式,避免保存成 Go 数值列表。

    已完整读取 issue 三条评论、PR 讨论及合并文本改动;原 f847803 的 text/binary 和 VECF32 反例均在此次范围内,未发现适用于合并版本的已验证反例或未完成的本 issue 开发 follow-up。原记录明确等待人工验证,未重复已有 QA 交接。

    已有证据是作者报告的 focused red→green、conversion/result-save 回归、vet 和公开 BVT 21/21,另补 BF16/Float16/int8/block-scaled coverage。审查在 590331d4... 复用成功的对应 head CI与静态/binary-golden audit,没有新的 CGo/SQL 执行或原始运行日志;最终 head 为 3b891a69...,合并队列记录 CI Required 成功。本轮只核对远端状态、讨论和源码范围,没有本地实测,未把旧 head CI 当作本轮全套测试。

    请 @Ariznawlll 在含该 merge 的 main 复测 direct DATA BRANCH DIFF→RESULT_SCAN→INSERT SELECT,核对中文、FF000A、嵌入 NUL/非 UTF-8、空值与 NULL、保存列类型及原表不变;补测 VECF32/F64、窄向量和 block-scaled 的显示文本,及 UUID/ENUM/DECIMAL/integer、普通 saved SELECT 对照。保存的 vector 是显示文本,恢复 vector 类型需要显式 CAST。全 frontend/广泛 BVT、多 CN、升级及历史已保存错误结果的修复未由本轮验证。JSON/BIT/BLOB 不支持保存仍属独立 #31534,本次不自动要求 4.2 backport。

  8. Ariznawlll commented on Nov 6, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    原问题验证

    复测 DATA BRANCH DIFF → RESULT_SCAN → INSERT SELECT:中文 中文 和二进制 FF000A 在直接结果、保存结果及插入目标中一致,原始表未改变;三个入口各重复 3 轮通过。

    Happy Path 覆盖

    1. 文本、VARBINARY、空字符串、空二进制、SQL NULL、非 UTF-8 和嵌入 NUL 逐值一致。保存结果的二进制列 charset 为 63 且带 binary 标记,文本列不带该标记。
    2. VECF32、VECF64、VECF16、VECBF16、VECINT8、VECF8、VECF4、DECIMAL、UUID、ENUM 的保存结果与客户端直接展示逐值一致;普通 /* save_result */ SELECT 保存和读回也通过。保存的向量是展示文本,恢复向量类型仍须显式 CAST。

    Unhappy Path 覆盖

    无效 query id 被拒绝;连接继续可用,源表、分支表和已保存结果保持预期。三个入口各重复 3 轮。

    白盒验证

    frontend 的文本/二进制转换、普通向量展示以及窄向量和块缩放转换定向 Go 单测各重复 3 次通过;没有运行完整 frontend 包或完整 CI。

    回归测试

    主库已有 BVT 和相应 frontend Go 单测,随 #32269 合入。本次未新增 PR。

    测试证据

    官方 mo-tester 309a0ca650e0c55e90292767fd61e4976818d66d:两个 CN 和 Proxy 各 3 轮,每轮 21/21。未验证升级及历史已保存错误结果的修复;JSON/BIT/BLOB 不支持保存属于独立问题 #31534。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions