orca: fall back on replicated CTE only when consumed in 2+ slices#398
Draft
Alena0704 wants to merge 2 commits into
Draft
orca: fall back on replicated CTE only when consumed in 2+ slices#398Alena0704 wants to merge 2 commits into
Alena0704 wants to merge 2 commits into
Conversation
GPDB has Shared Scan node to share the output of a subplan. Each Shared Scan
node can act like producer or consumer. Each one may be a part of different
slice. One of essential parts of Shared Scan processing is cross-slice
interaction detection. It helps to find the difference in producer's and
consumer's slices and mark underlying Material or Sort nodes as cross-slice.
Cross-slice producer reads all the tuples from child plan before the consumer
Shared Scan can read it.
Before this patch, cross-slice interaction detection of underlying subplan nodes
was broken. We walked through subplans separately from main plan. This, in case
subplan has no motion, caused `shareinput_mutator_xslice_2()` to think we don't
need to mark node as cross-slice - motion stack (`motStack`) used for
cross-slice interaction detection contained only default motion id (0) which
equals to producer's slice id.
Here is the simplified part of new regression test. It shows Shared Scan
consumer under Subplan, which has different (compared to producer upper) slice
id.
```
Sequence
-> Shared Scan (share slice:id 0:0)
-> Seq Scan on t1 t1_1
-> Gather Motion 3:1 (slice3; segments: 3)
-> Redistribute Motion 1:3 (slice1)
-> Function Scan on generate_series
SubPlan 1 (slice1)
-> Shared Scan (share slice:id 1:0)
```
Before this patch, we didn't have upper motions in `motStack`. From now, we dive
into subplans as parts of main plan according to the plan tree hierarchy.
Cross-slice detector understands that our slice(1) is different from producer's
slice(0) and marks node as cross-slice.
Existing logic and comments around rtables left almost unchanged.
Existing tricky logic around joins execution order changed to another tricky
logic which is compatible with `plan_tree_walker()`.
`gporca_optimizer.out` test output changed as we now start
`shareinput_mutator_dag_to_tree()` from the main plan. Before, we started from
subplans and global share input context contained only 3 producers at the time
`set_plan_share_id()` called. Now, at the same place producers count is equal to
4, so RangeTblEntry's name changed.
There was a bug when duplicate subplans were added without new corresponded
subroots. The old shareinput_walker() implementation not called for all
subplans, because forboth() loop stopped early. New shareinput_walker()
implementation not found appropriate subplan's subroot (and used main root as
default). From now, we fix old mistake and create new subroot for each new
subplan.
cherry-pick from a39683f #342 (https://github.com/GreengageDB/greengage)
Conflicts resolved in src/backend/cdb/cdbmutate.c: kept the new
shareinput_walker() and dropped HEAD's old manual Append/MergeAppend/ModifyTable
recursion, which plan_tree_walker() now handles.
Only a replicated CTE consumed in 2+ different slices hangs, not any cross-slice consumer. Narrow the fallback check to that case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
orca: fall back on replicated CTE only when consumed in 2+ slices
Only a replicated CTE consumed in 2+ different slices hangs, not any
cross-slice consumer. Narrow the fallback check to that case