public static double estimateJoinedRows( JoinRelBase joinRel, RexNode condition) { double product = RelMetadataQuery.getRowCount(joinRel.getLeft()) * RelMetadataQuery.getRowCount(joinRel.getRight()); // TODO: correlation factor return product * RelMetadataQuery.getSelectivity(joinRel, condition); }
public static double estimateJoinedRows( JoinRelBase joinRel, RexNode condition) { double product = RelMetadataQuery.getRowCount(joinRel.getLeft()) * RelMetadataQuery.getRowCount(joinRel.getRight()); // TODO: correlation factor return product * RelMetadataQuery.getSelectivity(joinRel, condition); }
public LoptJoinTree getLeft() { final Node node = (Node) factorTree; return new LoptJoinTree( ((JoinRelBase) joinTree).getLeft(), node.getLeft(), node.getLeft().getParent().isRemovableSelfJoin()); }
final int nFields = origOrder ? origJoin.getRight().getRowType().getFieldCount() : origJoin.getLeft().getRowType().getFieldCount(); for (int i = 0; i < newJoinFields.size(); i++) { final int source = (i + nFields) % newJoinFields.size();
JoinRelBase joinRel = (JoinRelBase) childRel; List<RelDataTypeField> leftFields = joinRel.getLeft().getRowType().getFieldList(); List<RelDataTypeField> rightFields = joinRel.getRight().getRowType().getFieldList();
final RelNode left = rel.getLeft(); final RelNode right = rel.getRight();
public Set<RelColumnOrigin> getColumnOrigins( JoinRelBase rel, int iOutputColumn) { int nLeftColumns = rel.getLeft().getRowType().getFieldList().size(); Set<RelColumnOrigin> set; boolean derived = false; if (iOutputColumn < nLeftColumns) { set = invokeGetColumnOrigins( rel.getLeft(), iOutputColumn); if (rel.getJoinType().generatesNullsOnLeft()) { derived = true; } } else { set = invokeGetColumnOrigins( rel.getRight(), iOutputColumn - nLeftColumns); if (rel.getJoinType().generatesNullsOnRight()) { derived = true; } } if (derived) { // nulls are generated due to outer join; that counts // as derivation set = createDerivedColumnOrigins(set); } return set; }
JoinRelBase joinRel = (JoinRelBase) childRel; List<RelDataTypeField> leftFields = joinRel.getLeft().getRowType().getFieldList(); List<RelDataTypeField> rightFields = joinRel.getRight().getRowType().getFieldList();
public void onMatch(RelOptRuleCall call) { final JoinRelBase join = call.rel(0); List<RexNode> expList = new ArrayList<RexNode>(join.getChildExps()); if (reduceExpressions(join, expList)) { call.transformTo( join.copy( join.getTraitSet(), expList.get(0), join.getLeft(), join.getRight(), join.getJoinType(), join.isSemiJoinDone())); // New plan is absolutely better than old plan. call.getPlanner().setImportance(join, 0.0); } } };
/** * Computes a cost for a join tree based on the row widths of the inputs * into the join. Joins where the inputs have the fewest number of columns * lower in the tree are better than equivalent joins where the inputs with * the larger number of columns are lower in the tree. * * @param tree a tree of RelNodes * * @return the cost associated with the width of the tree */ private int rowWidthCost(RelNode tree) { // The width cost is the width of the tree itself plus the widths // of its children. Hence, skinnier rows are better when they're // lower in the tree since the width of a RelNode contributes to // the cost of each JoinRel that appears above that RelNode. int width = tree.getRowType().getFieldCount(); if (isJoinTree(tree)) { JoinRelBase joinRel = (JoinRelBase) tree; width += rowWidthCost(joinRel.getLeft()) + rowWidthCost(joinRel.getRight()); } return width; }
/** * Determines whether a join is a removable self-join. It is if it's an * inner join between identical, simple factors and the equality portion of * the join condition consists of the same set of unique keys. * * @param joinRel the join * * @return true if the join is removable */ public static boolean isRemovableSelfJoin(JoinRelBase joinRel) { final RelNode left = joinRel.getLeft(); final RelNode right = joinRel.getRight(); if (joinRel.getJoinType() != JoinRelType.INNER) { return false; } // Make sure the join is between the same simple factor final RelOptTable leftTable = RelMetadataQuery.getTableOrigin(left); if (leftTable == null) { return false; } final RelOptTable rightTable = RelMetadataQuery.getTableOrigin(right); if (rightTable == null) { return false; } if (!leftTable.getQualifiedName().equals(rightTable.getQualifiedName())) { return false; } // Determine if the join keys are identical and unique return areSelfJoinKeysUnique(left, right, joinRel.getCondition()); }
RelNode lChild = join.getLeft(); RelNode rChild = join.getRight();
final RelDataType leftRowType = join.getLeft().getRowType(); final RelDataType rightRowType = join.getRight().getRowType(); final VariableReplacer variableReplacer = join.getLeft(), joinType.swap(), join.isSemiJoinDone()); final List<RexNode> exps = RelOptUtil.createSwappedJoinExprs(newJoin, join, true);
join.getTraitSet(), join.getCluster().getRexBuilder().makeLiteral(true), join.getLeft(), join.getRight(), join.getJoinType(),
origJoinRel.getCluster(), origJoinRel.getCluster().traitSetOf(Convention.NONE), origJoinRel.getLeft(), origJoinRel.getRight(), origJoinRel.getCondition(),
getCluster().getTypeFactory().builder() .addAll(getSystemFieldList()) .addAll(getLeft().getRowType().getFieldList()) .addAll(getRight().getRowType().getFieldList()) .build(),
RelDataTypeFactory.FieldInfoBuilder.of( getSystemFieldList()) .addAll(getLeft().getRowType().getFieldList()) .addAll(getRight().getRowType().getFieldList())), fail);