MySQL Forums
Forum List  »  Optimizer & Parser

Documentation regarding operator precedence incorrect for LIKE, REGEXP, IN?
Posted by: Justin Ng
Date: June 12, 2021 01:29PM

I'm looking at MySQL 5.7,
https://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html

It says the following have the same precedence,

```
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
```

It also says,

> For operators that occur at the same precedence level within an expression, evaluation proceeds left to right

This would suggest that `a = b LIKE c` should be parsed as `(a = b) LIKE c`.
However, it is actually parsed as `a = (b LIKE c)`

The reason is because of the following,
```
predicate:
...
| bit_expr LIKE simple_expr opt_escape
...
| bit_expr
```

```
bool_pri:
...
| bool_pri comp_op predicate %prec EQ
...
| predicate
```

https://github.com/mysql/mysql-server/blob/5c8c085ba96d30d697d0baa54d67b102c232116b/sql/sql_yacc.yy#L9376

https://github.com/mysql/mysql-server/blob/5c8c085ba96d30d697d0baa54d67b102c232116b/sql/sql_yacc.yy#L9308

-----

In order to parse as `('a' = 'a') LIKE '0'`, we would need a rule like,

```
predicate:
...
| bool_pri LIKE simple_expr opt_escape
```

because `'a' = 'a'` is a `bool_pri`.

However, there is no such rule.

Options: ReplyQuote


Subject
Views
Written By
Posted
Documentation regarding operator precedence incorrect for LIKE, REGEXP, IN?
129
June 12, 2021 01:29PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.