Skip to content

[Tracking]: numeric type inference and overflow semantics refactor #25705

Closed

Description

@ck89119

Tracking

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

ea7b57f

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:

  1. Parameter markers are initially bound as text and are rebound only when they are direct arguments of a function.
  2. A nested arithmetic parent is not rebound after an inner parameter expression changes type at execute time.
  3. INSERT and UPDATE assignment casts are applied after the arithmetic expression has already selected its intermediate
    computation domain.
  4. 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:

  1. An explicit approximate operand (FLOAT or DOUBLE) selects the approximate domain, even when the assignment target is
    exact.
  2. An explicit decimal operand selects the decimal domain.
  3. An exact outer cast or assignment context selects the exact domain when no approximate or decimal sibling overrides it.
  4. An integer sibling selects the integer domain when no stronger context exists.
  5. 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^53 in exact contexts.
  • A typed DOUBLE sibling 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_EXECUTE tests 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

  1. added
    kind/bug
    on Jul 14, 2026
  2. self-assigned this
    on Jul 14, 2026
  3. changed the title [-][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[/+] on Jul 15, 2026
  4. changed the title [-][Refactor]: unify numeric type inference and overflow semantics on main[/-] [+][Tracking]: numeric type inference and overflow semantics refactor[/+] on Jul 15, 2026
  5. added
    severity/s0
    kind/refactor
    and removed
    kind/bug
    on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/refactorseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions