Repository navigation
Description
Confirmed wrong-result cases
Found during continuous QA for #29249. Production files inspected are identical to main 7ff3eac2e8f17c0d013178c287dc686b4360b0f0; local HEAD 3478e810e9 contains test changes. No production patch, dependency replacement, or benchmark claim is involved.
Two minimal cases were reproduced through the real SQL parser, full planner, optimized TABLE_SCAN filter, and ordinary expression executor. The probe materializes one literal row after binding/optimization and retains the actual casts and resolved comparison overload. This is a planner/executor reproduction, not a running-server BVT result.
| Column domain / row | SQL predicate | Expected usual DOUBLE comparison | Actual optimized predicate / result |
|---|---|---|---|
| DECIMAL(20,0), 9007199254740993 | c=9.007199254740992e15 |
true | native DECIMAL c=9007199254740992, false |
| DECIMAL(20,2), 0.10 | c>=1.04e-1 |
false | native DECIMAL c>=0.10, true |
Independent oracle for the first case was also verified using actual NewCast: DECIMAL integers 9007199254740992 and 9007199254740993 both produce DOUBLE bits 0x4340000000000000. The second case compares 0.10 with 0.104; rounding the constant before comparison changes the result. Scientific notation takes the existing FLOAT64 literal path in BaseBinder.bindNumVal.
Root cause and owner
BindFuncExprImplByPlanExpr already has a guarded DECIMAL/DOUBLE native-domain optimization using decimalFloatComparisonHasUniqueValue. However, the later generic constant/column comparison rewrite calls checkNoNeedCast, whose FLOAT32/FLOAT64-to-DECIMAL branch unconditionally returns true. That later path bypasses the earlier rejection and changes the comparison domain. The optimized scan filter folds the narrowed constant, preserving the wrong result.
The repeated admission paths need a shared proof rather than another independent exception. Relevant owners: pkg/sql/plan/base_binder.go comparison binding and pkg/sql/plan/utils.go constant conversion admission. Related #29510 explicitly required collision and between-scale-point fallbacks; safe filtering performance must remain available.
A second design concern to close in the same proof: planner uniqueness checks currently use fast types.Decimal128ToFloat64, while actual DECIMAL-to-DOUBLE CAST uses exact decimal formatting plus strconv.ParseFloat. Coefficient 3 at scale 20 gives different binary64 values by one ULP. This helper difference alone is not a SQL wrong-result or measured performance claim, but a proof must agree with the actual executor conversion.
Required closure / QA
- Admit narrowing through one existing comparison-conversion responsibility, with no later bypass.
- Preserve collision and off-grid results, including reversed operands and ordered comparisons.
- Prove agreement with actual CAST at decimal rounding boundaries; retain safe native-column filtering cases.
- Check nonfinite/out-of-range values, NULL, prepared values, IN/BETWEEN consumers as applicable to the shared admission owner.
- Avoid globally slowing approximate statistics/import consumers or changing write behavior merely to repair query binding.
Both diagnostic test functions selected their two named cases and terminated with the expected assertion failures; no skipped/empty run is counted as evidence. No query timing or full BVT pass is claimed. Refs #29249.
Additional QA: the existing proof can itself admit an incorrect threshold
A second actual SQL/planner/executor probe confirms that fixing only the late unconditional rewrite is insufficient:
- Column
DECIMAL(20,20), coefficient 3 (0.00000000000000000003). - SQL peer
2.9999999999999997e-20, binary64 bits0x3be1b578c96db19a. - Existing
decimalFloatComparisonHasUniqueValuereturns true. - Actual optimized native DECIMAL equality returns true, while the ordinary DOUBLE comparison must be false: real DECIMAL-to-DOUBLE CAST of coefficient 3 has bits
0x3be1b578c96db19b.
TestDecimalFloatProofCastDiagnostic selected one test and terminated with the expected wrong-result assertion failure on local 81a888c925. This is actual SQL parser → full planner → scan filter → real executor evidence, with one row materialized after binding; it is not a running-server BVT or a performance measurement. A prior attempt lost its output during external artifact cleanup and receives no QA credit; this replacement retained its terminal log.
Fresh main is f1137a6cac72852be2ab2e5078b684b98f23d96c. All comparison/conversion production owners listed above are unchanged from the originally inspected main; the six local QA commits have now been rebased onto this main as head 27ad358c6c. Their 275 types/function Go source files are byte-identical across rebase. The new main changes concern charset compatibility and ISCP timeout reporting, not this conversion proof. No newly run full-main BVT/CI result is claimed. #29593 remains unfixed.
Activity
Fix regexp timeout deadlines and numeric comparison/scaling boundaries (
Ariznawlll commentedon Oct 8, 2026
测试版本
MatrixOne 最新 main
1a0088790c8823bd3fe824ad9ff2ef1ce130eb31;本地独立数据目录、单 CN/TN 服务;MOTR PR #218 已推送,Python 3.10/3.12/3.13 与 Go 离线检查均通过。原问题验证
原
DECIMAL(20,0)与 DOUBLE 在 2^53 邻界比较不再被错误窄化,9007199254740993 = 9.007199254740992e15按 DOUBLE 合同比较为真。正常场景覆盖
DECIMAL(20,2)与 0.104 的大小比较为假;IN、BETWEEN和显式CAST AS DOUBLE对照一致。边界与异常场景覆盖
SQL PREPARE 绑定 DOUBLE/NULL 反复重用,结果稳定;0.00000000000000000003 的极小量比较不被错误取整。
白盒验证
本轮未新增内部 Go UT;通过实际服务执行计划下的 SQL 与显式 DOUBLE 对照,限定结论为这些公开比较路径。
回归测试
新增 MOTR
14_issue_regression.issue_29593_decimal_double_comparison,3/3 通过(26 条语句/轮)。测试证据
MOTR PR #218 中三个原始边界及 prepared golden。
测试结论
测试通过。