public final static List<IAlgebraicRewriteRule> buildOpPushDownRuleCollection() { List<IAlgebraicRewriteRule> opPushDown = new LinkedList<IAlgebraicRewriteRule>(); opPushDown.add(new PushProjectDownRule()); opPushDown.add(new PushSelectDownRule()); return opPushDown; }
private static boolean pushNeededProjections(Set<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef, IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException { Set<LogicalVariable> allP = new LinkedHashSet<LogicalVariable>(); AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); VariableUtilities.getSubplanLocalLiveVariables(op, allP); Set<LogicalVariable> toProject = new LinkedHashSet<LogicalVariable>(); for (LogicalVariable v : toPush) { if (allP.contains(v)) { toProject.add(v); } } if (toProject.equals(allP)) { // projection would be redundant, since we would project everything // but we can try with the children boolean push = false; if (pushThroughOp(toProject, opRef, initialOp, context).first) { push = true; } return push; } else { return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp); } }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.PROJECT) { return false; } ProjectOperator pi = (ProjectOperator) op; Mutable<ILogicalOperator> opRef2 = pi.getInputs().get(0); Set<LogicalVariable> toPush = new LinkedHashSet<LogicalVariable>(); toPush.addAll(pi.getVariables()); Pair<Boolean, Boolean> p = pushThroughOp(toPush, opRef2, op, context); boolean smthWasPushed = p.first; if (p.second) { // the original projection is redundant opRef.setValue(op.getInputs().get(0).getValue()); smthWasPushed = true; } return smthWasPushed; }
if (pushNeededProjections(toPush, c, context, initialOp)) { smthWasPushed = true; for (ILogicalPlan p : n.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { if (pushNeededProjections(toPush, r, context, initialOp)) { smthWasPushed = true;
public final static List<IAlgebraicRewriteRule> buildPhysicalRewritesAllLevelsRuleCollection() { List<IAlgebraicRewriteRule> physicalPlanRewrites = new LinkedList<IAlgebraicRewriteRule>(); physicalPlanRewrites.add(new PullSelectOutOfEqJoin()); physicalPlanRewrites.add(new PushFunctionsOntoEqJoinBranches()); physicalPlanRewrites.add(new SetAlgebricksPhysicalOperatorsRule()); physicalPlanRewrites.add(new SetExecutionModeRule()); physicalPlanRewrites.add(new EnforceStructuralPropertiesRule()); physicalPlanRewrites.add(new PushProjectDownRule()); physicalPlanRewrites.add(new CopyLimitDownRule()); return physicalPlanRewrites; }
public static final List<IAlgebraicRewriteRule> buildPlanCleanupRuleCollection() { List<IAlgebraicRewriteRule> planCleanupRules = new LinkedList<>(); planCleanupRules.add(new SwitchInnerJoinBranchRule()); planCleanupRules.add(new PushAssignBelowUnionAllRule()); planCleanupRules.add(new ExtractCommonExpressionsRule()); planCleanupRules.add(new RemoveRedundantVariablesRule()); planCleanupRules.add(new PushProjectDownRule()); planCleanupRules.add(new PushSelectDownRule()); planCleanupRules.add(new SetClosedRecordConstructorsRule()); planCleanupRules.add(new IntroduceDynamicTypeCastRule()); planCleanupRules.add(new IntroduceDynamicTypeCastForExternalFunctionRule()); planCleanupRules.add(new RemoveUnusedAssignAndAggregateRule()); planCleanupRules.add(new RemoveCartesianProductWithEmptyBranchRule()); planCleanupRules.add(new InjectTypeCastForFunctionArgumentsRule()); planCleanupRules.add(new InjectTypeCastForUnionRule()); // Needs to invoke ByNameToByIndexFieldAccessRule as the last logical optimization rule because // some rules can push a FieldAccessByName to a place where the name it tries to access is in the closed part. // For example, a possible scenario is that a field-access-by-name can be pushed down through UnionAllOperator. planCleanupRules.add(new ByNameToByIndexFieldAccessRule()); return planCleanupRules; }
public static final List<IAlgebraicRewriteRule> buildPhysicalRewritesAllLevelsRuleCollection() { List<IAlgebraicRewriteRule> physicalRewritesAllLevels = new LinkedList<>(); physicalRewritesAllLevels.add(new PullSelectOutOfEqJoin()); //Turned off the following rule for now not to change OptimizerTest results. physicalRewritesAllLevels.add(new SetupCommitExtensionOpRule()); physicalRewritesAllLevels.add(new SetAlgebricksPhysicalOperatorsRule()); physicalRewritesAllLevels.add(new SetAsterixPhysicalOperatorsRule()); physicalRewritesAllLevels.add(new AddEquivalenceClassForRecordConstructorRule()); physicalRewritesAllLevels.add(new CheckFullParallelSortRule()); physicalRewritesAllLevels .add(new EnforceStructuralPropertiesRule(BuiltinFunctions.RANGE_MAP, BuiltinFunctions.LOCAL_SAMPLING)); physicalRewritesAllLevels.add(new RemoveSortInFeedIngestionRule()); physicalRewritesAllLevels.add(new RemoveUnnecessarySortMergeExchange()); physicalRewritesAllLevels.add(new PushProjectDownRule()); physicalRewritesAllLevels.add(new IntroduceMaterializationForInsertWithSelfScanRule()); physicalRewritesAllLevels.add(new InlineSingleReferenceVariablesRule()); physicalRewritesAllLevels.add(new RemoveUnusedAssignAndAggregateRule()); physicalRewritesAllLevels.add(new ConsolidateAssignsRule()); // After adding projects, we may need need to set physical operators again. physicalRewritesAllLevels.add(new SetAlgebricksPhysicalOperatorsRule()); return physicalRewritesAllLevels; }