Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect optimization of operation in expression in WHERE clause #9052

Closed
EmilyOng opened this issue Mar 31, 2025 · 0 comments · Fixed by dolthub/go-mysql-server#2921
Closed
Assignees
Labels
bug Something isn't working correctness We don't return the same result as MySQL customer issue

Comments

@EmilyOng
Copy link

EmilyOng commented Mar 31, 2025

Consider the following test case:

CREATE TABLE t0(c0 INT);
INSERT INTO t0(c0) VALUES(2);
SELECT t0.c0 AS ref0 FROM t0 WHERE (FALSE OR t0.c0) != t0.c0;

Actual:
no rows fetched

Expected:

ref0
2

Description

The condition evaluates to true in the WHERE clause for the row in the table. This is verified as follows:

d0/main*> SELECT t0.c0, (FALSE OR t0.c0) != t0.c0 FROM t0;
+----+---------------------------+
| c0 | (FALSE OR t0.c0) != t0.c0 |
+----+---------------------------+
| 2  | 1                         |
+----+---------------------------+
1 row in set (0.00 sec)

However, in the query plan shown below, the expression (FALSE OR t0.c0) != t0.c0 is optimized as (NOT((t0.c0 = t0.c0))). This is incorrect and prevented the row from being fetched.

d0/main*> EXPLAIN ANALYZE SELECT t0.c0 AS ref0 FROM t0 WHERE (FALSE OR t0.c0) != t0.c0;
+--------------------------------+
| plan                           |
+--------------------------------+
| Project                        |
|  ├─ columns: [t0.c0 as ref0]   |
|  └─ Filter                     |
|      ├─ (NOT((t0.c0 = t0.c0))) |
|      └─ Table                  |
|          ├─ name: t0           |
|          └─ columns: [c0]      |
+--------------------------------+
7 rows in set (0.00 sec)

Notably, the equivalent query produces the expected result:

d0/main*> SELECT t0.c0 AS ref0 FROM t0 WHERE (0 OR t0.c0) != t0.c0;
+------+
| ref0 |
+------+
| 2    |
+------+
1 row in set (0.00 sec)

Dolt Version

I reproduced this on v1.51.0.

d0/main*> SELECT dolt_version();
+----------------+
| dolt_version() |
+----------------+
| 1.51.0         |
+----------------+
1 row in set (0.01 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness We don't return the same result as MySQL customer issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants