You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance]: DOUBLE comparison on DECIMAL column loses block filtering #29510
A selective equality on a DECIMAL(12,2) column loses block filtering when the comparison peer is DOUBLE. The planner casts the column to DOUBLE, which scans all blocks; the same numeric value as an integer or same-scale DECIMAL literal retains the column's native domain and block filter. This occurs in ordinary SQL with an explicit DOUBLE literal as well as in a binary prepared statement with a float64 parameter, so it is a general comparison coercion/optimizer issue rather than solely a PREPARE issue.
Reproduction and measured impact
On current main with 100,000 sorted rows (d DECIMAL(12,2), values 1.00 through 100000.00):
EXPLAIN ANALYZE SELECTcount(*) FROM t WHERE d=54321;
-- native d=54321.00; Block Filter Cond; 1 block / 8192 scan input rows
EXPLAIN ANALYZE SELECTcount(*) FROM t WHERE d=CAST(54321AS DOUBLE);
-- cast(d AS DOUBLE)=54321; no Block Filter Cond; 13 blocks / 100000 scan input rows; 52ms scan time locally
A Go MySQL binary prepared SELECT count(*) FROM t WHERE d=?, executed 50 times on one connection with float64(54321), took ~2.82 s locally versus ~40–50 ms for integer/text parameters under the same script. The direct EXPLAIN ANALYZE result confirms the scan difference; local timings are not a benchmark-wide claim.
Correctness constraints
A generic DOUBLE-to-DECIMAL cast would change equality for values between DECIMAL scale points (for example, 0.104 versus a 0.10 column value), and precision collisions can occur at larger magnitudes. Preserve current result semantics and warnings. A safe optimization needs a proof that the peer value maps to exactly one representable DECIMAL value under the current comparison domain; otherwise keep the existing fallback. Cover SQL literals, prepared binary float, decimal scale/width, rounding boundaries, NULL and out-of-range values.
Found while challenging #29462/#29505 pushdown behavior; independent from #29506's signed BIGINT case.
Activity
fix: preserve prepared ROUND and TRUNCATE value domains (#29508)
Ariznawlll commentedon Oct 2, 2026
测试版本
maind59cc02ef6ca68f340c9570e56f7eb71d90e42e7原问题验证
构造 100003 行的
DECIMAL(12,2)数据,验证WHERE d = ?的 binary prepared statement。54321:返回 1 行,并启用选择性 block filter;当前 fixture 的目标值位于边界,扫描 2/14 blocks0.104:返回 0 行,保留原有保守路径,扫描 14/14 blocks说明修复只在能证明 DOUBLE 对应唯一 DECIMAL 值时使用原生 DECIMAL 过滤;小数刻度之间的值不会被错误下推。
正常路径覆盖
同一 prepared statement 连续复用,分别绑定安全的 int64、完整 numeric text、float64,均返回 1 行。每类执行 30 次,平均耗时:
边界与保守路径覆盖
0.104不可在DECIMAL(12,2)中精确表示,结果为 0,完整扫描 14 blocks,30 次平均 50.69 ms。白盒与 BVT 验证
MatrixOne 现有用例
test/distributed/cases/prepare/issue_29510_decimal_float_filter.sql连续执行 3 轮均通过。回归测试
已加入 MOTR PR #209,commit
3b4d80060724d3f19c672d9f039c5df951d63c81,用例:suites/14_issue_regression/t/issue_29507_29510_29511_29512_filter_pruning.test14_issue_regression并发套件中该新增用例通过本问题是值域证明和 block-filter 生成逻辑,安全与保守分支均可由确定性 SQL/计划断言覆盖,不依赖数据规模阈值,因此不另加 big-data。
测试结论
最新 main 中,安全 DOUBLE 参数已恢复 DECIMAL 原生过滤;不可精确表示的参数仍保留保守扫描,查询结果与原语义一致,回归已补充。
测试通过。