final class Arithmetic
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @visibility public.

A binary arithmetic or bit operation of the bit_expr level, in the order written (Item_func_plus, Item_func_int_div, Item_func_bit_or, …).

The operators associate to the left with the levels of MYSQL-PRECEDENCE-001; an operand that would be read differently without a grouping is rejected, among them a right operand of + or - that starts with a leading interval INTERVAL n unit + x, which the parser reads as a trailing interval.

Rule: MYSQL-ARITHMETIC-001. Facts: the type follows MYSQL-NUMERIC-RESULT-001. +, -, * and the bit operators are NULL when an operand is; /, DIV and % are also NULL for a zero divisor. Both operands take a single value. Terminates: the operands are strict parts. Source: https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html, https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html. Status: Implemented.

Writing MOD as the remainder operatordoctest
(new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE a MOD 2 = 1')->toString() // => 'SELECT a FROM t WHERE a % 2 = 1'
Typing a division of integers as DECIMALdoctest
$query = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('SELECT a FROM t WHERE 1 / 2');
    $query->facts->scalar($query->statement->where)->type->descriptor->name() // => 'DECIMAL'

Properties§

public Scalar $left
public Scalar $right

Methods§

public function __construct(
    public ArithmeticOperator $operator,
    public Scalar $left,
    public Scalar $right,
)

Parameters

$operatorArithmeticOperatorThe operator
$leftScalarThe left operand
$rightScalarThe right operand
Calls 8
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives both operands and the type of the result.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

Calls 10
public function render(Output $out): void

Writes the operands around the operator.

Parameters

$outOutput
Test cases 1
Calls 4

Test cases 29§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 5
Other tests reaching this symbol 24

Relations§

Instantiated in 1
Type checks 1