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

[CALCITE-2204] Use BFS for propagating cost #643

Closed
wants to merge 2 commits into from

Conversation

LeoWangLZ
Copy link
Contributor

@LeoWangLZ LeoWangLZ commented Mar 5, 2018

In function propagateCostImprovements0, This subset is already in the chain being propagated to. This means that the graph is cyclic, and therefore the cost of this relational expression - not this subset - must be infinite. it may miss the best plan. I think we should change the way of propagation. now the algorithm like pre-order, it may use Breadth-first Search.
like

parent21,parent22
    parent11, parent12
        input

now the order of propagation is input->parent11->parent22->parent12.
use BFS, it maybe input->parent11->parent12->parent21->parent22.


void hierarchicalPropagateImprovement(VolcanoPlanner planner, RelMetadataQuery mq,
RelSubset subset, RelNode rel, Set<RelSubset> activeSet) {
Stack<Pair<RelNode, RelSubset>> propagateStack = new Stack<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack class is very legacy, it extends Vector, maybe we can use some better util class

Copy link
Contributor Author

@LeoWangLZ LeoWangLZ Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, It only need Queue for FIFO instead of Stack

@@ -319,9 +321,67 @@ RelNode buildCheapestPlan(VolcanoPlanner planner) {
*/
void propagateCostImprovements(VolcanoPlanner planner, RelMetadataQuery mq,
RelNode rel, Set<RelSubset> activeSet) {
// for (RelSubset subset : set.subsets) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: drop comments

Copy link
Contributor Author

@LeoWangLZ LeoWangLZ Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,I will

@LeoWangLZ LeoWangLZ changed the title [CALCITE-2204]Use BDF for propagating cost [CALCITE-2204]Use BFS for propagating cost Mar 5, 2018
@LeoWangLZ
Copy link
Contributor Author

LeoWangLZ commented Mar 5, 2018

@eolivelli It use ArrayDeque instead of Stack. Please review again. Thanks

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing my comments @LeoWangLZ for me is OK.

Unfortunately I have not enough information to say that this change is good, I did not run tests locally.

my +1 is non-binding, I did only a simple code review

@LeoWangLZ
Copy link
Contributor Author

@eolivelli Thanks again. I think Julian Hyde will review it

@zinking
Copy link
Contributor

zinking commented Mar 29, 2018

could you add some test, say what scenario does this enhancement addresses, there are descriptions in your PR, but your implementation need to be guarded anyway.

@@ -360,6 +359,28 @@ void propagateCostImprovements0(VolcanoPlanner planner, RelMetadataQuery mq,
}
}

void hierarchicalPropagateImprovement(VolcanoPlanner planner, RelMetadataQuery mq,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeoWangLZ what do you think about documenting BFS approach with examples?

@vlsi
Copy link
Contributor

vlsi commented Jan 8, 2019

I wonder how this plays with #552 which seems to update propagateCostImprovements as well.

@LeoWangLZ , have you seen that?

@risdenk risdenk changed the title [CALCITE-2204]Use BFS for propagating cost [CALCITE-2204] Use BFS for propagating cost Feb 28, 2019
@chunweilei
Copy link
Contributor

Close it because it has been fixed in e435954.

@chunweilei chunweilei closed this Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants