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
[Bug]: POW() with negative base and fractional exponent silently returns NULL (MySQL raises 1690) #31155
POW() / POWER() with a negative base and a non-integer exponent returns a silent NULL instead of raising the MySQL-compatible out-of-range error. This is a regression of #25308: that issue was closed in July 2026 when the value changed from NaN to NULL, but MySQL actually raises an error, so the compatibility gap is still open (silent NULL is arguably worse than NaN because it hides domain errors entirely).
Environment
MatrixOne dev build (local multi-CN, main)
MySQL 8.0.45 control
Reproduction
SELECT pow(-2, 0.5);
-- MO : NULL-- MySQL: ERROR 1690 (22003): DOUBLE value is out of range in 'pow(-(2),0.5)'
sqrt(-4), ln(-1), log(-1), log10(-1), log2(-1), asin(2), acos(2) all return NULL on both engines — so those are correct. Only POW/POWER diverges.
Root cause
The July fix for #25308 stopped producing NaN but replaced it with NULL, i.e. the code now maps an out-of-domain math.Pow result to a NULL vector element instead of surfacing an error. MySQL treats a negative base with a fractional exponent as an out-of-range DOUBLE error (1690), not a NULL.
Impact
Silent NULL propagation: pow(-2, 0.5) inside a larger expression silently nulls the whole expression instead of failing loudly, so data-quality problems and user typos go unnoticed.
Porting MySQL queries/tests that expect error 1690 fails.
POW is used for compound-interest / growth / distance style calculations where a negative base with fractional exponent is a genuine domain bug in the query — erroring is the correct behavior.
Expected behavior
SELECT pow(-2, 0.5);
-- ERROR 1690 (22003): DOUBLE value is out of range in 'pow(-(2),0.5)'
i.e. raise errno 1690 the same way MySQL does, and keep the sqrt/ln/log/asin/acos NULL behavior unchanged (those match MySQL).
The November 20 QA acceptance above records the 1690 behavior delivered by #32863. For finite negative bases and finite non-integer exponents, #33126 supersedes that expectation with row-local SQL NULL for both POW and POWER. The implementation is in draft PR #33147. Builds without that change can still exhibit the accepted 1690 behavior.
The main-only MOTR regression and its golden in matrixorigin/motr#358 have been updated at 5a7d8a8. It now checks scalar NULL results, continuation across mixed rows, and storage into a nullable column. The fifteen finite-value, overflow, math-function and short-circuit controls remain covered.
This also affects existing CHECK constraints. In the reviewer's shutdown-upgrade test from v4.2.9, the same table with CHECK (POWER(b, 0.5) > 0) rejected -2 with 1690 before upgrade and admitted it after upgrade because the predicate was UNKNOWN. It rejected 0 with 3819 on both versions.
Activity
fix(function): reject undefined real-domain POW arguments
fix(function): reject undefined real-domain POW arguments
fix(function): reject undefined real-domain POW arguments (#32863)
XuPeng-SH commentedon Nov 19, 2026
转 QA 验证,不代表验收通过,保持 issue 开放。
#32863 已于 2026-11-19 03:26:36 UTC 合入 main,merge SHA
793b62b5b51e92a07b87890f5a94565e376ec58d,最终 head0a3d2c2cf5a6c9286cbfd74c6c9d2b9f8ae5fcbc。有限负底数与有限非整数指数的 POW/POWER 在实际求值行返回 typed DOUBLE out-of-range(MySQL 1690 / SQLSTATE 22003),不再静默 NULL;NULL、空批次、未选中/屏蔽行及其他溢出等既有 NULL 语义保留。证据按来源区分:
4061503845f25d7523c152cd6bcae87a2005a477报告单 CN embedded MySQL 协议 probe:两种函数别名、空/过滤输入、未激活 IF 分支、NULL/overflow 对照、prepared 错误后恢复通过;五个相关包 focused race 通过。多 CN BVT 通过仅来自其冻结 CI 状态,未取得原始 CI 日志。PR 同时包含 GC catalog delete timestamp 读锁修复及测试夹具调整;#31401 cleanup 只新增诊断,失败根因仍未知,不能算作已解决。HAKeeper stall 根因也未确定,不将其与 POW 修复混为一谈。
请 QA 在包含上述 merge 的 main 确认原始 pow(-2,0.5)、power(-8,1.0/3)、power(-8,0.5) 的错误码/SQLSTATE;覆盖常量/向量、NULL、整数指数、空结果、IF/CASE 屏蔽、DECIMAL 转换、prepared 连续错误/恢复、DML 失败原子性,并检查 sqrt/ln/log/asin/acos 及 overflow/EXP/COT 的既有行为不回退。最终版本多 CN、并发、长稳与生产环境边界仍待验证,不自动要求 backport。
完整 issue 当前无其他评论;未见适用于 POW 修复的已验证反例或未完成开发 follow-up。移除原研发负责人,交唯一 @Ariznawlll 继续验证。
Ariznawlll commentedon Nov 20, 2026
QA 验收 2026-11-20:实际通过,关闭
验证环境
max_dop=1默认。git_version()=43fa9f4(version()=8.0.30-MatrixOne-v1.3.0),源码树 HEAD43fa9f4329(origin/main)。修复 PR fix(function): reject undefined real-domain POW arguments #32863 merge commit793b62b5b51e92a07b87890f5a94565e376ec58d经git merge-base --is-ancestor验证为该构建的祖先(修复前构建035af99680验证过不含该修复、问题确实存在于其中,构成修复前对照)。原始问题复现与修复验证
修复前(
035af99680,2026-11-20 实测):pow(-2,0.5)、power(-8,0.5)、power(-8,1.0/3)均静默返回 NULL。修复后(
43fa9f4,同一套隔离环境实测):select pow(-2, 0.5)DOUBLE value is out of range in 'pow(-2,0.5)'select power(-8, 0.5)select power(-8, 1.0/3)pow(-8,0.33333))select pow(-2, -0.5)select power(-2.5, 0.001)select pow(v,2.5) from (select -2 as v union all select 3) tinsert into t values(pow(-2,0.5))保护面回归(Happy/Unhappy path 均实测)
pow(-2,3)=-8、pow(-8,3.0)=-512(整数浮点指数不触发)、pow(2,0.5)、pow(-2,2.0)=4、pow(0,0)=1、pow(-2,-3)=-0.125。pow(2,1024)溢出仍为 NULL、pow(0,-1)NULL、sqrt(-4)/ln(-1)/log2(-1)/asin(2)/acos(2)仍为 NULL,与 MySQL 一致。select if(0, pow(-2,0.5), 1)=1、case when 0 then power(0,-1) else 1 end=1(未路由分支不触发域错误)。select v, pow(v,3)对 (-2,3,-8,2) 全部正确输出。白盒 Go 单测
go test ./pkg/sql/plan/function/ -run 'TestPower' -count=1:ok。TestPower、TestPowerNonDomainFailuresReturnNull/{vector_continues_after_overflow_row, vector_base_with_constant_exponent, overflow_underflow_and_input_null, nan_and_inf_inputs_stay_row-local_null}、TestPowerNegativeFractionalExponentReturnsOutOfRange/...全部 PASS(即在修复代码所在包上直接验证域拒绝与 NULL 契约并存)。motr 回归用例(main-only)
script/14_issue_regression/issue_31155_pow_domain_error.py+ goldenout/issue_31155_pow_domain_error.out(@target-branch: main),推送到 PR example of using uber zap in aoe storage layer #358 headc394f5d(https://github.com/matrixorigin/motr/pull/358)。issue_31155_pow_domain_error(main 分支下)。SUMMARY: all assertions passed。--repeat 3(重复)全部通过;--branch 4.2-dev下no tests matched(exit 2),main-only 门控有效。修复不在 4.2-dev,符合双分支规则(main only)。未验证边界(如实声明)
pow(-2, 1e300)返回 NULL 而非 1690——该形状math.Trunc判定下指数非有限域错误路径,与修复 PR 声明的契约(!IsInf守卫优先)一致,MySQL 同入 NULL/无值情形,不作为缺陷记录。POWER与POW仅验证别名一致性pow(2,3)=power(2,3),未对全部别名重复 1690 断言(同实现路径)。ck89119 commentedon Nov 24, 2026
The November 20 QA acceptance above records the 1690 behavior delivered by #32863. For finite negative bases and finite non-integer exponents, #33126 supersedes that expectation with row-local SQL NULL for both POW and POWER. The implementation is in draft PR #33147. Builds without that change can still exhibit the accepted 1690 behavior.
The main-only MOTR regression and its golden in matrixorigin/motr#358 have been updated at 5a7d8a8. It now checks scalar NULL results, continuation across mixed rows, and storage into a nullable column. The fifteen finite-value, overflow, math-function and short-circuit controls remain covered.
This also affects existing CHECK constraints. In the reviewer's shutdown-upgrade test from v4.2.9, the same table with CHECK (POWER(b, 0.5) > 0) rejected -2 with 1690 before upgrade and admitted it after upgrade because the predicate was UNKNOWN. It rejected 0 with 3819 on both versions.
fix(function): return row-local NULL for fractional powers of negativ…