incubator-gluten icon indicating copy to clipboard operation
incubator-gluten copied to clipboard

[GLUTEN-10559] Simplify StrictRule and remove unnecessary DummyLeafExec

Open beliefer opened this issue 4 months ago • 15 comments

What changes are proposed in this pull request?

This PR proposes to simplify StrictRule and remove unnecessary DummyLeafExec. Fixes: #10559 This improvement can advance the perf of Spark driver. I paste the perf below. Before this improvement, the benchmark of TPCDS SF1000 show below.

First Second Third. Avg Median
3091.7 s 3012.2 s 3100.7 s 3068.2 s 3034.5 s

Before this improvement, the benchmark of TPCDS SF1000 show below.

First Second Third. Avg Median
2996.5 s 2938.4 s 2945.9 s 2960.267 s 2948.6 s

The average perf advances 3.52% and the median perf advances 2.83%.

There is an example. The original plan:

Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

Before this PR, the transform process is as follows: Because the mechanism of transfomUp, treat Scan OneRowRelation[] first. Scan OneRowRelation[] do not have any children, so nothing could be hidden. Scan OneRowRelation[] cannot be offloaded, so the plan will not change. The current plan show below.

Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

Because Scan OneRowRelation[] do not have any children, so nothing need restore from hidden. So the plan will not change. The current plan show below.

Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

Because the mechanism of transfomUp, treat Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L] now. The child Scan OneRowRelation[] would be hide. So the plan changed. The current plan show below.

Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- DummyLeaf Scan OneRowRelation[]
   +- Scan OneRowRelation[]

After offload Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L], the plan would be ...

ProjectExecTransformer [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- DummyLeaf Scan OneRowRelation[]
   +- Scan OneRowRelation[]

Now restore the child from hidden. The plan would be ...

ProjectExecTransformer [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

After this PR, the transform process is as follows: Because the mechanism of transfomUp, treat Scan OneRowRelation[] first. Scan OneRowRelation[] cannot be offloaded, so the plan will not change. The current plan show below.

Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

Because the mechanism of transfomUp, treat Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L] now. After offload Project [3 AS e#8L, 1 AS c#10, 2 AS d#9L], the plan would be ...

ProjectExecTransformer [3 AS e#8L, 1 AS c#10, 2 AS d#9L]
+- Scan OneRowRelation[]

How was this patch tested?

GA tests.

beliefer avatar Aug 27 '25 09:08 beliefer

Run Gluten Clickhouse CI on x86

github-actions[bot] avatar Aug 27 '25 09:08 github-actions[bot]

Run Gluten Clickhouse CI on x86

github-actions[bot] avatar Aug 27 '25 12:08 github-actions[bot]

https://github.com/apache/incubator-gluten/issues/10559

github-actions[bot] avatar Aug 27 '25 12:08 github-actions[bot]

ping @zhztheplayer @zml1206

beliefer avatar Aug 28 '25 02:08 beliefer

May I know what led you to this attempt?

Thank you! I know that. In fact, DummyLeafExec does not work well due to the transform up. Please see LegacyOffload.

beliefer avatar Aug 29 '25 07:08 beliefer

DummyLeafExec does not work well due to the transform up.

I may lose the contexts... Would you elaborate on this? Thanks.

zhztheplayer avatar Aug 29 '25 15:08 zhztheplayer

I may lose the contexts... Would you elaborate on this? Thanks.

Take an example, a ProjectExec has a child FileSourceScanExec. The StrictRule will transform FileSourceScanExec to FileSourceScanExecTransformer and then transform ProjectExec to ProjectExecTransformer due to transformUp.

When hiding the children of ProjectExec, the child of ProjectExec already be the ProjectExecTransformer, so StrictRule can't hide anything.

beliefer avatar Aug 31 '25 04:08 beliefer

When hiding the children of ProjectExec, the child of ProjectExec already be the ProjectExecTransformer

I still don't understand the example. Are you able to share the plans before and after the strict rule?

zhztheplayer avatar Sep 10 '25 07:09 zhztheplayer

I still don't understand the example. Are you able to share the plans before and after the strict rule?

I added an example into PR's description.

beliefer avatar Sep 10 '25 09:09 beliefer

OffloadOthers(), OffloadExchange(), and OffloadJoin() do not traverse the plan internally, so I also think DummyLeafExec is not necessary.

zml1206 avatar Sep 10 '25 10:09 zml1206

OffloadOthers(), OffloadExchange(), and OffloadJoin() do not traverse the plan internally

Can we keep the hiding children logic in testing only? We should make sure the single node rules doesn't touch the children nodes to keep the logic atomic. If a rule matches and offloads a sub-tree, it should be placed in post-transform instead.

zhztheplayer avatar Sep 10 '25 11:09 zhztheplayer

Can we keep the hiding children logic in testing only? We should make sure the single node rules doesn't touch the children nodes to keep the logic atomic. If a rule matches and offloads a sub-tree, it should be placed in post-transform instead.

I have no idea how to implement this test. I see that the trait OffloadSingleNode has added a note, is it sufficient?

zml1206 avatar Sep 10 '25 12:09 zml1206

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Oct 26 '25 02:10 github-actions[bot]

Please hold this one.

beliefer avatar Oct 28 '25 12:10 beliefer

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Dec 14 '25 02:12 github-actions[bot]