Description:
Hi,
According to the official documentation, comparison operators and the `IN` operator have the same precedence level and are left-associative. Here’s the relevant excerpt:
<https://dev.mysql.com/doc/refman/8.4/en/operator-precedence.html>
<https://dev.mysql.com/doc/refman/9.1/en/operator-precedence.html>
```sql
(highest)
...
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN, MEMBER OF
...
(lowest)
```
However, we’ve observed that MySQL always evaluates the `IN` operator before comparison operators, which seems inconsistent with the documentation.
How to repeat:
**Minimized Query to Reproduce**:
```sql
SELECT 2 = 5 IN (0, 20, 100);
```
**Expected Result**:
```
mysql> SELECT (2 = 5) IN (0, 20, 100);
+-------------------------+
| (2 = 5) IN (0, 20, 100) |
+-------------------------+
| 1 |
+-------------------------+
1 row in set (0.00 sec)
```
This is the expected result where the comparison is evaluated first, per left-associativity. (Note the parentheses around `2 = 5`, which are required for correct behavior.)
**Actual result** (MySQL, tested on version 8.4.3 and 9.1.0):
```
mysql> SELECT 2 = 5 IN (0, 20, 100);
+-----------------------+
| 2 = 5 IN (0, 20, 100) |
+-----------------------+
| 0 |
+-----------------------+
1 row in set (0.01 sec)
mysql> SELECT 2 = (5 IN (0, 20, 100));
+-------------------------+
| 2 = (5 IN (0, 20, 100)) |
+-------------------------+
| 0 |
+-------------------------+
1 row in set (0.00 sec)
```
The actual result is the same as when `IN` is explicitly forced to be evaluated first with parentheses.
Suggested fix:
We believe this behavior is a bug, as it contradicts the documented precedence rules.
We suggest that MySQL be updated to to evaluate comparisons and `IN` according to left-associativity as specified, or that the documentation be updated to align with the current behavior.
Thank you for your time and attention to this matter. We look forward to your response.
Best regards,