private static Set<ImmutableBitSet> getUniqueKeys(Correlate rel) { return getUniqueKeys(rel.getLeft()); }
Project project, Set<Integer> isCount) { final RelNode left = correlate.getLeft(); final JoinRelType joinType = correlate.getJoinType().toJoinType();
LogicalProject project, Set<Integer> isCount) { final RelNode left = correlate.getLeft(); final JoinRelType joinType = correlate.getJoinType().toJoinType();
public Set<ImmutableBitSet> getUniqueKeys(Project rel, RelMetadataQuery mq, boolean ignoreNulls) { // LogicalProject maps a set of rows to a different set; // Without knowledge of the mapping function(whether it // preserves uniqueness), it is only safe to derive uniqueness // info from the child of a project when the mapping is f(a) => a. // // Further more, the unique bitset coming from the child needs // to be mapped to match the output of the project. final Map<Integer, Integer> mapInToOutPos = new HashMap<>(); final List<RexNode> projExprs = rel.getProjects(); final Set<ImmutableBitSet> projUniqueKeySet = new HashSet<>(); // Build an input to output position map. for (int i = 0; i < projExprs.size(); i++) { RexNode projExpr = projExprs.get(i); if (projExpr instanceof RexInputRef) { mapInToOutPos.put(((RexInputRef) projExpr).getIndex(), i); } } if (mapInToOutPos.isEmpty()) { // if there's no RexInputRef in the projected expressions // return empty set. return projUniqueKeySet; } Set<ImmutableBitSet> childUniqueKeySet = mq.getUniqueKeys(rel.getInput(), ignoreNulls);
public Set<ImmutableBitSet> getUniqueKeys(Project rel, RelMetadataQuery mq, boolean ignoreNulls) { // LogicalProject maps a set of rows to a different set; // Without knowledge of the mapping function(whether it // preserves uniqueness), it is only safe to derive uniqueness // info from the child of a project when the mapping is f(a) => a. // // Further more, the unique bitset coming from the child needs // to be mapped to match the output of the project. final Map<Integer, Integer> mapInToOutPos = new HashMap<>(); final List<RexNode> projExprs = rel.getProjects(); final Set<ImmutableBitSet> projUniqueKeySet = new HashSet<>(); // Build an input to output position map. for (int i = 0; i < projExprs.size(); i++) { RexNode projExpr = projExprs.get(i); if (projExpr instanceof RexInputRef) { mapInToOutPos.put(((RexInputRef) projExpr).getIndex(), i); } } if (mapInToOutPos.isEmpty()) { // if there's no RexInputRef in the projected expressions // return empty set. return projUniqueKeySet; } Set<ImmutableBitSet> childUniqueKeySet = mq.getUniqueKeys(rel.getInput(), ignoreNulls);
case ANTI: case SEMI: return mq.areColumnsUnique(rel.getLeft(), columns, ignoreNulls); case LEFT: case INNER: final Pair<ImmutableBitSet, ImmutableBitSet> leftAndRightColumns = splitLeftAndRightColumns(rel.getLeft().getRowType().getFieldCount(), columns); final ImmutableBitSet leftColumns = leftAndRightColumns.left; final ImmutableBitSet rightColumns = leftAndRightColumns.right; final RelNode left = rel.getLeft(); final RelNode right = rel.getRight();
case ANTI: case SEMI: return mq.areColumnsUnique(rel.getLeft(), columns, ignoreNulls); case LEFT: case INNER: final Pair<ImmutableBitSet, ImmutableBitSet> leftAndRightColumns = splitLeftAndRightColumns(rel.getLeft().getRowType().getFieldCount(), columns); final ImmutableBitSet leftColumns = leftAndRightColumns.left; final ImmutableBitSet rightColumns = leftAndRightColumns.right; final RelNode left = rel.getLeft(); final RelNode right = rel.getRight();
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { double rowCount = mq.getRowCount(this); final double rightRowCount = right.estimateRowCount(mq); final double leftRowCount = left.estimateRowCount(mq); if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) { return planner.getCostFactory().makeInfiniteCost(); } Double restartCount = mq.getRowCount(getLeft()); // RelMetadataQuery.getCumulativeCost(getRight()); does not work for // RelSubset, so we ask planner to cost-estimate right relation RelOptCost rightCost = planner.getCost(getRight(), mq); RelOptCost rescanCost = rightCost.multiplyBy(Math.max(1.0, restartCount - 1)); return planner.getCostFactory().makeCost( rowCount /* generate results */ + leftRowCount /* scan left results */, 0, 0).plus(rescanCost); } }
@Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { double rowCount = mq.getRowCount(this); final double rightRowCount = right.estimateRowCount(mq); final double leftRowCount = left.estimateRowCount(mq); if (Double.isInfinite(leftRowCount) || Double.isInfinite(rightRowCount)) { return planner.getCostFactory().makeInfiniteCost(); } Double restartCount = mq.getRowCount(getLeft()); // RelMetadataQuery.getCumulativeCost(getRight()); does not work for // RelSubset, so we ask planner to cost-estimate right relation RelOptCost rightCost = planner.getCost(getRight(), mq); RelOptCost rescanCost = rightCost.multiplyBy(Math.max(1.0, restartCount - 1)); return planner.getCostFactory().makeCost( rowCount /* generate results */ + leftRowCount /* scan left results */, 0, 0).plus(rescanCost); } }
LogicalProject project, Set<Integer> isCount) { final RelNode left = correlate.getLeft(); final JoinRelType joinType = correlate.getJoinType().toJoinType();
LogicalProject project, Set<Integer> isCount) { final RelNode left = correlate.getLeft(); final JoinRelType joinType = correlate.getJoinType().toJoinType();
LogicalProject project, Set<Integer> isCount) { final RelNode left = correlate.getLeft(); final JoinRelType joinType = correlate.getJoinType().toJoinType();
Correlate corrRel = (Correlate) childRel; List<RelDataTypeField> leftFields = corrRel.getLeft().getRowType().getFieldList(); List<RelDataTypeField> rightFields = corrRel.getRight().getRowType().getFieldList();
Correlate corrRel = (Correlate) childRel; List<RelDataTypeField> leftFields = corrRel.getLeft().getRowType().getFieldList(); List<RelDataTypeField> rightFields = corrRel.getRight().getRowType().getFieldList();
final RelBuilder relBuilder = call.builder(); final RelNode leftRel = relBuilder.push(corr.getLeft()).filter(leftFilters).build(); final RelNode rightRel = relBuilder.push(corr.getRight()).filter(rightFilters).build();
final RelBuilder relBuilder = call.builder(); final RelNode leftRel = relBuilder.push(corr.getLeft()).filter(leftFilters).build(); final RelNode rightRel = relBuilder.push(corr.getRight()).filter(rightFilters).build();
corr.getLeft(), true, false);
corr.getLeft(), true, false);
final MutableRel left = toMutable(correlate.getLeft()); final MutableRel right = toMutable(correlate.getRight()); return MutableCorrelate.of(correlate.getRowType(), left, right,
final MutableRel left = toMutable(correlate.getLeft()); final MutableRel right = toMutable(correlate.getRight()); return MutableCorrelate.of(correlate.getRowType(), left, right,