Skip to content

fix: preserve POWER, EXP, and COT error semantics - #28155

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-28137
Sep 7, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-28137

Conversation

@Lundomn

@Lundomn Lundomn commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Related issue

Related to #28137. This PR does not implement the issue's original request to return NULL for evaluated POWER, EXP, or COT domain/overflow failures and does not claim to satisfy that acceptance criterion.

What this PR does / why we need it:

Preserve the existing MySQL-compatible out-of-range error contract for invalid POWER, EXP, and COT results. POWER and EXP use the shared error-propagating vector helpers; COT retains its error-checking implementation. Evaluated domain or overflow failures therefore abort the statement instead of becoming silent row-local NULL values.

The EXP vector path also respects the selection mask: ignored rows and input NULLs bypass evaluation, while evaluated valid rows retain the existing result semantics.

Compatibility contract and issue disposition

MySQL 8.4 evaluates EXP and POW through check_float_overflow, which raises a floating-point overflow error for non-finite results; COT explicitly raises an overflow error when its tangent is zero. SQRT has a separate NULL-domain path, so its behavior does not establish a blanket NULL contract for these functions. See the MySQL function implementations and non-finite result check.

The reported post-merge errors for POWER(0,-1), POWER(-2,0.5), EXP(710), and COT(0) are consistent with the delivered behavior. See the QA verification.

Issue #28137 still requires maintainer confirmation and correction of its original compatibility expectation. If row-local NULL behavior is desired as a product choice, it requires a separately agreed scope, diagnostics, and aggregate/DML semantics, followed by implementation and validation. This PR does not deliver that behavior.

Regression coverage includes:

  • POWER(0, -1) and POWER(-2, 0.5) domain/overflow errors
  • vector, constant/vector, vector/constant, and constant POWER inputs
  • EXP finite/overflow boundary (709/710)
  • positive and negative zero for COT
  • mixed valid/invalid evaluated rows
  • selection-mask short circuiting and all-masked invalid constants

Validation of the code change:

  • focused pkg/sql/plan/function regression tests
  • complete pkg/sql/plan/function test suite
  • make build-with-prebuilt-native
  • isolated mo-tester BVT: func_math_power (55), func_math_exp (39), func_math_trig (133), and decimal (688) SQL statements passed
  • git diff --check

The compatibility references above are source evidence; no MySQL server execution is claimed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 64c0f6f: all changed production functions, the shared unary/binary null-on-error helpers, constant/vector and selection-mask paths, and all changed UT/BVT expectations.

[P2] Resolve the compatibility contract before replacing out-of-range errors with successful NULL results (func_builtin.go:4008 and 4039; func_binary.go:7516).

The premise in #28137 and the updated func_math_trig.test compatibility comment is incorrect for these functions. MySQL explicitly documents COT(0) as an out-of-range error (https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/mathematical-functions.html). MySQL 8.4 source also routes EXP and POW through check_float_overflow, which raises an error for non-finite results; COT explicitly raises overflow when tan(value) is zero (https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.cc#L2867 and https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.h#L602). This differs from the intentional NULL-domain behavior of SQRT/ACOS and cannot be inferred from those functions.

Concrete changed behavior: SELECT COT(0), SELECT EXP(1000), and SELECT POWER(0,-1) previously failed but now succeed with NULL, without a warning. For a table containing valid and overflowing values, SELECT SUM(EXP(v)) can now successfully return an aggregate that omits the overflowing rows instead of reporting failure. Updating golden outputs to NULL only verifies this changed contract; it does not establish compatibility.

Please preserve the existing out-of-range behavior for a MySQL-compatibility fix (the EXP selection-mask improvement can remain independently). If MO intentionally chooses lenient row-local NULL semantics, explicitly resolve that product-level divergence in the issue/PR and define its scope, diagnostics and DML implications rather than presenting it as restoring MySQL behavior. This is a semantic/design blocker, not a demand for more test evidence alone.

