This topic describes the precedence of operators supported by PolarDB-X 1.0.

The following table describes the precedence of operators that are supported by PolarDB-X 1.0. The operators are listed by precedence in descending order.

Precedence Operator
15 !
14 - (unary minus) and ~
13 ^
12 *, /, %, and MOD
11 + and -
10 <<,>>
9 &
8 |
7 = (equality operator for comparison), <=>, >, >=, <, <=, <>, !=, IS, LIKE, REGEXP, and IN
6 BETWEEN
5 NOT
4 AND, &&
3 XOR
2 OR, ||
1 = (assignment operator)

Compare the precedence of the IN and NOT IN operators and the = comparison operator

Execute the following SQL statements on a database that runs MySQL 5.7.19:

mysql> select binary 'a' = 'a' in (1, 2, 3);
+-------------------------------+
| binary 'a' = 'a' in (1, 2, 3) |
+-------------------------------+
|                             1 |
+-------------------------------+
1 row in set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)

mysql> select 1 in (1, 2, 3) = 'a';
+----------------------+
| 1 in (1, 2, 3) = 'a' |
+----------------------+
|                    0 |
+----------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------+
| Level   | Code | Message                               |
+---------+------+---------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
+---------+------+---------------------------------------+
1 row in set (0.00 sec)
            

This example shows that in MySQL, the IN and NOT IN operators have a higher precedence than the = comparison operator.PolarDB-X 1.0 strictly follows the precedence described in the preceding table. If two or more operators that have the same precedence are used in one SQL statement, the operators are evaluated from left to right.