Repository navigation
fix(vector): reject non-finite results in vector-vector arithmetic (#29085) - #29336
Conversation
…atrixorigin#29085) moarray.Add/Subtract/Multiply/Divide returned their element-wise result without the finite-result check ScalarOp already applies to vector-scalar arithmetic. Two finite vectors could overflow to [+Inf,+Inf] and, since the SQL binary operators (arithmetic.go plusFnArray/minusFnArray/...) return the value as-is, persist Infinity into a VECF32/VECF64 column via CTAS or INSERT ... SELECT -- while the vector-scalar path and a direct insert of [Inf,Inf] are both rejected. Add a shared checkVectorFinite and call it before returning from all four ops. It uses the metric.CheckFinite* test x-x != 0 (0 for every finite x, NaN for +Inf/-Inf/NaN alike) rather than math.IsInf(float64(x),0): it also rejects a NaN produced from a non-finite input (e.g. Inf-Inf, which matrixorigin#29083 shows a cast can feed in) that an IsInf check would miss, and stays in T's domain with no float64 widening per element. The error text matches ScalarOp's "vector contains infinity values" for a consistent arithmetic-overflow message. The check runs after the existing div-by-zero and dimension guards, so those still fire first; finite results are unaffected. Test TestVectorVectorArithmeticRejectsOverflow covers all four ops x VECF32/VECF64 with overflowing finite inputs (the issue's reproduction values), NaN-from-Inf inputs, finite controls, and the preserved div-by-zero / dimension-mismatch guards. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
fixed |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed head a017f89 against main at d7d940e. I found no merge-blocking correctness, resource-lifecycle, or error-propagation issue. The shared finite-result check rejects both overflow and NaN while preserving division-by-zero and dimension error precedence.
Validation: the baseline reproduces the bug, with CTAS and INSERT ... SELECT persisting [+Inf,+Inf]. The PR rejects it across vecf32/vecf64 and all four operators. SQL probes also verified NULL/CASE handling, prepared-statement reuse after an error, and that failed writes do not persist non-finite results. Owning package tests, affected SQL arithmetic tests, build, vet, scoped lint, and current required CI passed.
Non-blocking follow-ups:
- Add permanent public SQL and length 7/8/9 boundary regressions. The committed arithmetic tests currently exercise short vectors directly.
- Record or consider reducing the extra result scan's cost. In a single-thread microbenchmark, 1536-element Add measured ~1.06 us on base vs ~1.81 us on this head; Divide measured ~2.14 us vs ~2.83 us. This does not establish an end-to-end SQL regression.
Merge Queue Status
This pull request spent 1 minute 27 seconds in the queue, with no time running CI. ReasonHintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #29085
What this PR does / why we need it:
Vector-vector
+,-,*,/did not check whether the result stayed finite, so two finite vectors could overflow to[+Inf,+Inf]and — since the SQL binary operators return the value as-is — persist Infinity into aVECF32/VECF64column via CTAS orINSERT ... SELECT. The vector-scalar path (ScalarOp) and a direct[Inf,Inf]insert are both already rejected; this closes the vector-vector gap.Root cause:
pkg/vectorize/moarray/external.go'sAdd/Subtract/Multiply/Dividereturned the element-wise result without the finite checkScalarOpalready applies to vector-scalar arithmetic.Fix:
checkVectorFiniteand call it before returning from all four ops.metric.CheckFinite*testx-x != 0(0 for every finitex, NaN for+Inf/-Inf/NaNalike) rather thanmath.IsInf(float64(x),0): it also rejects a NaN produced from a non-finite input (e.g.Inf-Inf, which [Bug]: vector functions underflow or overflow on finite extreme magnitudes #29083 shows a cast can feed in) that anIsInfcheck would miss, and stays inT's domain with no float64 widening per element.ScalarOp's"vector contains infinity values"(surfaces as ERROR 20101), for a consistent arithmetic-overflow message across both paths.Tests:
TestVectorVectorArithmeticRejectsOverflowcovers all four ops ×VECF32/VECF64with overflowing finite inputs (the issue's reproduction values), NaN-from-Inf inputs, finite controls (no false positives), and the preserved div-by-zero / dimension-mismatch guards. Build, existing arithmetic/scalar tests, and gofmt all clean.