Repository navigation
Description
MatrixOne version
bdcada5438 (2026-08-09), local single-node deployment, 6 GiB memory cache.
What happened?
A range predicate whose DECIMAL lower-bound literal has a larger scale (only trailing zeroes) returns wrong rows when a composite secondary index is selected. Equality works, the upper bound works, and the same query is correct with an equal-scale literal or without the secondary index.
The physical index table is complete: it has 10,000 rows for 10,000 base rows, 10,000 distinct encoded index keys, and 10,000 distinct primary-key mappings.
Reproduction
CREATE DATABASE decimal_index_repro;
USE decimal_index_repro;
CREATE TABLE decimal_scale_probe (
tenant_id INT NOT NULL,
id BIGINT NOT NULL,
price DECIMAL(10,2) NOT NULL,
PRIMARY KEY (tenant_id,id),
KEY idx_price_owner (price,tenant_id,id)
);
CREATE TABLE decimal_scale_scan (
tenant_id INT NOT NULL,
id BIGINT NOT NULL,
price DECIMAL(10,2) NOT NULL,
PRIMARY KEY (tenant_id,id)
);
INSERT INTO decimal_scale_probe
SELECT 1 + result % 8, result, CAST(result / 100.0 AS DECIMAL(10,2))
FROM generate_series(1,10000) g;
INSERT INTO decimal_scale_scan SELECT * FROM decimal_scale_probe;
SELECT COUNT(*), SUM(price)
FROM decimal_scale_probe FORCE INDEX(idx_price_owner)
WHERE price BETWEEN 10.250000 AND 15.750000;
-- wrong: 0, 0.00
SELECT COUNT(*), SUM(price)
FROM decimal_scale_probe IGNORE INDEX(idx_price_owner)
WHERE price BETWEEN 10.250000 AND 15.750000;
-- correct: 551, 7163.00
SELECT COUNT(*), SUM(price)
FROM decimal_scale_scan
WHERE price BETWEEN 10.250000 AND 15.750000;
-- correct: 551, 7163.00
SELECT COUNT(*) FROM decimal_scale_probe FORCE INDEX(idx_price_owner)
WHERE price > 10.250000 AND price < 15.750000;
-- wrong: 8975 (scan returns 549)
SELECT COUNT(*) FROM decimal_scale_probe FORCE INDEX(idx_price_owner)
WHERE price = 10.250000;
-- correct: 1
SELECT COUNT(*) FROM decimal_scale_probe FORCE INDEX(idx_price_owner)
WHERE price <= 15.750000;
-- correct: 1575
SELECT COUNT(*) FROM decimal_scale_probe FORCE INDEX(idx_price_owner)
WHERE price BETWEEN 10.25 AND 15.75;
-- correct: 551The optimizer selects the index even without FORCE INDEX, and the default query is also wrong.
Expected behavior
DECIMAL literals with extra trailing-zero scale should compare identically to literals represented at the column scale. Indexed and non-indexed execution must return the same 551 rows (549 for the open interval).
Initial root-cause analysis
The ordinary comparison binder already recognizes harmless trailing-zero scale differences, but the composite-index range rewrite in replaceRangePairCondition serializes copied range constants directly. It does not first normalize each bound to the indexed part's DECIMAL type. The encoded lower key therefore differs from the DECIMAL(10,2) encoding stored in __mo_index_idx_col.
This is distinct from #25348: that issue involved empty/incomplete hidden index tables. Here the hidden table and primary mappings are complete, and changing only the literal scale changes the result.
Additional validation requested
Please cover closed/open range pairs, single-sided lower and upper bounds, equality controls, default/FORCE/IGNORE plans, composite primary keys, and direct physical-index count/distinct-mapping checks after indexed DML.
Activity
XuPeng-SH commentedon Aug 8, 2026
Fix is available in PR #26806. Higher-scale trailing-zero bounds are losslessly normalized before composite-key serialization; rounding-sensitive bounds bypass the index rewrite. Full planner tests and the isolated range BVT pass.
XuPeng-SH commentedon Aug 9, 2026
Round 30 found an index-order interaction between this DECIMAL range-key defect and #26807's VARBINARY prefix defect on a 50,005-row table with composite PK
(tenant_id,id)and both index orders:After an indexed UPDATE that changes both DECIMAL values and binary lengths/NUL prefixes, all three hidden tables remain exactly one-to-one (
50005/50005/50005) and survive restart.With
(amount,b,PK), the higher-scale DECIMAL range-key rewrite prunes the candidate set to zero before the binary predicate can help. Reversing the index to(b,amount,PK)avoids that leading DECIMAL failure but exposes #26807's prefix matching and doubles the result.Please retain this as a cross-regression: fixing either leading key in isolation should not leave the alternate index ordering semantically wrong. The nearest control (the amount-only range) is important because it is currently correct on this
DECIMAL(20,4)data shape.fix(plan): normalize decimal index range bounds (#26806)
Ariznawlll commentedon Aug 12, 2026
测试版本
mainca845354162ca2b01feb391d7b5b6e029c609420mo-service,1 CN / 1 TN / 1 Log service,MySQL text protocol原问题验证
在最新 main 上保留原始 10000 行 DECIMAL(10,2) composite secondary index 数据。高 scale 闭区间在 default/FORCE/IGNORE/shadow scan 四种路径均返回 551 行、SUM(price)=7163.00;高 scale 开区间均返回 549 行,连续 3 轮一致。
Happy Path 覆盖
Unhappy Path 覆盖
本问题由合法 DECIMAL bound 触发,不涉及应拒绝输入。舍入敏感边界
10.255000/15.755000同时覆盖 open 和 BETWEEN 路径,FORCE 与 scan 均返回 550;确认不能通过错误索引重写产生漏行/多行,连接和源数据保持正常。白盒验证
未做故障注入;公开 FORCE INDEX 已强制进入 composite range-key 路径,并用 IGNORE INDEX 和独立 shadow table 双重对照。
回归测试
已加入 motr PR #106 的 storage/index 用例,连续 3 轮稳定通过。
测试证据
motr PR #106;result 记录所有 range 变体、DML 前后查询和物理隐藏表完整性。
测试结论
测试通过。
fix(plan): normalize decimal index range bounds (matrixorigin#26806)
fix(plan): normalize decimal index range bounds (matrixorigin#26806)
fix(plan): normalize decimal index range bounds (matrixorigin#26806)