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 propagateSelectionRec(Mutable<ILogicalOperator> sigmaRef, Mutable<ILogicalOperator> opRef2) throws AlgebricksException { AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (op2.getInputs().size() != 1 || op2.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN || !OperatorPropertiesUtil.isMovable(op2)) { return false; } SelectOperator sigma = (SelectOperator) sigmaRef.getValue(); LinkedList<LogicalVariable> usedInSigma = new LinkedList<LogicalVariable>(); sigma.getCondition().getValue().getUsedVariables(usedInSigma); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, produced2); if (OperatorPropertiesUtil.disjoint(produced2, usedInSigma)) { // just swap opRef2.setValue(sigma); sigmaRef.setValue(op2); List<Mutable<ILogicalOperator>> sigmaInpList = sigma.getInputs(); sigmaInpList.clear(); sigmaInpList.addAll(op2.getInputs()); List<Mutable<ILogicalOperator>> op2InpList = op2.getInputs(); op2InpList.clear(); op2InpList.add(opRef2); propagateSelectionRec(opRef2, sigma.getInputs().get(0)); return true; } return false; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.SELECT) { return false; } Mutable<ILogicalOperator> opRef2 = op.getInputs().get(0); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); if (context.checkAndAddToAlreadyCompared(op, op2)) { return false; } LogicalOperatorTag tag2 = op2.getOperatorTag(); if (tag2 == LogicalOperatorTag.INNERJOIN || tag2 == LogicalOperatorTag.LEFTOUTERJOIN || tag2 == LogicalOperatorTag.REPLICATE || tag2 == LogicalOperatorTag.SPLIT) { return false; } else { // not a join boolean res = propagateSelectionRec(opRef, opRef2); if (res) { OperatorPropertiesUtil.typeOpRec(opRef, context); } return res; } }
public final static List<IAlgebraicRewriteRule> buildCondPushDownRuleCollection() { List<IAlgebraicRewriteRule> condPushDown = new LinkedList<IAlgebraicRewriteRule>(); condPushDown.add(new PushSelectDownRule()); condPushDown.add(new InlineVariablesRule()); condPushDown.add(new FactorRedundantGroupAndDecorVarsRule()); condPushDown.add(new EliminateSubplanRule()); return condPushDown; }
/** * When a nested data sources exist, convert the plan to use the join operator. * * @return List of algebraic rewrite rules. */ public final static List<IAlgebraicRewriteRule> buildNestedDataSourceRuleCollection() { List<IAlgebraicRewriteRule> xquery = new LinkedList<IAlgebraicRewriteRule>(); xquery.add(new BreakSelectIntoConjunctsRule()); xquery.add(new SimpleUnnestToProductRule()); xquery.add(new PushMapOperatorDownThroughProductRule()); xquery.add(new PushSubplanWithAggregateDownThroughProductRule()); xquery.add(new PushSelectDownRule()); xquery.add(new PushSelectIntoJoinRule()); // Clean up xquery.add(new RemoveRedundantVariablesRule()); xquery.add(new RemoveUnusedAssignAndAggregateRule()); return xquery; }
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; }
/** * Unnest more complex structures. * * @return List of algebraic rewrite rules. */ public final static List<IAlgebraicRewriteRule> buildUnnestingRuleCollection() { List<IAlgebraicRewriteRule> xquery = new LinkedList<IAlgebraicRewriteRule>(); xquery.add(new PushSelectDownRule()); xquery.add(new SimpleUnnestToProductRule()); xquery.add(new ComplexUnnestToProductRule()); xquery.add(new ComplexJoinInferenceRule()); xquery.add(new PushSelectIntoJoinRule()); xquery.add(new IntroJoinInsideSubplanRule()); xquery.add(new PushMapOperatorDownThroughProductRule()); xquery.add(new PushSubplanWithAggregateDownThroughProductRule()); xquery.add(new IntroduceGroupByForSubplanRule()); xquery.add(new SubplanOutOfGroupRule()); xquery.add(new InsertOuterJoinRule()); xquery.add(new ExtractFunctionsFromJoinConditionRule()); xquery.add(new RemoveRedundantVariablesRule()); xquery.add(new RemoveUnusedAssignAndAggregateRule()); xquery.add(new FactorRedundantGroupAndDecorVarsRule()); xquery.add(new EliminateSubplanRule()); xquery.add(new EliminateGroupByEmptyKeyRule()); xquery.add(new PushSubplanIntoGroupByRule()); xquery.add(new NestedSubplanToJoinRule()); xquery.add(new EliminateSubplanWithInputCardinalityOneRule()); return xquery; }
public static final List<IAlgebraicRewriteRule> buildCondPushDownAndJoinInferenceRuleCollection() { List<IAlgebraicRewriteRule> condPushDownAndJoinInference = new LinkedList<>(); condPushDownAndJoinInference.add(new PushSelectDownRule()); condPushDownAndJoinInference.add(new PushSortDownRule()); condPushDownAndJoinInference.add(new RemoveRedundantListifyRule());