The vector-template reuse itself is reasonable: normal finite calculations are unchanged, constants avoid repeated evaluation, and masks/input NULLs are preserved. No new wait/lock/resource-lifecycle risk was found in this diff. Nonblocking performance note if lenient semantics are selected: each invalid vector row still constructs and formats a discarded moerr; a validity-returning evaluator would avoid error-allocation overhead for dense invalid data.

Evidence: code/contract review plus existing green head CI; no fresh local native execution or MySQL server run was performed.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of commit 64c0f6f5e87f9a5e48b92d5640c8c91f08843054.

[P1][compatibility] Preserve the MySQL error contract for COT(0). Changing builtInCot from the error-checking helper to the null-on-error helper makes SELECT COT(0) succeed with NULL and changes the existing regression expectations accordingly. MySQL explicitly documents an out-of-range error for this input: https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html . The issue's blanket claim that all these math errors should become NULL is insufficient evidence for overriding this specific contract. Restore the COT zero error and verify POWER/EXP error behavior against the intended MySQL version before changing their public semantics. Any intentional divergence needs an explicit product decision, not a MySQL-compatibility claim.

Evidence: source review and existing passing CI for this commit; no new local test run was performed for this review.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep-reviewed exact head 64c0f6f5e87f9a5e48b92d5640c8c91f08843054, including the complete diff, issue #28137, all prior reviews/comments, and the second commit's incremental golden-result update. The vector-helper conversion is mechanically sound and its focused/full/race tests pass, but the requested compatibility contract is still unresolved and the current implementation silently changes public SQL semantics; details are inline. Validation: focused tests PASS (5 runs), full pkg/sql/plan/function PASS, focused race PASS (100 runs), go vet PASS, git diff --check PASS; head CI is green.

Comment thread pkg/sql/plan/function/func_builtin.go Outdated

