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-6788] LoptOptimizeJoinRule should delegate costs to optimization planner #4148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public LoptOptimizeJoinRule(RelFactories.JoinFactory joinFactory,

findRemovableSelfJoins(mq, multiJoin);

findBestOrderings(mq, call.builder(), multiJoin, semiJoinOpt, call);
findBestOrderings(call, multiJoin, semiJoinOpt);
}

/**
Expand Down Expand Up @@ -443,11 +443,9 @@ private static boolean isSelfJoinFilterUnique(
* @param call RelOptRuleCall associated with this rule
*/
private static void findBestOrderings(
RelMetadataQuery mq,
RelBuilder relBuilder,
RelOptRuleCall call,
LoptMultiJoin multiJoin,
LoptSemiJoinOptimizer semiJoinOpt,
RelOptRuleCall call) {
LoptSemiJoinOptimizer semiJoinOpt) {
final List<RelNode> plans = new ArrayList<>();

final List<String> fieldNames =
Expand All @@ -461,8 +459,7 @@ private static void findBestOrderings(
}
LoptJoinTree joinTree =
createOrdering(
mq,
relBuilder,
call,
multiJoin,
semiJoinOpt,
i);
Expand Down Expand Up @@ -680,8 +677,7 @@ private static void setFactorJoinKeys(
* firstFactor to appear as the first factor in the join
*/
private static @Nullable LoptJoinTree createOrdering(
RelMetadataQuery mq,
RelBuilder relBuilder,
RelOptRuleCall call,
LoptMultiJoin multiJoin,
LoptSemiJoinOptimizer semiJoinOpt,
int firstFactor) {
Expand Down Expand Up @@ -712,7 +708,7 @@ private static void setFactorJoinKeys(
} else {
nextFactor =
getBestNextFactor(
mq,
call.getMetadataQuery(),
multiJoin,
factorsToAdd,
factorsAdded,
Expand All @@ -733,8 +729,7 @@ private static void setFactorJoinKeys(
factorsNeeded.and(factorsAdded);
joinTree =
addFactorToTree(
mq,
relBuilder,
call,
multiJoin,
semiJoinOpt,
joinTree,
Expand Down Expand Up @@ -879,15 +874,16 @@ private static boolean isJoinTree(RelNode rel) {
* add the factor; otherwise, null is returned
*/
private static @Nullable LoptJoinTree addFactorToTree(
RelMetadataQuery mq,
RelBuilder relBuilder,
RelOptRuleCall call,
LoptMultiJoin multiJoin,
LoptSemiJoinOptimizer semiJoinOpt,
@Nullable LoptJoinTree joinTree,
int factorToAdd,
BitSet factorsNeeded,
List<RexNode> filtersToAdd,
boolean selfJoin) {
RelMetadataQuery mq = call.getMetadataQuery();
RelBuilder relBuilder = call.builder();

// if the factor corresponds to the null generating factor in an outer
// join that can be removed, then create a replacement join
Expand Down Expand Up @@ -943,8 +939,7 @@ private static boolean isJoinTree(RelNode rel) {
selfJoin);
LoptJoinTree pushDownTree =
pushDownFactor(
mq,
relBuilder,
call,
multiJoin,
semiJoinOpt,
joinTree,
Expand All @@ -959,10 +954,10 @@ private static boolean isJoinTree(RelNode rel) {
RelOptCost costPushDown = null;
RelOptCost costTop = null;
if (pushDownTree != null) {
costPushDown = mq.getCumulativeCost(pushDownTree.getJoinTree());
costPushDown = call.getPlanner().getCost(pushDownTree.getJoinTree(), mq);
}
if (topTree != null) {
costTop = mq.getCumulativeCost(topTree.getJoinTree());
costTop = call.getPlanner().getCost(topTree.getJoinTree(), mq);
}

if (pushDownTree == null) {
Expand Down Expand Up @@ -1036,8 +1031,7 @@ private static int rowWidthCost(RelNode tree) {
* returned
*/
private static @Nullable LoptJoinTree pushDownFactor(
RelMetadataQuery mq,
RelBuilder relBuilder,
RelOptRuleCall call,
LoptMultiJoin multiJoin,
LoptSemiJoinOptimizer semiJoinOpt,
LoptJoinTree joinTree,
Expand Down Expand Up @@ -1110,8 +1104,7 @@ private static int rowWidthCost(RelNode tree) {
LoptJoinTree subTree = (childNo == 0) ? left : right;
subTree =
addFactorToTree(
mq,
relBuilder,
call,
multiJoin,
semiJoinOpt,
subTree,
Expand Down Expand Up @@ -1165,8 +1158,8 @@ private static int rowWidthCost(RelNode tree) {

// create the new join tree with the factor pushed down
return createJoinSubtree(
mq,
relBuilder,
call.getMetadataQuery(),
call.builder(),
multiJoin,
left,
right,
Expand Down
Loading