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

[Enhancement] multi left join do not push down #39740

Open
2 of 3 tasks
cambyzju opened this issue Aug 21, 2024 · 1 comment · May be fixed by #42480
Open
2 of 3 tasks

[Enhancement] multi left join do not push down #39740

cambyzju opened this issue Aug 21, 2024 · 1 comment · May be fixed by #42480

Comments

@cambyzju
Copy link
Contributor

cambyzju commented Aug 21, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Description

Version: doris-2.1.5-rc02-a04583c9a1

Step 1: create three tables with same schema, and insert some example data:

CREATE TABLE `a` (
  `k1` INT NOT NULL,
  `k2` INT NOT NULL,
  `v` INT NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
PROPERTIES ("replication_num"="1");

CREATE TABLE `b` (
  `k1` INT NOT NULL,
  `k2` INT NOT NULL,
  `v` INT NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
PROPERTIES ("replication_num"="1");

CREATE TABLE `c` (
  `k1` INT NOT NULL,
  `k2` INT NOT NULL,
  `v` INT NULL
) ENGINE=OLAP
DUPLICATE KEY(`k1`, `k2`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`k1`) BUCKETS 1
PROPERTIES ("replication_num"="1");

INSERT INTO a VALUES(1,2,3),(4,5,6);
INSERT INTO b VALUES(1,2,3),(4,5,6);
INSERT INTO c VALUES(1,2,3),(4,5,6);

Step 2: Use one left join like bellow, we found y.k1=1 generated and pushed down to table b

> explain shape plan select * from a as x left join b as y on x.k1 = y.k1 where y.k1=1;
+--------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                                              |
+--------------------------------------------------------------------------------------------------------------+
| PhysicalResultSink                                                                                           |
| --PhysicalDistribute[DistributionSpecGather]                                                                 |
| ----hashJoin[INNER_JOIN] hashCondition=((x.k1 = y.k1)) otherCondition=() build RFs:RF0 k1->[k1];RF1 k1->[k1] |
| ------filter((x.k1 = 1))                                                                                     |
| --------PhysicalOlapScan[a] apply RFs: RF0 RF1                                                               |
| ------PhysicalDistribute[DistributionSpecHash]                                                               |
| --------filter((y.k1 = 1))                                                                                   |
| ----------PhysicalOlapScan[b]                                                                                |
+--------------------------------------------------------------------------------------------------------------+

Problem 1:
But if we replace table y with another left join, we found y.k1=1 only pushed to join node, not pushed to table b and c

> explain shape plan select * from a as x left join (select c.k1 as k1 from b left join c on b.k1=c.k1) as y on x.k1 = y.k1 where x.k1=1;
+-------------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                                     |
+-------------------------------------------------------------------------------------+
| PhysicalResultSink                                                                  |
| --PhysicalDistribute[DistributionSpecGather]                                        |
| ----hashJoin[LEFT_OUTER_JOIN] hashCondition=((x.k1 = y.k1)) otherCondition=()       |
| ------filter((x.k1 = 1))                                                            |
| --------PhysicalOlapScan[a]                                                         |
| ------PhysicalDistribute[DistributionSpecHash]                                      |
| --------PhysicalProject                                                             |
| ----------filter((y.k1 = 1))                                                        |
| ------------hashJoin[LEFT_OUTER_JOIN] hashCondition=((b.k1 = k1)) otherCondition=() |
| --------------PhysicalProject                                                       |
| ----------------PhysicalOlapScan[b]                                                 |
| --------------PhysicalDistribute[DistributionSpecHash]                              |
| ----------------PhysicalProject                                                     |
| ------------------PhysicalOlapScan[c]                                               |
+-------------------------------------------------------------------------------------+

Problem 2:
If left table is come from UNION, the predict do not push down to table c

> explain shape plan with x as(select * from a union select * from b) select * from x left join c on x.k1=c.k1 where x.k1=1;
+-------------------------------------------------------------------------------+
| Explain String(Nereids Planner)                                               |
+-------------------------------------------------------------------------------+
| PhysicalResultSink                                                            |
| --PhysicalDistribute[DistributionSpecGather]                                  |
| ----hashJoin[LEFT_OUTER_JOIN] hashCondition=((x.k1 = c.k1)) otherCondition=() |
| ------hashAgg[GLOBAL]                                                         |
| --------PhysicalDistribute[DistributionSpecHash]                              |
| ----------hashAgg[LOCAL]                                                      |
| ------------PhysicalUnion                                                     |
| --------------PhysicalDistribute[DistributionSpecExecutionAny]                |
| ----------------PhysicalProject                                               |
| ------------------filter((a.k1 = 1))                                          |
| --------------------PhysicalOlapScan[a]                                       |
| --------------PhysicalDistribute[DistributionSpecExecutionAny]                |
| ----------------PhysicalProject                                               |
| ------------------filter((b.k1 = 1))                                          |
| --------------------PhysicalOlapScan[b]                                       |
| ------PhysicalDistribute[DistributionSpecReplicated]                          |
| --------PhysicalOlapScan[c]                                                   |
+-------------------------------------------------------------------------------+

Solution

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@cambyzju
Copy link
Contributor Author

cambyzju commented Aug 23, 2024

Problem2 will fixed after:#39450

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.

1 participant