Skip to content

Unexpected Results when Using IN for Floating-Point #7120

@suyZhong

Description

@suyZhong

Consider the test case below. It is unexpected that the second query returns 1 (true). If it is intended, the third query should return the row in the table as well. I guess there might be some optimization in the filter that accidently corrects the expression.

CREATE TABLE t1(c0 INTEGER, PRIMARY KEY(c0));
INSERT INTO t1 (c0) VALUES (1);

SELECT * FROM t1; -- 1
SELECT  (c0 IN (NULL, 0.8)) FROM t1; -- 1 (Unexpected)
SELECT * FROM t1 WHERE (c0 IN (NULL, 0.8)); -- Empty

Besides, the result of the query is different from MySQL.

-- In Dolt:
SELECT  (1 IN (NULL, 0.8)); -- 1
-- In MySQL:
SELECT  (1 IN (NULL, 0.8)); -- NULL

I also noticed that, if we removed the PK constraint, the result of the third query would be 1 (true), which matches the result of the second query, but is different from MySQL.

CREATE TABLE t1(c0 INTEGER);
INSERT INTO t1 (c0) VALUES (1);

SELECT * FROM t1; -- 1
SELECT  (c0 IN ((NULL), 0.8)) FROM t1; -- 1 (Unexpected)
SELECT * FROM t1 WHERE (c0 IN ((NULL), 0.8)); -- 1

I originally find this by building dolt from source code a7447ba. I found I couldn't reproduce the first issue in 1.29.0, but the discrepancy issue still exists.

Kindly inform me if it is caused by distinct reasons.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions