Skip to content

[Bug]: DIV Operator Correctness Issues #23439

Closed

Description

@XuPeng-SH

Summary

The DIV operator has 4 correctness bugs unrelated to division by zero:

  1. Decimal64 negative sign check error - Sign detection fails for negative values
  2. Prepared statement strict mode - Strict mode doesn't work with prepared statements
  3. uint64 code style inconsistency - Inconsistent cast order
  4. Decimal overflow detection incomplete - Negative overflow not caught

Bug 1: Decimal64 Negative Sign Check Error

Problem: Using < 0 to check sign of uint64 type always returns false

Impact: Negative decimal DIV returns incorrect results

  • Example: -12.00 DIV 3.00 should return -4

Solution: Use Sign() method instead of < 0

Bug 2: Prepared Statement Strict Mode

Problem: ERROR_FOR_DIVISION_BY_ZERO doesn't work with prepared statements

Impact: Strict mode can be bypassed using prepared statements

Solution: Track actual statement type separately from outer statement type

Bug 3: uint64 Code Style

Problem: uint64 uses int64(v1 / v2) while other unsigned types use int64(v1) / int64(v2)

Impact: Code consistency issue, potential future bugs

Bug 4: Decimal Overflow Detection

Problem: Negative overflow not caught when B0_63 < 0x8000000000000000

Impact: Very large negative decimals can silently overflow

Solution: Add range check for B0_63 in negative number validation

MySQL 8.0 Compatibility

All bugs violate MySQL 8.0 DIV operator specification regarding:

  • Correct decimal sign handling
  • Strict mode enforcement
  • Overflow detection

Activity

  1. added this to the MO-202601 milestone on Jan 4, 2026
  2. self-assigned this
    on Jan 4, 2026
  3. added theissue type on Jan 4, 2026
  4. added
    kind/bug
    kind/compatibility
    severity/s0
    on Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugkind/compatibilityseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions