Skip to content

Disallow comparison operations between incomparable data types #2803

@mrigger

Description

@mrigger

Consider the following test case:

CREATE TABLE T0(c0 BOOL);
INSERT INTO T0(c0) VALUES (true);
SELECT * FROM t0 WHERE NOT (c0 != 2 AND c0) -- expected: {}, actual: {TRUE}

Unexpectedly, H2 fetches a row, while none is expected. Omitting the NOT results in the row being fetched as well, which is as expected. I found this based on commit 59fb36c.

I have started working on a SQLancer implementation for H2, which found this bug using the TLP oracle and the following discrepancy between the result sets:

CREATE TABLE T0(c0 BOOL);
INSERT INTO T0(c0) VALUES (true);
SELECT * FROM t0; -- {TRUE}
SELECT * FROM t0 WHERE c0 != 2 AND c0 UNION ALL SELECT * FROM t0 WHERE NOT (c0 != 2 AND c0) UNION ALL SELECT * FROM t0 WHERE (c0 != 2 AND c0) IS NULL; -- {TRUE, TRUE}

Addresses sqlancer/sqlancer#23. I can continue working on the H2 implementation and reporting bugs if there is an interest, and if (most of) the bugs I'm reporting are fixed within a couple of days.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions