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

Unexpected Results when Querying with NULL values #7025

Closed
suyZhong opened this issue Nov 19, 2023 · 1 comment · Fixed by dolthub/go-mysql-server#2153
Closed

Unexpected Results when Querying with NULL values #7025

suyZhong opened this issue Nov 19, 2023 · 1 comment · Fixed by dolthub/go-mysql-server#2153
Labels
bug Something isn't working correctness We don't return the same result as MySQL customer issue

Comments

@suyZhong
Copy link

Considering the test case below:

CREATE TABLE t2(c0 INT, PRIMARY KEY(c0))
INSERT INTO t2(c0) VALUES (1);

SELECT * FROM t2; -- 1
SELECT (c0 IN (NULL >= 1)) IS NULL FROM t2; -- 1
SELECT * FROM t2 WHERE ((c0 IN (NULL >= 1)) IS NULL); 
-- Expected: 1
-- Actual: empty

The third SELECT returns an empty result, which is surprising: If the result of second query is 1 (TRUE), the value of the IN expression should be true, and thus the third query should return the row in t2.

These test cases works well in MySQL 8.0.33, however not in dolt.

I originally find this by building dolt from source version 4cffade. It could also be reproduced in 1.26.1. I haven't tried on the PR that has not merged yet.

-- We also found similar cases as below
SELECT (c0 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL FROM t2; -- 1
SELECT * FROM t2 WHERE (c0 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL; -- empty

SELECT (c0 IN (NULL * 1)) IS NULL FROM t2; -- 1
SELECT * FROM t2 WHERE ((c0 IN (NULL * 1)) IS NULL); -- empty

Kindly inform me if these are caused by different reasons.

@timsehn timsehn added bug Something isn't working correctness We don't return the same result as MySQL labels Nov 20, 2023
@max-hoffman
Copy link
Contributor

These all look related to our hash map IN executor, so probably a bug there:

tmp4> explain SELECT (c0 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL FROM t2;
+--------------------------------------------------------------------+
| plan                                                               |
+--------------------------------------------------------------------+
| Project                                                            |
|  ├─ columns: [(t2.c0 IN ((NOT((NULL BETWEEN -1 AND 1))))) IS NULL] |
|  └─ Table                                                          |
|      ├─ name: t2                                                   |
|      └─ columns: [c0]                                              |
+--------------------------------------------------------------------+
5 rows in set (0.01 sec)

tmp4> explain SELECT * FROM t2 WHERE (c0 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL;
+------------------------------------+
| plan                               |
+------------------------------------+
| Filter                             |
|  ├─ (t2.c0 HASH IN (NULL)) IS NULL |
|  └─ Table                          |
|      ├─ name: t2                   |
|      └─ columns: [c0]              |
+------------------------------------+
5 rows in set (0.00 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