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

Query with an AND predicate, NOT and comparison yields an incorrect result #517

Closed
mrigger opened this issue Apr 11, 2020 · 1 comment · Fixed by #519
Closed

Query with an AND predicate, NOT and comparison yields an incorrect result #517

mrigger opened this issue Apr 11, 2020 · 1 comment · Fixed by #519

Comments

@mrigger
Copy link
Contributor

mrigger commented Apr 11, 2020

Consider the following statements:

CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT);
INSERT INTO t0(c0) VALUES (0);
INSERT INTO t1(c0) VALUES (0);
SELECT * FROM t1, t0 WHERE NOT ((t1.c0 AND t0.c0) < 0); -- expected: {0|0}, actual: {}

Unexpectedly, the query does not fetch a row. The predicate should evaluate to TRUE for the rows in t0, and t1. The negated predicate works as expected and does not fetch any rows:

SELECT * FROM t1, t0 WHERE ((t1.c0 AND t0.c0) < 0); -- {}

I found htis based on the latest commit to master (9795d18).

@Mytherin
Copy link
Collaborator

Fixed this in d88e21d. The issue was that in the planning of a join with an expression in the form of NOT(comparison) we tried to invert the underlying comparison, e.g. NOT(x < 0) is equivalent to x >= 0. The problem is that we did this, then tried to split the comparison into a left and right side, and if this did not succeed we did not properly revert the comparison.

In this query what it would mean is the following:

-- original expression
NOT((t1.c0 AND t0.c0) < 0)
-- transform into:
(t1.c0 AND t0.c0) >= 0
-- cannot divide into left/right side! treat as arbitrary expression
NOT((t1.c0 AND t0.c0) >= 0) -- <= BUG!

I now moved this inversion of the NOT to the parser, so the parser would already invert NOT(x <y) to x>=y. This also makes the code cleaner in general :)

@hannes hannes linked a pull request Apr 12, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants