Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
11.6.2
-
Docker 11.6.2-MariaDB-ubu2404
Description
Hi,
According to the official MariaDB documentation, comparison operators have higher precedence than the BETWEEN operator. Here's the relevant part of the documentation:
https://mariadb.com/kb/en/operator-precedence/
(highest)
|
...
|
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN, MEMBER OF |
BETWEEN, CASE, WHEN, THEN, ELSE |
...
|
(lowest)
|
However, we've observed that MariaDB evaluates the BETWEEN operator first, which seems to be in contrast to what's stated in the documentation.
Minimized Query to Reproduce:
SELECT 5 BETWEEN 0 AND 10 = 1; |
Expected Result:
+--------------------------+
|
| 5 BETWEEN 0 AND (10 = 1) |
|
+--------------------------+
|
| 0 |
|
+--------------------------+
|
This is the expected result when the comparator = is evaluated first, as indicated in the documentation. (Note the parentheses around 10 = 1, which are required for correct behavior.)
Actual result (MariaDB, version 11.6.2):
SELECT 5 BETWEEN 0 AND 10 = 1; |
+------------------------+ |
| 5 BETWEEN 0 AND 10 = 1 | |
+------------------------+ |
| 1 |
|
+------------------------+ |
 |
SELECT (5 BETWEEN 0 AND 10) = 1; |
+--------------------------+ |
| (5 BETWEEN 0 AND 10) = 1 | |
+--------------------------+ |
| 1 |
|
+--------------------------+ |
In MariaDB 11.6.2, the actual result is the same as when BETWEEN is explicitly forced to be evaluated first using parentheses.
We believe this behavior is a bug because it differs from the precedence described in the official documentation.
Developers often rely on the official documentation, assuming it's accurate, only to find that it doesn't reflect the actual behavior in this case.
The fact that each DBMS defines the precedence of BETWEEN and comparison operators autonomously makes this situation even more problematic.
We suggest that MariaDB be updated to evaluate comparison operators first, as specified in the documentation, 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,