Repository navigation
Description
Tracking
- [Subtask]: add numeric resolver and prepared expression context #25751
- [Subtask]: propagate numeric assignment context across DML paths #25752
- [Subtask]: close the prepared numeric protocol lifecycle #25753
- [Subtask]: unify checked arithmetic and overflow semantics #25754
Each subtask is implemented, tested, reviewed, and submitted independently. This issue owns the cross-subtask compatibility
matrix and is complete only when all four subtasks and the final integration verification are complete.
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Reference server: MySQL 8.4.8
- Development baseline: latest
main
Actual Behavior
Numeric type inference, implicit coercion, decimal precision/scale deduction, and overflow handling are currently distributed
across the binder, shared binary cast tables, arithmetic overloads, assignment casts, and execution kernels. These layers do
not share one numeric-domain contract.
This causes observable inconsistencies, especially for protocol-level prepared statements:
- Parameter markers are initially bound as text and are rebound only when they are direct arguments of a function.
- A nested arithmetic parent is not rebound after an inner parameter expression changes type at execute time.
INSERTandUPDATEassignment casts are applied after the arithmetic expression has already selected its intermediate
computation domain.- Decimal precision/scale deduction and overflow error mapping are implemented in several independent locations.
For example, nested parameter arithmetic can enter the DOUBLE domain too early and lose precision above 2^53:
SET @a = 9007199254740993, @b = 0;
PREPARE p FROM 'SELECT CAST((? + ?) + 1 AS DECIMAL(30,0))';
EXECUTE p USING @a, @b;The same class of problem appears when a typed sibling or an assignment target should determine an exact numeric domain,
including INSERT ... SELECT, parenthesized selects, set operations, star expansion, UPDATE, and ODKU expressions.
Expected Behavior
MatrixOne should have one arithmetic-specific numeric type resolver, with MySQL 8.4 as the compatibility baseline. The
resolver must determine operand coercion types, result type, signedness, and decimal precision/scale before execution kernels
are selected.
The required precedence is:
- An explicit approximate operand (
FLOATorDOUBLE) selects the approximate domain, even when the assignment target is
exact. - An explicit decimal operand selects the decimal domain.
- An exact outer cast or assignment context selects the exact domain when no approximate or decimal sibling overrides it.
- An integer sibling selects the integer domain when no stronger context exists.
- Unresolved parameter arithmetic without any numeric context defaults to
DOUBLE.
An outer target type must not be pushed blindly into every child. For example, a DOUBLE sibling must override a DECIMAL
assignment target so that large opposite operands may cancel in the approximate domain without an earlier decimal overflow.
Refactoring Scope
- Add a pure numeric resolver for
+,-,*,/,DIV,MOD, and unary+/-. - Bind a numeric arithmetic subtree once using typed siblings and optional cast/assignment context.
- Make
CAST, projection,VALUES,INSERT ... SELECT,UPDATE, and ODKU provide context through one binder entry point. - Keep comparisons, temporal arithmetic, JSON, arrays, and string coercion on their existing paths.
- Consolidate checked integer arithmetic and align float/decimal overflow errors with MySQL after behavior is verified.
- Preserve vectorized execution and avoid per-row string conversion, reflection, or unbounded integer allocation.
Acceptance Criteria
- Values, errors, and result metadata match MySQL 8.4 for the numeric behavior matrix.
- Nested prepared-parameter arithmetic preserves values above
2^53in exact contexts. - A typed
DOUBLEsibling overrides an exact assignment target. - Direct and non-direct
INSERT ... SELECT,UPDATE, ODKU, parenthesized select, set operation, and star-expansion paths use
the same inference rules. - Signed/unsigned integer boundaries, decimal precision/scale boundaries, division by zero, and overflow have focused unit
tests. - Real
COM_STMT_PREPARE/COM_STMT_EXECUTEtests cover repeated execution and parameter type changes. - Modified code has at least 75% coverage and dependent package regressions pass.
Non-goals
- Changing comparison, temporal, JSON, array/vector, or string implicit-conversion semantics.
- Changing the global SQL mode error framework without MySQL compatibility evidence.
- Closing, replacing, or changing the status of other issues or pull requests.
Activity
[-][Bug]: prepared-param arithmetic loses precision vs MySQL for nested typed-sibling and non-direct INSERT ... SELECT contexts[/-][+][Refactor]: unify numeric type inference and overflow semantics on main[/+][-][Refactor]: unify numeric type inference and overflow semantics on main[/-][+][Tracking]: numeric type inference and overflow semantics refactor[/+]fix: re-bind prepared-param arithmetic from AST so literal peers keep…
fix: unify checked arithmetic and overflow semantics (#25846)
fix: unify checked arithmetic and overflow semantics (matrixorigin#25846
fix: unify checked arithmetic and overflow semantics (matrixorigin#25846
fix: unify checked arithmetic and overflow semantics (matrixorigin#25846