本文介绍了DRDS中运算符的优先级。

DRDS操作符的优先级由高到低,如下所示:

优先级 运算符
15 !
14 -(负号), ~
13 ^
12 *,/,%,MOD
11 +,-
10 <<,>>
9 &
8 |
7 =(比较运算符等于),<=>,>,>=,<,<=,<>,!=,IS,LIKE,REGEXP,IN
6 BETWEEN
5 NOT
4 AND, &&
3 XOR
2 OR, ||
1 =(赋值运算符)

IN/NOT IN与=优先级

在MySQL 5.7.19中执行如下SQL:

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)
            

可见,在MySQL中,IN/NOT IN的优先级高于=(比较运算符),在DRDS中,严格按照以上优先级实现,在优先级相同的情况下,采用左结合的方式。