Repository navigation
[SEEK-1414] fix(json): preserve signed microseconds for SQL TIME values - #2631
Merged
Merged
Conversation
Negative SQL TIME values lose their sign when converted to JSON, and JSON TIME comparison discards fractional seconds. The SQL comparison and hash callbacks must agree on the complete signed microsecond value. Production paths and cause The original 93248f3 Windows artifact reproduces eight incorrect comparison rows in a 26-value, 676-pair temporal matrix. Native negative TIME compares correctly, while CAST(TIME AS JSON) prints a positive value. The relevant current win production paths retain this behavior. The datum CAST operator in ob_datum_cast.cpp and the legacy ObObj time_json operator both call json::encode_json_time. Its J_TIME branch reconstructs the positive amplitude through ob_time_to_time but omits DT_MODE_NEG. The JSON expression helper has a separate producer used by constructors such as JSON_ARRAY. It likewise decomposes a signed datum and reconstructs only the amplitude. Preserve the sign in the common builder and copy the already validated signed datum directly in the expression helper. The reverse ObIJsonBase::to_time J_TIME branch repeats the decomposition and loses the sign again. Read the existing signed payload directly so scalar and nested JSON values convert back to the original TIME(6). The SQL CXX temporal comparator previously converted ObTime components to HHMMSS. That conversion loses the negative flag and microseconds. Compare the two J_TIME i64 payloads after both reset_iter calls succeed. Relational comparison avoids subtraction overflow. Other temporal tag combinations retain the existing win ordering matrix and callback behavior. The SQL hash capability previously used the same whole-second conversion. Once comparison distinguishes microseconds, that would put every distinct value within a second into the same deterministic bucket. Feed the complete eight-byte signed integer into the existing synchronous append callback. Equal signed values have equal bytes and hashes under the same algorithm and seed. The supported Windows/Linux x86_64 targets use the existing little-endian representation. History checked a8b56bb, refactor(json): migrate JSON parsing and consumers to Rust (#2541), introduced the present builder, helper and SQL callback paths. The reverse conversion predates that commit and is already present at the checked repository history boundary 2c524b5. This identifies the checked implementation history. It does not claim that the earlier conversion behavior was introduced by #2541. The product branch is rebased against the real fetched windows-mysqltest-fix a9a24a3. Ownership and native Rust contract This change uses the existing CXX bridge and module-owned callbacks. Rust owns binary JSON encoding, decoding and generic comparison dispatch. SQL supplies its database TIME semantics through the existing comparator and hash capabilities. Native Rust callers continue to use ScalarComparator, order/equal_with/contains_with and their custom provider without a C++ bridge object. The existing custom IgnoreFractions behavior and provider error propagation remain intact. The first proposed native Rust TIME special case bypassed that public provider contract and was withdrawn before publication. No Rust API, bridge signature, global context, worker, queue or lifetime is added. The three C++ files complete the existing SQL TIME boundary responsibility. The scalar tag, payload width, binary layout and signed i64 representation stay compatible with the current binary decoder. Datum validation still owns SQL range checks. Borrowed payloads and allocator-owned conversion buffers retain their existing owners. Hash append consumes the stack integer synchronously and retains no pointer. reset_iter and allocation errors follow their existing return paths. No unsafe or panic boundary is introduced. These operations have no independent cancellation or shutdown state. Historical values whose sign was already lost cannot reconstruct that sign from the stored positive amplitude. Executed verification A private native instance extracted from the verified existing official MySQL image ran MySQL 8.0.46. The original 676-pair reference and additional 20-row signed-microsecond matrix ran against the real server. Its exact PID was stopped and reaped. The container entry initially failed at OCI sysfs setup before mysqld started, so the same verified image was used via its native loader and libraries with a private socket and data directory. MySQL 8.0.46 renders the extreme 838-hour JSON TIME inputs as 630 hours. The original 676-pair reference remains exact. Additional range-end text checks use the independently frozen native signed-microsecond input to require full 838-hour values. Comparison and group assertions retain the actual reference results. This boundary is recorded explicitly. Alibaba Cloud Linux 3 x86_64 binaries were built with the pinned SDK and private Bazel cache. A fixed build-only fancy-regex patch framing correction and generated lock metadata were required for both baseline and candidates. They are excluded from this commit. The matched SQL baseline contains the independent Tablet GC commit 7b50fe4 and no JSON fix. The final candidate contains the same GC change plus this exact three-file JSON patch, SHA256 b87a0ae6c0c4ea43744a27dc6ed679c669e270e9b112b35c7c2483ec3bcbb7e9. The final binary SHA256 is faafea6608eb58c01d38cc77accbb204ead6511851470c661d328291c3da5167. The first two-file candidate completed the real probe with 19 failed assertions, exposing the missing common CAST builder path. Stored scalar JSON was positive while JSON_ARRAY's nested TIME retained its sign. That failure was preserved and led to the final builder and reverse-read fixes. The final real 2 CPU / 4 GiB candidate passed the original 676 pairs, all 400 signed boundary pairs, exact ascending/descending order, both requested grouping forms, scalar/nested text, containment, and reverse TIME(6) reads. Actual HASH GROUP BY plans were collected for 1000/2000/4000/8000 distinct microsecond values within one second and for spread-second controls. Every group count matched the distinct input count. No baseline performance ratio is claimed because the baseline incorrectly merges microsecond values into one group. Normal SIGUSR1 shutdown returned zero in 8.010s. The same frozen binary and data directory were restarted after the normal shutdown. All original SELECT checks, 400 boundary pairs, scalar/nested results and reverse TIME(6) reads passed against the persisted data. The unique schema was dropped, independently confirmed absent, and health reads passed. The restarted instance exited zero after SIGUSR1 in 6.006s. A TIME_WAIT-only local port preflight initially rejected the restart before launch. SO_REUSEADDR corrected that temporary controller check after an independent ss read confirmed there was no listener. No SQL assertion or product timeout was relaxed. The existing //rust/json:test target executed with test-result caching disabled. All 119 existing tests passed, including custom temporal provider and error behavior. No tests or temporary probes enter this product commit. One independent baseline bootstrap attempt deadlocked before SQL readiness. Full native thread stacks show the main thread joining a replay worker while holding workers_lock_, and that worker waiting for the same lock to publish an already-started new worker. The existing generic thread-pool stop/expansion protocol requires separate work. The configured 900-second shutdown window expired and the exact owned PID was killed and reaped. A fresh baseline reached readiness and reproduced the JSON failures. The startup failure is preserved separately from the JSON workload results. Remaining boundaries Matching Windows candidate validation remains pending because the VM's SSH connection closes during key exchange. No Windows fix-pass is claimed. The private SDK initialization and the main lane's native process need exact state/cleanup verification when access returns. The PR remains Draft pending those results and independent acceptance. Real regression cases belong in the separate seekdb_test repository under the user's submission rules. No regression MR is claimed here. Master-target delivery Retarget this existing fix PR to the fetched master 00f88ac. The original fix commit was 55029bd on the win baseline. Cherry-pick applies without conflicts and retains the same stable patch-id. The seven PR branches each contain their own product fix only. Existing Linux and Windows runtime evidence belongs to the original win-based artifacts described above. No runtime verification of the new master-based commit is claimed by this branch migration.
willlling
force-pushed
the
fix/seek-1414-json-time-sign
branch
from
November 16, 2026 03:42
55029bd to
ca9c5a0
Compare
Remove 1 full-line explanatory comments that repeat the adjacent code or the public API contract. Keep required copyright, lifecycle, lock-order, cancellation/rollback and workflow security documentation where present. Only complete standalone comment lines are deleted. No statements, strings, preprocessor directives, workflow keys or executable script are changed. Verified the diff contains only these deletions, no added lines and no line continuations; git diff --check passes. Existing functional evidence belongs to the previous product tree; this cleanup does not claim a new runtime test.
…sion CI run 43814769610 compiled the PR merge tree and ran 294 mysqltest cases. expr.json_standard_syntax alone failed, identically on the initial attempt and three existing retries. Its enum assertion expected TIME 12:00:00.000001 to equal 12:00:00.000002; uniqueItems expected those two values to be duplicates. Those expectations captured the old comparator's loss of fractional seconds and contradict this PR's signed-microsecond comparison contract. Run both exact SQL statements on an independently initialized, official MySQL 8.0.46 native server. The reference returns enum=0 and uniqueItems=1, matching the corrected SeekDB output. Identical-value controls return 1 and 0 respectively, and JSON rendering retains both distinct fractions. The reference server exits normally with code 0. OCI startup was denied and not bypassed; native setup first needed an explicit task-private secure-file-priv directory. These setup failures are not SQL passes. Correct only the two existing result values. Keep SQL, case selection, timeouts, retries and product code unchanged; add no tests or framework self-tests. The user was given this precise two-line remedy and has now instructed us to resolve the failures and retry. This is the narrowly scoped existing-result correction, not a general change to product/test submission boundaries or an assertion relaxation. Validation: the previous full CI's only diff is exactly these two values; independent MySQL reference and identical-value controls as above; git diff --check. New-head CI must run after publication; this commit does not claim that pending run has passed.
footka
approved these changes
Nov 17, 2026
footka
enabled auto-merge (squash)
November 17, 2026 02:48
willlling
force-pushed
the
fix/seek-1414-json-time-sign
branch
from
November 19, 2026 09:13
e0a16f5 to
c9eb379
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
修复 SQL TIME 转为 JSON 时丢失负号,以及 JSON 时间比较和散列丢失微秒信息的问题,使构造、比较、散列和转回 TIME 的过程保留完整的有符号微秒值。
背景: Windows 原始验证使用 26 个时间值组成 676 对比较,其中有 8 对结果错误。原生 TIME 中的负一小时小于零,但转换为 JSON 后却显示为正的 01:00:00.000000,负值之间的排序也因此出错。
根因: 负一小时应当以 -3600000000 微秒保存。但是,json::encode_json_time() 调用 ob_time_to_time() 时只组合了时间的绝对值,没有应用 DT_MODE_NEG 负号标志;convert_datum_to_json() 中重复分解和组合时间的过程也会丢失符号。比较路径 compare_temporal() 又将时间转换为时、分、秒表示,丢失了符号和微秒信息,散列路径也只保留了整秒。最后,ObIJsonBase::to_time() 在转回 TIME 时再次组合时间值,同样没有保留负号。这些路径使用了不一致且不完整的时间表示,因而会影响显示、排序、分组和反向转换。
修复与取舍: 修复后的共用 CAST 构造方法会根据负号标志恢复时间值的符号。convert_datum_to_json() 直接使用已经校验过的 datum.get_time(),不再重复分解和组合时间。对于 J_TIME,比较和反向转换直接读取有符号的 64 位微秒值,散列则使用该值的完整 8 字节,从而保留符号和小数部分。此次修改继续使用现有 Rust 解码器、CXX 桥和自定义语义提供者接口,同步回调的生命周期约束也保持不变。
转折: 首个只修改两个文件的候选构建仍有 19 个断言失败。实际运行表明,共用 CAST 构造入口也需要修改;补齐该入口和反向读取路径后,才形成目前的三文件修复。
验证: Linux 验证覆盖了以 MySQL 8.0.46 为参考的 676 对比较、400 对微秒边界比较,以及排序、分组、标量与嵌套 JSON、转回 TIME(6) 和重启读回,相关检查均通过;既有 119 项 Rust 检查也通过。Windows 基线记录了 22 个失败断言,组合候选随后通过了准备阶段 24 项检查和重启读回阶段 34 项检查,两阶段均核对了 676 行比较矩阵。
本轮新增 CI 验证在 master 与当前 PR 的临时合并构建上执行,共运行 294 个用例,唯一失败为 expr.json_standard_syntax。其差异仅为两个相差 1 微秒的 TIME 值在 enum 和 uniqueItems 校验中的返回值;实际结果分别为 0 和 1。真实 MySQL 8.0.46 对相同 SQL 也返回 0 和 1,相同时间值的反向对照分别返回 1 和 0。因此已确认旧测试预期与修复后的微秒精度行为不一致,这两个旧预期现已依据独立参考结果纠正,并触发新提交的完整 CI。旧运行仍保留为失败。新提交
57983d128dd2e57348a2ecc38a614f5e0e646311的运行现已结束:四个 mysqltest 切片和 collect 全部成功,汇总为 295 个用例、0 个失败,expr.json_standard_syntax实际通过;CodeQL 和 CLA 也已通过。翻译检查仍因旧 master 工作流的HTTPError失败,不能将本轮测试通过写成 PR 所有检查全绿。影响平台与版本: Windows 原构建 93248f3 实测复现了负号问题,Linux 旧 win 基线和匹配的组合候选也有实测记录。#2541 引入了当前构造方法、辅助转换方法和 SQL 回调,但反向转换的缺陷在更早代码中已经存在,因此不能将全部问题都归因于 #2541。具体构建对应关系见下方记录。
遗留与验证边界: 当前 PR 与 master 的临时合并构建已完成本轮 CI 编译及 294 个用例的运行,但旧运行中的两个预期不匹配使该轮验证失败;最新提交已纠正这两处预期,新提交的完整 mysqltest 工作流已完成并通过 295 个用例;翻译自动化仍失败,独立保留。历史数据如果已经丢失负号,仅凭保存下来的正值无法还原原始符号。历史 Windows 完整 JSON 原例仍保留严格行序失败记录,虽然全部 178 行按内容和重复次数比较相同;这次 Linux CI 通过不改写该历史结果。另在 MySQL 8.0.46 中,极端 838 小时时间值的 JSON 文本会显示为 630 小时;新增端点文本检查以独立的有符号值为依据,不能声称该部分完全匹配 MySQL。
改动概览
当前分支提交为
57983d128dd2e57348a2ecc38a614f5e0e646311。最新提交仅纠正已有json_standard_syntax.result中两个忽略微秒精度的旧预期值,不改 SQL、产品代码、用例范围或超时预算;此前的纯注释清理提交仍保留在历史中。旧修复提交
55029bdaaa3685e59ee72f0c330fa4057ca7c1d3已无冲突迁移为ca9c5a09611e8d1d6a502a30aec76e2c66c29336。该修复提交直接基于 master00f88ac89b472e4979c37c22036dc2cecdc25e2e;随后新增的提交仅清理注释。git patch-id --stable两侧均为8464b24889d9165e0d80780a25401519aee8c779,git diff --check通过。补丁等价检查只能确认两次修复的差异相同,不能证明其在新 master 环境中的运行行为也相同。旧提交映射和 Git bundle 已保存。src/oblib/common/json_type/json_builder.cppsrc/oblib/common/json_type/ob_json_base.cppsrc/sql/engine/expr/ob_expr_json_func_helper.cpp既有运行验证使用旧 win 基线
a9a24a3113e52e5c2be90f49ca7af8d0255b0b41或相应的组合构建。具体构建 SHA、二进制身份、必要适配及前后对照范围见折叠记录。迁移到 master 时已完成静态检查和补丁校验;先前临时合并构建的唯一用例失败和本次纠正后 295 个用例通过,分别见上述结论及下方 CI 记录。合入理由
构造、比较、散列、反向转换和持久化读回的实测结果共同支持本次修复,避免只修显示而遗漏其他使用路径。合入判断仍需考虑历史数据无法恢复符号、严格行序检查失败、MySQL 极端值差异,以及更广的压力、性能和匹配新 master 的 Windows 制品尚未验证等限制;本轮 master 临时合并构建的编译和 mysqltest 范围已有真实通过证据。
当前 PR 为 Ready for review,目标分支为 master。是否合入仍需结合实际审核、新基线验证和上述风险判断。
Related links
纠正两个旧预期后的完整 CI
本轮 CI:294 个用例,唯一失败为 JSON schema 时间预期
SEEK-1414
原提交
当前提交
验证报告
原始证据包
展开详细复现与验证记录
Linux真实MySQL8.0.46参考的676对、400对微秒边界、排序/分组、scalar/nested、反向TIME(6)及重启读回通过,既有Rust119项通过。Windows基线22个失败,组合候选准备24项和重启读回34项通过,两阶段均核676行矩阵。
上述为既有实测,本次master迁移新增检查限于补丁等价、提交/文件范围、空白错误及身份。旧运行制品与当前master提交存在基线差异,未将既有PASS标记为新head实测PASS。基线验证报告中的完整SHA和组合关系保留在下方。
展开迁移前的真实验证结果与失败记录
//rust/json:test禁用结果缓存执行,119/119 通过。a9a24a311基线保留 22 个失败断言;包含当前补丁的组合制品准备检查 24 PASS、同数据目录重启读回 34 PASS,均无 FAIL,两个阶段都核对了完整 676 行比较矩阵。候选 schema 删除和健康检查通过,进程与端口已清理。Windows 组合制品
f697a798e03b9d26336e26c27c4f3858ec34b43c还含 #2629、#2630 和 #2633;当前三个 JSON 文件与本 PR 完全一致。EXE SHA256 为d664c95832fcbd2706ae02d1b5a1f3c5d019f64844134e1e792f1964f9eebb6a,EXE/PDB GUID、Age 与运行 DLL 清单已核对。Windows 使用明确记录的强制停止后恢复,不声称正常关闭通过;正常 SIGUSR1 证据来自 Linux。展开已实跑输入中的最小SQL摘录
在独占实例执行以下原输入,旧制品返回正TIME文本,原生TIME比较为1而JSON比较为0;已验证修复候选保留负文本且JSON比较为1。
完整676对及400对微秒矩阵、同目录重启与新连接独立读回采用既有证据包中的固定SQL和真实MySQL参考。新master提交尚未重跑。
历史风险与证据范围
展开既有风险、证据链接及历史验证范围
两平台定向 SQL、微秒边界及重启读回已通过。原完整 mysqltest 严格比较仍因无外层 ORDER BY 的 GROUP BY 输出行序出现差异,178 行全行多重集相同,原 expected 和严格 FAIL 均保留;对应结果记录在 SEEK-1414。
沿用已有 J_TIME signed i64 格式;历史已丢失的负号无法由正幅度恢复,跨版本迁移及混合版本尚未实测。MySQL 对极端 ±838 小时 JSON 文本显示为 ±630 小时;原 676 参考保留其实际结果,新增端点文本按独立 signed 微秒输入检查,未声称这部分文本完全匹配 MySQL。
产品提交只含必要代码,无测试或构建适配。真实回归仍应进入 seekdb_test 独立 MR,目前无该 MR。原始输入、失败和本轮结果保存在 SEEK-1414 的证据附件中,访问受工作区权限限制。
本轮验证报告及原始证据包访问受工作区权限限制。
发布说明
修复 JSON TIME 转换的负号丢失及比较、分组的微秒精度丢失。
新增 CI 失败归因与独立参考验证
运行 43814769610 对应 PR head
7448d14b06dacf35b579d7add28e24c6f7c57af3,实际 checkout 的临时合并提交为a9d7dadf6798f5c4bddb689c3a9354e32409821b,master 基线为00f88ac89b472e4979c37c22036dc2cecdc25e2e。编译成功,汇总为 294 个用例,唯一失败用例为expr.json_standard_syntax;该用例首次执行及三次既有 CI 重试均出现同一差异。collect因该用例失败而返回非零,不是独立的汇总程序故障。原 SQL 如下,未修改输入或断言范围:
MySQL 参考还验证了两个值完全相同时的结果:enum 为 1,uniqueItems 为 0。参考服务使用已有官方 MySQL 8.0.46 原生程序、新建独立数据目录和本地 Unix socket,未对外开放端口;运行后已正常 SIGTERM 退出,返回码为 0。最初容器启动因 OCI 挂载权限被拒绝,未使用特权模式绕过;原生启动的首次准备还因默认 secure-file-priv 目录不存在而退出,指定任务私有目录后完成验证。上述准备失败不计为 SQL 验证通过。
根据用户最新的修复并重试要求,已在提交
57983d128dd2e57348a2ecc38a614f5e0e646311中纠正已有 result 文件的两个预期值,并触发完整 CI。产品代码不回退微秒精度、不新增或放宽断言,也不将这次参考验证写成 CI 已经通过。该测试文件来自 #2541,旧预期记录了不同微秒值被当成相同值的行为。新提交完整 CI 的回收结果:运行43820490130,事件为pull_request,绑定head
57983d128dd2e57348a2ecc38a614f5e0e646311。setup、四个mysqltest切片及collect均成功;collect的实际汇总为case_count=295, failed_cases=[], errors=[], success=true。expr.json_standard_syntax在切片2实际执行并通过。前轮294个已运行用例中的失败仍保留,不拼接两次运行数量或抹去旧失败。当前CodeQL三个分析及CLA均成功;同一head的翻译运行43820685921仍报HTTPError。其余七次已请求的旧翻译重试也仍失败,本轮只回收,没有无限追加重跑。翻译修复PR2660现已关闭且未合入,master仍使用旧action;这与本次两处预期纠正的实际测试结果分别判断。