PolarDB-X 1.0-SQL 手册-运算符-运算符优先级

PolarDB-X 中操作符的优先级由高到低,如下所示:

优先级 运算符
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:


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

  8. mysql> show warnings;
  9. +---------+------+---------------------------------------+
  10. | Level | Code | Message |
  11. +---------+------+---------------------------------------+
  12. | Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
  13. +---------+------+---------------------------------------+
  14. 1 row in set (0.00 sec)

  15. mysql> select 1 in (1, 2, 3) = 'a';
  16. +----------------------+
  17. | 1 in (1, 2, 3) = 'a' |
  18. +----------------------+
  19. | 0 |
  20. +----------------------+
  21. 1 row in set, 1 warning (0.00 sec)

  22. mysql> show warnings;
  23. +---------+------+---------------------------------------+
  24. | Level | Code | Message |
  25. +---------+------+---------------------------------------+
  26. | Warning | 1292 | Truncated incorrect DOUBLE value: 'a' |
  27. +---------+------+---------------------------------------+
  28. 1 row in set (0.00 sec)

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

上一篇:php,mysql分页


下一篇:『C程序设计』读书笔记系列文章之第二章 数据类型、运算符与表达式