Skip to content

Unexpected Result by UNION #85502

@bajinsheng

Description

@bajinsheng

Describe the problem

An unexpected result in UNION.
The third SELECT is the UNION of above two SELECTs, but the result is not the sum of the results of above two SELECTs.

To Reproduce

CREATE TABLE t1 (c0 BOOL AS (1 IS NULL) STORED, CONSTRAINT "primary" PRIMARY KEY(c0));
CREATE TABLE t2 (c0 INT);
INSERT INTO t2 (c0) VALUES(1);
INSERT INTO t1 DEFAULT VALUES;


SELECT t1.c0 FROM t2 FULL OUTER JOIN t1 ON false WHERE false IN (t1.c0 IS NULL); -- {f}
SELECT t1.c0 FROM t2 FULL OUTER JOIN t1 ON false WHERE NOT false IN (t1.c0 IS NULL); -- {NULL}

SELECT t1.c0 FROM t2 FULL OUTER JOIN t1 ON false WHERE false IN (t1.c0 IS NULL) UNION SELECT t1.c0 FROM t2 FULL OUTER JOIN t1 ON false WHERE NOT false IN (t1.c0 IS NULL); -- {f}

Expected behavior
The result of the third SELECT should be {f}, {NULL}, while it only return one row.

Additional data / screenshots

If applicable, add screenshots to help explain your problem.

Environment:

  • CockroachDB version [5cd0309]
  • Server OS: [Ubuntu 20.04]
  • Client app [cockroach sql]

Additional context

Jira issue: CRDB-18273

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityT-sql-queriesSQL Queries Team

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions