Repository navigation
Description
Description
MatrixOne orders JSON boolean literals below JSON numeric and string scalars. This makes direct JSON comparisons and ascending ORDER BY on JSON scalar columns differ from MySQL.
Environment
- Branch:
main - Commit:
17c161a31b47a22e71ca222839143f66717ac365 - Deployment: local single-CN test service
- Test date: 2026-09-03
- MySQL control: isolated MySQL
8.0.45
Steps to reproduce
SELECT
CAST('true' AS JSON) > CAST('[]' AS JSON) AS bool_gt_array,
CAST('true' AS JSON) > CAST('{}' AS JSON) AS bool_gt_object,
CAST('true' AS JSON) > CAST('\"a\"' AS JSON) AS bool_gt_string,
CAST('true' AS JSON) > CAST('1' AS JSON) AS bool_gt_number;
CREATE TABLE t (id INT PRIMARY KEY, j JSON);
INSERT INTO t VALUES
(1, CAST('null' AS JSON)), (2, CAST('false' AS JSON)),
(3, CAST('true' AS JSON)), (4, CAST('0' AS JSON)),
(5, CAST('\"a\"' AS JSON));
SELECT JSON_TYPE(j) FROM t ORDER BY j, id;Actual behavior
Three independent MatrixOne executions return:
bool_gt_array bool_gt_object bool_gt_string bool_gt_number
0 0 0 0
NULL
BOOLEAN
BOOLEAN
INTEGER
STRING
Expected behavior
The isolated MySQL 8.0.45 control returns 1,1,1,1 for the pairwise predicates and orders the scalar JSON column as:
NULL
INTEGER
STRING
BOOLEAN
BOOLEAN
This matches MySQL JSON type precedence: booleans compare above arrays, objects, strings, and numbers; JSON null is lowest. Reference: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
Stability and controls
- MatrixOne reproducer:
3/3. - MySQL 8.0.45 control: all pairwise predicates return
1; scalar ordering is as shown above. - Controls in MatrixOne:
ARRAY > OBJECT,OBJECT > STRING,STRING > INTEGER, andINTEGER > NULLeach return1, isolating the problem to the literal/boolean precedence category. - No DDL or DML persists after the probe.
Code analysis
pkg/container/bytejson/types.go assigns every LITERAL (JSON null, false, and true) one jsonTpOrder value of -11, below numeric and container types. CompareByteJson uses that map for cross-type comparisons; it is used by SQL JSON comparisons and the JSON sort comparator in pkg/sort/sort.go. This collapses JSON null and JSON booleans into one low-precedence category, whereas MySQL requires JSON null to be lowest and JSON booleans to have high precedence.
Regression coverage
After the fix, add deterministic JSON comparison/sort coverage for JSON null, booleans, numeric scalars, and strings. Include pairwise boolean comparisons with arrays/objects, but do not assert an order for nonscalar ORDER BY, because MySQL documents that nonscalar JSON sorting is not supported.
Activity
Ariznawlll commentedon Sep 3, 2026
补充范围:该排序问题不止 JSON boolean。
在同一 main commit 的三次独立执行中,先把 SQL
DATE、TIME、DATETIME、BLOB放入JSON_ARRAY(),再用JSON_EXTRACT(..., $[0])取回 JSON 标量:JSON_TYPE()分别为DATE、TIME、DATETIME、BLOB,确认比较的是带类型的 JSON 值。MySQL 的 JSON 预期升序为
DATE,TIME,DATETIME,BLOB(其优先级列表从高到低为BLOB ... DATETIME, TIME, DATE ...)。因此当前实现不仅将 boolean 放错位置,也把BLOB/DATETIME/TIME/DATE的相对顺序完全反转。这与
pkg/container/bytejson/types.go:jsonTpOrder的负序映射一致;该映射同时被比较和排序路径使用。[-][Compatibility]: JSON boolean sort and comparison precedence differs from MySQL[/-][+][Bug]: JSON boolean sort and comparison precedence is incorrect[/+]fix: correct JSON comparison precedence (#28086)
test(vectorindex): encode JSON ColumnBuffer fixtures (#28769)
fix: correct JSON comparison precedence (matrixorigin#28086)
test(vectorindex): encode JSON ColumnBuffer fixtures (matrixorigin#28769
fix: correct JSON comparison precedence (matrixorigin#28086)
test(vectorindex): encode JSON ColumnBuffer fixtures (matrixorigin#28769
fix: correct JSON comparison precedence (matrixorigin#28086)
test(vectorindex): encode JSON ColumnBuffer fixtures (matrixorigin#28769
Ariznawlll commentedon Oct 22, 2026
Fix verification on dev build
3a1e42b430(v1.3.0, 2026-10-22): JSON boolean precedence now matches MySQL.Full-spectrum ORDER BY on a mixed JSON column (null/number/string/object/array/false/true) now produces
null < 1 < "s" < {"a":1} < [1] < false < true, identical to MySQL 8.0.45 verified side-by-side on the same fixture. The scalar type-major ordering is fully fixed on main.Remaining divergences observed during the same sweep are cosmetic and outside this issue's scope: (1) MySQL emits Warning 1235 ("sorting of non-scalar JSON values") while MatrixOne is silent, and (2) inter-object ordering differs — but MySQL's own manual states that ordering of non-equal objects is "unspecified but deterministic", so both are allowed.
Ariznawlll commentedon Nov 29, 2026
结论
测试通过。JSON boolean 与带类型日期/时间/BLOB 标量的比较、排序已与 MySQL 对照一致。
关键证据
版本与环境
922815d74fe664dc9f4ea7bfc4c4e8ac3b279cd0;本次 Linux CI 从官方 main 检出的实际版本为231b68c2d6421e9d212538866e0f825afd6c13e8,两处分别核对完整git_version()。CI 比本地多了 Release merge spill buffers on panic #32160,核对差异仅为 spill sinker 及其两个测试文件。以下 CI 的正式 SQL、SDK 和源码测试确实在 CI 版本上重新执行;不把 MOTR commit 当作 MO 版本,也不将 main 结果外推为 4.2-dev 通过。步骤、断言与实际结果
未把 MySQL 不保证的非标量对象内部排序当作通过标准。源码
TestCompareByteJson*三轮覆盖比较器路径;没有仅凭旧 boolean 修复遗漏后续 typed scalar 报告。回归与 CI
qa-acceptance-main中版本、正式结果、原生测试和 SDK 日志。本轮整体正式 MOTR 63/63(21 个用例各三轮)、0 失败;63 次不全属于本 Issue。待解决点
本 Issue 上述原始问题与相关边界没有未通过项。该结论不扩展为其他 Issue、大数据性能或未执行的生产拓扑验收。MOTR 回归已经提交,按用户允许先验收关闭、随后合入 PR 的流程处理。
最终结论:测试通过。原始复现、上述扩展、对应 MOTR 回归及 Linux CI 均已完成;本 Issue 验收范围内未通过项:无。按授权关闭 #28039。