func builtInCot(parameters []*vector.Vector, result vector.FunctionResultWrapper, proc *process.Process, length int, selectList *FunctionSelectList) error {
return opUnaryFixedToFixedWithErrorCheck[float64, float64](parameters, result, proc, length, func(v float64) (float64, error) {
return opUnaryFixedToFixedWithNullOnError[float64, float64](parameters, result, proc, length, func(v float64) (float64, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve the existing out-of-range error contract unless an explicit product decision approves this incompatibility. Switching COT here—and EXP at line 4039 and POWER in func_binary.go:7517—to the null-on-error helpers makes SELECT COT(0), SELECT EXP(1000), and SELECT POWER(0,-1) succeed with silent NULLs. This is not MySQL compatibility: the MySQL 8.0 manual explicitly shows COT(0) as an out-of-range error, and MySQL 8.4 source sends EXP/POW non-finite results through check_float_overflow while COT calls raise_float_overflow. The impact is silent result corruption rather than just a presentation difference: with rows (0),(1000), SELECT SUM(EXP(v)) now returns the partial aggregate from the valid row instead of failing, and nullable INSERT ... SELECT EXP(v) can store NULL without diagnostics. The issue remains needs-triage and contains no approved divergence or warning/DML contract; changing golden files only records the new behavior. Please keep the error-checking paths (the EXP selection-mask fix can be separated), or first obtain and document the product-level semantic decision and its diagnostics/DML scope.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head c1557b7a90f0549c942110d01ffcf806849f0872: approve. The previous SQL-semantics blocker is closed in the implementation.

The actual current diff does not turn POWER/EXP/COT errors into NULL. POWER now uses the error-propagating binary helper and retains its original math.Pow plus NaN/Inf rejection. EXP uses the error-propagating unary helper around the unchanged momath.Exp; COT's production implementation is unchanged from main. Overflow/domain errors therefore still abort evaluation rather than silently disappearing from aggregates. The new EXP behavior is selection-mask short-circuiting, not lenient arithmetic.

I checked the full six-file diff, shared constant/vector/error helper branches and the evaluator's AllNull mask construction. Input NULLs and ignored rows bypass evaluation, valid finite calculations retain the same kernels, mixed valid/invalid evaluated rows propagate errors, and constant operands avoid redundant calculation. The tests cover each POWER const/vector combination, positive/negative-zero COT controls, EXP 709/710 boundaries and all-masked invalid constants. There is no new concurrent state, lock, goroutine, external resource or per-row allocation on the valid path; the existing error allocation occurs only when returning an actual error.

Nonblocking but important handoff correction: the PR title/body still say invalid results become row-local NULL and list that as the fix for #28137. Please update them to describe the delivered change—preserve the out-of-range contract and use shared vector helpers, including EXP mask handling—and clarify the issue disposition. I am approving the current code, not the stale NULL-semantics claim or an unimplemented change of product behavior.

Evidence: source/helper/test-oracle review and successful exact-head CI run 34091120310 (head verified). No new native/MySQL run or performance benchmark is claimed. No concrete remaining blocker was found.

@Lundomn Lundomn changed the title fix: return NULL for invalid POWER, EXP, and COT results fix: preserve POWER, EXP, and COT error semantics Sep 7, 2026
@Lundomn
Lundomn requested review from aptend and aunjgr September 7, 2026 08:35

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep re-review of exact head c1557b7a90f0549c942110d01ffcf806849f0872 against base 494e6a7723242947c73442528e5fbabe62144ec3. No blocking findings. I read the complete review/comment/thread history, issue #28137, the increment since my prior reviewed head 64c0f6f5e87f9a5e48b92d5640c8c91f08843054, and the full current diff. The prior semantic blocker is closed: POWER and EXP use the shared error-propagating helpers, COT retains its existing error path, and domain/overflow failures still abort the statement rather than becoming row-local NULLs. The net production change is a helper refactor plus EXP selection-mask handling; valid values, input NULLs, constant/vector combinations, and the existing error types/messages remain consistent. Ignored rows and fully masked invalid constants bypass evaluation, while any evaluated invalid row still returns ErrOutOfRange. The shared helpers add no mutable state, retained resource, synchronization, or valid-row allocation. The title/body now describe the delivered error-preserving behavior rather than the abandoned lenient behavior. All exact-head CI checks are green. Independent validation: git diff --check; the full pkg/sql/plan/function suite; and focused race runs of POWER/EXP/COT error and selection-mask cases (-count=20). All passed and the worktree is clean.

@XuPeng-SH
XuPeng-SH merged commit 7fbb401 into matrixorigin:main Sep 7, 2026
16 of 19 checks passed
XuPeng-SH pushed a commit that referenced this pull request Sep 8, 2026
## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #28137. Follow-up to merged PR #28155.

## What this PR does / why we need it:

Implement the row-local NULL behavior requested by #28137.
`POWER(-1,0.5)`, `POWER(0,-1)`, `EXP(1000)`, and `COT(0)` now return
NULL instead of aborting the statement. Valid rows after an invalid row
continue to be evaluated. Existing finite calculations,
underflow-to-zero, input NULLs, and selection masks are preserved
through the existing null-on-error vector helpers.

Mark POWER/POW, EXP, and COT as potentially nullable even with NOT NULL
arguments. This keeps planner deductions, IS NULL predicates, and CTAS
column nullability consistent with the new results.

### Intentional SQL behavior change

This supersedes #28155's error-preserving contract to fulfill the
issue's requested NULL semantics. It is an intentional MatrixOne
behavior change, **not a claim of restoring MySQL compatibility**: MySQL
8.4 routes POW/EXP non-finite results and COT(0) to errors ([function
implementations](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.cc#L2867-L2953),
[overflow
check](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.h#L602-L604)).
Maintainer review should explicitly consider this divergence.

- Aggregates such as SUM/COUNT ignore the resulting NULLs instead of
failing the query.
- INSERT SELECT and UPDATE can store these results in nullable columns.
- NOT NULL constraints still reject them; a rejected mixed-row INSERT
leaves no partial rows.
- No new warning mechanism is added. The issue permits optional
warnings; these arithmetic failures become NULL without emitting a new
warning.
- Other functions, conversion errors, and schema constraints retain
their existing behavior.

### Validation

Base: `b2f0f3fe69b23cde495c59d226c647aba555cfdc` (fresh origin/main when
the branch was created).

- Red/green: 10 arithmetic subcases failed with the original range
errors before the helper changes; all passed afterward. Three
nullable-deduction subcases independently failed before the planner fix.
- Focused POWER/EXP/COT invalid-result and selection-mask tests passed;
the full `pkg/sql/plan/function` suite passed after the final production
change using `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=240s ./pkg/sql/plan/function`.
- `make build-with-prebuilt-native` passed on macOS arm64 / Go 1.27.0.
- Isolated native single-CN mo-tester, normal comparison mode (`nometa
ignore pprof`, equivalent to `-n -g -o -p`): POWER 101, EXP 39, TRIG
133, general math 42, builtin 256, decimal 688: **1,259/1,259 SQL
statements passed**. All five changed cases also passed a second run on
the same instance.
- BVT covers constant folding, decimal/integer casts, mixed vectors,
aggregate/filter behavior, nullable INSERT/UPDATE, NOT NULL rejection
and atomicity, prepared-statement reuse, NOT NULL source columns, IS
NULL predicates, and CTAS metadata. The new tables are dropped and their
absence is asserted.
- Generated result drafts were reviewed against explicit expected rows;
unrelated formatting/metadata drift was removed before normal comparison
runs. Existing affected golden results were updated.
- `git diff --check` passed.

Self-review: R2 SQL result/metadata contract change; existing helpers
and fixtures reused, no new shared state, resource ownership,
persistence format, or distributed protocol. Focused design-document
exemption applies; the contract and tradeoffs are recorded above. No
remaining implementation or validation blocker found. MySQL source
evidence is cited; no MySQL server execution is claimed.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137

## What this PR does / why we need it:

Preserve the existing MySQL-compatible out-of-range error contract for
invalid `POWER`, `EXP`, and `COT` results. `POWER` and `EXP` use the
shared error-propagating vector helpers; `COT` retains its
error-checking implementation. Evaluated domain or overflow failures
therefore abort the statement instead of becoming silent row-local
`NULL` values.

The `EXP` vector path also respects the selection mask: ignored rows and
input `NULL`s bypass evaluation, while evaluated valid rows retain the
existing result semantics.

Regression coverage includes:
- `POWER(0, -1)` and `POWER(-2, 0.5)` domain/overflow errors
- vector, constant/vector, vector/constant, and constant `POWER` inputs
- `EXP` finite/overflow boundary (`709`/`710`)
- positive and negative zero for `COT`
- mixed valid/invalid evaluated rows
- selection-mask short circuiting and all-masked invalid constants

Validation:
- focused `pkg/sql/plan/function` regression tests
- complete `pkg/sql/plan/function` test suite
- `make build-with-prebuilt-native`
- isolated mo-tester BVT: `func_math_power` (55), `func_math_exp` (39),
`func_math_trig` (133), and `decimal` (688) SQL statements passed
- `git diff --check`

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28375)

## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137. Follow-up to merged PR matrixorigin#28155.

## What this PR does / why we need it:

Implement the row-local NULL behavior requested by matrixorigin#28137.
`POWER(-1,0.5)`, `POWER(0,-1)`, `EXP(1000)`, and `COT(0)` now return
NULL instead of aborting the statement. Valid rows after an invalid row
continue to be evaluated. Existing finite calculations,
underflow-to-zero, input NULLs, and selection masks are preserved
through the existing null-on-error vector helpers.

Mark POWER/POW, EXP, and COT as potentially nullable even with NOT NULL
arguments. This keeps planner deductions, IS NULL predicates, and CTAS
column nullability consistent with the new results.

### Intentional SQL behavior change

This supersedes matrixorigin#28155's error-preserving contract to fulfill the
issue's requested NULL semantics. It is an intentional MatrixOne
behavior change, **not a claim of restoring MySQL compatibility**: MySQL
8.4 routes POW/EXP non-finite results and COT(0) to errors ([function
implementations](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.cc#L2867-L2953),
[overflow
check](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.h#L602-L604)).
Maintainer review should explicitly consider this divergence.

- Aggregates such as SUM/COUNT ignore the resulting NULLs instead of
failing the query.
- INSERT SELECT and UPDATE can store these results in nullable columns.
- NOT NULL constraints still reject them; a rejected mixed-row INSERT
leaves no partial rows.
- No new warning mechanism is added. The issue permits optional
warnings; these arithmetic failures become NULL without emitting a new
warning.
- Other functions, conversion errors, and schema constraints retain
their existing behavior.

### Validation

Base: `b2f0f3fe69b23cde495c59d226c647aba555cfdc` (fresh origin/main when
the branch was created).

- Red/green: 10 arithmetic subcases failed with the original range
errors before the helper changes; all passed afterward. Three
nullable-deduction subcases independently failed before the planner fix.
- Focused POWER/EXP/COT invalid-result and selection-mask tests passed;
the full `pkg/sql/plan/function` suite passed after the final production
change using `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=240s ./pkg/sql/plan/function`.
- `make build-with-prebuilt-native` passed on macOS arm64 / Go 1.27.0.
- Isolated native single-CN mo-tester, normal comparison mode (`nometa
ignore pprof`, equivalent to `-n -g -o -p`): POWER 101, EXP 39, TRIG
133, general math 42, builtin 256, decimal 688: **1,259/1,259 SQL
statements passed**. All five changed cases also passed a second run on
the same instance.
- BVT covers constant folding, decimal/integer casts, mixed vectors,
aggregate/filter behavior, nullable INSERT/UPDATE, NOT NULL rejection
and atomicity, prepared-statement reuse, NOT NULL source columns, IS
NULL predicates, and CTAS metadata. The new tables are dropped and their
absence is asserted.
- Generated result drafts were reviewed against explicit expected rows;
unrelated formatting/metadata drift was removed before normal comparison
runs. Existing affected golden results were updated.
- `git diff --check` passed.

Self-review: R2 SQL result/metadata contract change; existing helpers
and fixtures reused, no new shared state, resource ownership,
persistence format, or distributed protocol. Focused design-document
exemption applies; the contract and tradeoffs are recorded above. No
remaining implementation or validation blocker found. MySQL source
evidence is cited; no MySQL server execution is claimed.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137

## What this PR does / why we need it:

Preserve the existing MySQL-compatible out-of-range error contract for
invalid `POWER`, `EXP`, and `COT` results. `POWER` and `EXP` use the
shared error-propagating vector helpers; `COT` retains its
error-checking implementation. Evaluated domain or overflow failures
therefore abort the statement instead of becoming silent row-local
`NULL` values.

The `EXP` vector path also respects the selection mask: ignored rows and
input `NULL`s bypass evaluation, while evaluated valid rows retain the
existing result semantics.

Regression coverage includes:
- `POWER(0, -1)` and `POWER(-2, 0.5)` domain/overflow errors
- vector, constant/vector, vector/constant, and constant `POWER` inputs
- `EXP` finite/overflow boundary (`709`/`710`)
- positive and negative zero for `COT`
- mixed valid/invalid evaluated rows
- selection-mask short circuiting and all-masked invalid constants

Validation:
- focused `pkg/sql/plan/function` regression tests
- complete `pkg/sql/plan/function` test suite
- `make build-with-prebuilt-native`
- isolated mo-tester BVT: `func_math_power` (55), `func_math_exp` (39),
`func_math_trig` (133), and `decimal` (688) SQL statements passed
- `git diff --check`

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28375)

## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137. Follow-up to merged PR matrixorigin#28155.

## What this PR does / why we need it:

Implement the row-local NULL behavior requested by matrixorigin#28137.
`POWER(-1,0.5)`, `POWER(0,-1)`, `EXP(1000)`, and `COT(0)` now return
NULL instead of aborting the statement. Valid rows after an invalid row
continue to be evaluated. Existing finite calculations,
underflow-to-zero, input NULLs, and selection masks are preserved
through the existing null-on-error vector helpers.

Mark POWER/POW, EXP, and COT as potentially nullable even with NOT NULL
arguments. This keeps planner deductions, IS NULL predicates, and CTAS
column nullability consistent with the new results.

### Intentional SQL behavior change

This supersedes matrixorigin#28155's error-preserving contract to fulfill the
issue's requested NULL semantics. It is an intentional MatrixOne
behavior change, **not a claim of restoring MySQL compatibility**: MySQL
8.4 routes POW/EXP non-finite results and COT(0) to errors ([function
implementations](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.cc#L2867-L2953),
[overflow
check](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.h#L602-L604)).
Maintainer review should explicitly consider this divergence.

- Aggregates such as SUM/COUNT ignore the resulting NULLs instead of
failing the query.
- INSERT SELECT and UPDATE can store these results in nullable columns.
- NOT NULL constraints still reject them; a rejected mixed-row INSERT
leaves no partial rows.
- No new warning mechanism is added. The issue permits optional
warnings; these arithmetic failures become NULL without emitting a new
warning.
- Other functions, conversion errors, and schema constraints retain
their existing behavior.

### Validation

Base: `b2f0f3fe69b23cde495c59d226c647aba555cfdc` (fresh origin/main when
the branch was created).

- Red/green: 10 arithmetic subcases failed with the original range
errors before the helper changes; all passed afterward. Three
nullable-deduction subcases independently failed before the planner fix.
- Focused POWER/EXP/COT invalid-result and selection-mask tests passed;
the full `pkg/sql/plan/function` suite passed after the final production
change using `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=240s ./pkg/sql/plan/function`.
- `make build-with-prebuilt-native` passed on macOS arm64 / Go 1.27.0.
- Isolated native single-CN mo-tester, normal comparison mode (`nometa
ignore pprof`, equivalent to `-n -g -o -p`): POWER 101, EXP 39, TRIG
133, general math 42, builtin 256, decimal 688: **1,259/1,259 SQL
statements passed**. All five changed cases also passed a second run on
the same instance.
- BVT covers constant folding, decimal/integer casts, mixed vectors,
aggregate/filter behavior, nullable INSERT/UPDATE, NOT NULL rejection
and atomicity, prepared-statement reuse, NOT NULL source columns, IS
NULL predicates, and CTAS metadata. The new tables are dropped and their
absence is asserted.
- Generated result drafts were reviewed against explicit expected rows;
unrelated formatting/metadata drift was removed before normal comparison
runs. Existing affected golden results were updated.
- `git diff --check` passed.

Self-review: R2 SQL result/metadata contract change; existing helpers
and fixtures reused, no new shared state, resource ownership,
persistence format, or distributed protocol. Focused design-document
exemption applies; the contract and tradeoffs are recorded above. No
remaining implementation or validation blocker found. MySQL source
evidence is cited; no MySQL server execution is claimed.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137

## What this PR does / why we need it:

Preserve the existing MySQL-compatible out-of-range error contract for
invalid `POWER`, `EXP`, and `COT` results. `POWER` and `EXP` use the
shared error-propagating vector helpers; `COT` retains its
error-checking implementation. Evaluated domain or overflow failures
therefore abort the statement instead of becoming silent row-local
`NULL` values.

The `EXP` vector path also respects the selection mask: ignored rows and
input `NULL`s bypass evaluation, while evaluated valid rows retain the
existing result semantics.

Regression coverage includes:
- `POWER(0, -1)` and `POWER(-2, 0.5)` domain/overflow errors
- vector, constant/vector, vector/constant, and constant `POWER` inputs
- `EXP` finite/overflow boundary (`709`/`710`)
- positive and negative zero for `COT`
- mixed valid/invalid evaluated rows
- selection-mask short circuiting and all-masked invalid constants

Validation:
- focused `pkg/sql/plan/function` regression tests
- complete `pkg/sql/plan/function` test suite
- `make build-with-prebuilt-native`
- isolated mo-tester BVT: `func_math_power` (55), `func_math_exp` (39),
`func_math_trig` (133), and `decimal` (688) SQL statements passed
- `git diff --check`

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#28375)

## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#28137. Follow-up to merged PR matrixorigin#28155.

## What this PR does / why we need it:

Implement the row-local NULL behavior requested by matrixorigin#28137.
`POWER(-1,0.5)`, `POWER(0,-1)`, `EXP(1000)`, and `COT(0)` now return
NULL instead of aborting the statement. Valid rows after an invalid row
continue to be evaluated. Existing finite calculations,
underflow-to-zero, input NULLs, and selection masks are preserved
through the existing null-on-error vector helpers.

Mark POWER/POW, EXP, and COT as potentially nullable even with NOT NULL
arguments. This keeps planner deductions, IS NULL predicates, and CTAS
column nullability consistent with the new results.

### Intentional SQL behavior change

This supersedes matrixorigin#28155's error-preserving contract to fulfill the
issue's requested NULL semantics. It is an intentional MatrixOne
behavior change, **not a claim of restoring MySQL compatibility**: MySQL
8.4 routes POW/EXP non-finite results and COT(0) to errors ([function
implementations](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.cc#L2867-L2953),
[overflow
check](https://github.com/mysql/mysql-server/blob/8.4/sql/item_func.h#L602-L604)).
Maintainer review should explicitly consider this divergence.

- Aggregates such as SUM/COUNT ignore the resulting NULLs instead of
failing the query.
- INSERT SELECT and UPDATE can store these results in nullable columns.
- NOT NULL constraints still reject them; a rejected mixed-row INSERT
leaves no partial rows.
- No new warning mechanism is added. The issue permits optional
warnings; these arithmetic failures become NULL without emitting a new
warning.
- Other functions, conversion errors, and schema constraints retain
their existing behavior.

### Validation

Base: `b2f0f3fe69b23cde495c59d226c647aba555cfdc` (fresh origin/main when
the branch was created).

- Red/green: 10 arithmetic subcases failed with the original range
errors before the helper changes; all passed afterward. Three
nullable-deduction subcases independently failed before the planner fix.
- Focused POWER/EXP/COT invalid-result and selection-mask tests passed;
the full `pkg/sql/plan/function` suite passed after the final production
change using `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1
-timeout=240s ./pkg/sql/plan/function`.
- `make build-with-prebuilt-native` passed on macOS arm64 / Go 1.27.0.
- Isolated native single-CN mo-tester, normal comparison mode (`nometa
ignore pprof`, equivalent to `-n -g -o -p`): POWER 101, EXP 39, TRIG
133, general math 42, builtin 256, decimal 688: **1,259/1,259 SQL
statements passed**. All five changed cases also passed a second run on
the same instance.
- BVT covers constant folding, decimal/integer casts, mixed vectors,
aggregate/filter behavior, nullable INSERT/UPDATE, NOT NULL rejection
and atomicity, prepared-statement reuse, NOT NULL source columns, IS
NULL predicates, and CTAS metadata. The new tables are dropped and their
absence is asserted.
- Generated result drafts were reviewed against explicit expected rows;
unrelated formatting/metadata drift was removed before normal comparison
runs. Existing affected golden results were updated.
- `git diff --check` passed.

Self-review: R2 SQL result/metadata contract change; existing helpers
and fixtures reused, no new shared state, resource ownership,
persistence format, or distributed protocol. Focused design-document
exemption applies; the contract and tradeoffs are recorded above. No
remaining implementation or validation blocker found. MySQL source
evidence is cited; no MySQL server execution is claimed.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants