Skip to content

Unexpected result when using multiple RIGHT JOIN #17089

Closed

Description

@suyZhong

CrateDB version

CrateDB 5.10.0-SNAPSHOT built ef65c3b

CrateDB setup information

Manual build following the instructions here: https://github.com/crate/crate/blob/master/devs/docs/basics.rst

Problem description

Consider the following test case. The second query returns an unexpected result: The first query returns 1 row, and the second query with the filter which will be evaluated to NULL should return an empty set. However, one row is fetched.

PostgreSQL returns an empty result. Besides, the third query also returns one row; the expression t0.c1 != t0.c1 and (t0.c1 != t0.c1) IS NULL should not be evaluated to TRUE at the same time.

Not sure if there's any misunderstanding and if it's related to #16951

Steps to Reproduce

DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t1;

CREATE  TABLE  t0(c0 BOOLEAN , c1 INT );
CREATE  TABLE  t1(c0 BOOLEAN);
INSERT INTO t0(c0, c1) VALUES (false, NULL);
REFRESH TABLE t0;
REFRESH TABLE t1;


SELECT t0.c0 FROM t1 RIGHT  JOIN  (SELECT t0.c0 AS col0 FROM t0) AS sub0  ON true, t0 RIGHT  JOIN  (SELECT true) AS sub1  ON t0.c0; -- NULL

SELECT t0.c0 FROM t1 RIGHT  JOIN  (SELECT t0.c0 AS col0 FROM t0) AS sub0  ON true, t0 RIGHT  JOIN  (SELECT true) AS sub1  ON t0.c0 WHERE t0.c1 != t0.c1;
-- Expected: empty result set
-- Actual: NULL
-- PostgreSQL: empty result set

SELECT t0.c0 FROM t1 RIGHT  JOIN  (SELECT t0.c0 AS col0 FROM t0) AS sub0  ON true, t0 RIGHT  JOIN  (SELECT true) AS sub1  ON t0.c0 WHERE ((t0.c1 != t0.c1) IS NULL); -- NULL

Actual Result

As mentioned above

Expected Result

As mentioned above.

Activity

  1. added
    triageAn issue that needs to be triaged by a maintainer
    on Nov 30, 2024
  2. self-assigned this
    on Dec 2, 2024
  3. added
    bugClear identification of incorrect behaviour
    and removed
    triageAn issue that needs to be triaged by a maintainer
    on Jan 14, 2025
  4. assigned and unassigned on Jan 20, 2025
  5. matriv commented on Jan 24, 2025

    @matriv
    Contributor

    I've tried also to see if there can be an easy fix for this, but it seems we indeed need a bigger refactoring to be able to assign priorities to explicit joins and to outer joins before any implicit ones. Since there is already a PR out towards this direction, I'm re-assigning the issue to @mkleen who has been working on this.

  6. mkleen commented on Feb 6, 2025

    @mkleen
    Contributor

    Fixed by #17100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugClear identification of incorrect behaviour

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions