apache / doris

Apache Doris is an easy-to-use, high performance and unified analytics database.
https://doris.apache.org
Apache License 2.0
12.3k stars 3.21k forks source link

[Bug] A predicate after right-anti-join should not be pushed down to the scan node of left table #4487

Open WuZixing opened 4 years ago

WuZixing commented 4 years ago

Describe the bug The predicate in the following SQL should not be pushed down to the OlapScanNode corresponding to the left table. SELECT * FROM t1 RIGHT ANTI JOIN t0 ON t1.c2 = t0.c2 AND t1.c4 = t0.c3 WHERE true is NULL;

The result set of this query should be empty. The real execution pushes down the predicate in WHERE clause to the scan node under t1, and left table (t1) of the right-anti-join would be empty, so all rows from the right table (t0) are outputted after join as the result set.

To Reproduce Steps to reproduce the behavior:

  1. Create 2 tables:

Schema:

CREATE TABLE `t0` (
  `c0` tinyint NOT NULL,
  `c1` tinyint NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`c0`, `c1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`c1`, `c0`) BUCKETS 10
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);
CREATE TABLE `t1` (
  `c0` tinyint NOT NULL,
  `c1` tinyint NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`c0`, `c1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`c1`, `c0`) BUCKETS 10
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);

Rows:

insert into t0 (c0,c1) values (1, 2);
insert into t1 (c0,c1) values (3, 4);
  1. This query will produce a result set of one row (1,2), while it's supposed to be empty:

SELECT * FROM t1 RIGHT ANTI JOIN t0 ON t1.c0 = t0.c0 AND t1.c1 = t0.c1 WHERE true is NULL;

xinghuayu007 commented 4 years ago

which version does this bug appear