public final static List<IAlgebraicRewriteRule> buildConsolidationRuleCollection() { List<IAlgebraicRewriteRule> consolidation = new LinkedList<IAlgebraicRewriteRule>(); consolidation.add(new ConsolidateSelectsRule()); consolidation.add(new ConsolidateAssignsRule()); consolidation.add(new InlineAssignIntoAggregateRule()); consolidation.add(new IntroduceGroupByCombinerRule()); consolidation.add(new IntroduceAggregateCombinerRule()); consolidation.add(new RemoveUnusedAssignAndAggregateRule()); return consolidation; }
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; } clear(); Set<LogicalVariable> accumulatedUsedVarFromRootSet = new HashSet<>(); collectUnusedAssignedVars(opRef, accumulatedUsedVarFromRootSet, true, context); // If there are ASSIGN, UNNEST, AGGREGATE, UNION, and GROUP operators in the plan, // we try to remove these operators if the produced variables from these // operators are not used. if (!assignedVarMap.isEmpty()) { removeUnusedAssigns(opRef, context); } return isTransformed; }
Set<LogicalVariable> assignVarsSetForThisOp = removeAssignVarFromConsideration(opRef); while (removeFromAssigns(op, assignVarsSetForThisOp, context) == 0) { assignVarsSetForThisOp = removeAssignVarFromConsideration(opRef); isTransformed = true; while (childIter.hasNext()) { Mutable<ILogicalOperator> cRef = childIter.next(); removeUnusedAssigns(cRef, context); ILogicalPlan p = planIter.next(); for (Mutable<ILogicalOperator> r : p.getRoots()) { removeUnusedAssigns(r, context);
case ASSIGN: AssignOperator assign = (AssignOperator) op; if (removeUnusedVarsAndExprs(toRemove, assign.getVariables(), assign.getExpressions())) { context.computeAndSetTypeEnvironmentForOperator(assign); isTransformed = true; case AGGREGATE: AggregateOperator agg = (AggregateOperator) op; if (removeUnusedVarsAndExprs(toRemove, agg.getVariables(), agg.getExpressions())) { context.computeAndSetTypeEnvironmentForOperator(agg); isTransformed = true; case UNIONALL: UnionAllOperator unionOp = (UnionAllOperator) op; if (removeUnusedVarsFromUnionAll(unionOp, toRemove)) { context.computeAndSetTypeEnvironmentForOperator(unionOp); isTransformed = true; case GROUP: GroupByOperator groupByOp = (GroupByOperator) op; if (removeUnusedVarsFromGroupBy(groupByOp, toRemove)) { context.computeAndSetTypeEnvironmentForOperator(groupByOp); isTransformed = true; case WINDOW: WindowOperator winOp = (WindowOperator) op; if (removeUnusedVarsAndExprs(toRemove, winOp.getVariables(), winOp.getExpressions())) { context.computeAndSetTypeEnvironmentForOperator(winOp); isTransformed = true;
collectUnusedAssignedVars(c, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet), false, context); for (ILogicalPlan plan : opWithNested.getNestedPlans()) { for (Mutable<ILogicalOperator> r : plan.getRoots()) { collectUnusedAssignedVars(r, new HashSet<LogicalVariable>(accumulatedUsedVarFromRootSet), false, context);
/** * Optimizations specific to XQuery. * * @return List of algebraic rewrite rules. */ public final static List<IAlgebraicRewriteRule> buildXQueryNormalizationRuleCollection() { List<IAlgebraicRewriteRule> normalization = new LinkedList<IAlgebraicRewriteRule>(); // Find assign for scalar aggregate function followed by an aggregate operator. normalization.add(new ConsolidateAssignAggregateRule()); normalization.add(new RemoveRedundantVariablesRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); // Find assign for scalar aggregate function. // normalization.add(new ConvertAssignToAggregateRule()); // Use two step aggregate operators if possible. normalization.add(new IntroduceTwoStepAggregateRule()); // Used to clean up any missing noops after all the subplans have been altered. normalization.add(new RemoveRedundantVariablesRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); return normalization; }
public static final List<IAlgebraicRewriteRule> buildFuzzyJoinRuleCollection() { List<IAlgebraicRewriteRule> fuzzy = new LinkedList<>(); fuzzy.add(new FuzzyJoinRule()); fuzzy.add(new ExtractCommonExpressionsRule()); fuzzy.add(new NestedSubplanToJoinRule()); fuzzy.add(new PushSelectIntoJoinRule()); fuzzy.add(new RemoveUnusedAssignAndAggregateRule()); fuzzy.add(new InlineSubplanInputForNestedTupleSourceRule()); fuzzy.add(new RemoveRedundantVariablesRule()); fuzzy.add(new AsterixInlineVariablesRule()); fuzzy.add(new RemoveUnusedAssignAndAggregateRule()); return fuzzy; }
public static final List<IAlgebraicRewriteRule> buildAccessMethodRuleCollection() { List<IAlgebraicRewriteRule> accessMethod = new LinkedList<>(); accessMethod.add(new IntroduceSelectAccessMethodRule()); accessMethod.add(new IntroduceJoinAccessMethodRule()); accessMethod.add(new IntroduceLSMComponentFilterRule()); accessMethod.add(new IntroducePrimaryIndexForAggregationRule()); accessMethod.add(new IntroduceSecondaryIndexInsertDeleteRule()); accessMethod.add(new RemoveUnusedOneToOneEquiJoinRule()); accessMethod.add(new PushSimilarityFunctionsBelowJoin()); accessMethod.add(new RemoveUnusedAssignAndAggregateRule()); return accessMethod; }
/** * 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; }
/** * Remove expressions known to be redundant. * * @return List of algebraic rewrite rules. */ public final static List<IAlgebraicRewriteRule> buildInlineRedundantExpressionNormalizationRuleCollection() { List<IAlgebraicRewriteRule> normalization = new LinkedList<IAlgebraicRewriteRule>(); normalization.add(new InlineNestedVariablesRule()); normalization.add(new RemoveRedundantTreatExpressionsRule()); normalization.add(new RemoveRedundantDataExpressionsRule()); normalization.add(new RemoveRedundantPromoteExpressionsRule()); normalization.add(new RemoveRedundantCastExpressionsRule()); normalization.add(new ConvertToAlgebricksExpressionsRule()); normalization.add(new RemoveRedundantBooleanExpressionsRule()); // Clean up normalization.add(new RemoveRedundantVariablesRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); return normalization; }
public static final List<IAlgebraicRewriteRule> buildLoadFieldsRuleCollection(ICcApplicationContext appCtx) { List<IAlgebraicRewriteRule> fieldLoads = new LinkedList<>(); fieldLoads.add(new LoadRecordFieldsRule()); fieldLoads.add(new PushFieldAccessRule()); // fieldLoads.add(new ByNameToByHandleFieldAccessRule()); -- disabled fieldLoads.add(new ReinferAllTypesRule()); fieldLoads.add(new ByNameToByIndexFieldAccessRule()); fieldLoads.add(new RemoveRedundantVariablesRule()); fieldLoads.add(new AsterixInlineVariablesRule()); fieldLoads.add(new RemoveUnusedAssignAndAggregateRule()); fieldLoads.add(new ConstantFoldingRule(appCtx)); fieldLoads.add(new RemoveRedundantSelectRule()); fieldLoads.add(new FeedScanCollectionToUnnest()); fieldLoads.add(new NestedSubplanToJoinRule()); fieldLoads.add(new InlineSubplanInputForNestedTupleSourceRule()); fieldLoads.add(new RemoveLeftOuterUnnestForLeftOuterJoinRule()); return fieldLoads; }
public static final List<IAlgebraicRewriteRule> buildPhysicalRewritesTopLevelRuleCollection( ICcApplicationContext appCtx) { List<IAlgebraicRewriteRule> physicalRewritesTopLevel = new LinkedList<>(); physicalRewritesTopLevel.add(new PushNestedOrderByUnderPreSortedGroupByRule()); physicalRewritesTopLevel.add(new CopyLimitDownRule()); // CopyLimitDownRule may generates non-topmost limits with numeric_adds functions. // We are going to apply a constant folding rule again for this case. physicalRewritesTopLevel.add(new ConstantFoldingRule(appCtx)); physicalRewritesTopLevel.add(new PushLimitIntoOrderByRule()); physicalRewritesTopLevel.add(new PushLimitIntoPrimarySearchRule()); // remove assigns that could become unused after PushLimitIntoPrimarySearchRule physicalRewritesTopLevel.add(new RemoveUnusedAssignAndAggregateRule()); physicalRewritesTopLevel.add(new IntroduceProjectsRule()); physicalRewritesTopLevel.add(new SetAlgebricksPhysicalOperatorsRule()); physicalRewritesTopLevel.add(new IntroduceRapidFrameFlushProjectAssignRule()); physicalRewritesTopLevel.add(new SetExecutionModeRule()); physicalRewritesTopLevel.add(new IntroduceRandomPartitioningFeedComputationRule()); return physicalRewritesTopLevel; }
public static final List<IAlgebraicRewriteRule> buildConsolidationRuleCollection() { List<IAlgebraicRewriteRule> consolidation = new LinkedList<>(); consolidation.add(new ConsolidateSelectsRule()); consolidation.add(new ConsolidateAssignsRule()); consolidation.add(new InlineAssignIntoAggregateRule()); consolidation.add(new AsterixIntroduceGroupByCombinerRule()); consolidation.add(new IntroduceAggregateCombinerRule()); consolidation.add(new CountVarToCountOneRule()); consolidation.add(new RemoveUnusedAssignAndAggregateRule()); consolidation.add(new RemoveRedundantGroupByDecorVarsRule()); //PushUnnestDownUnion => RemoveRedundantListifyRule cause these rules are correlated consolidation.add(new PushUnnestDownThroughUnionRule()); consolidation.add(new RemoveRedundantListifyRule()); // Window operator consolidation rules consolidation.add(new ConsolidateWindowOperatorsRule()); consolidation.add(new ReuseWindowAggregateRule()); consolidation.add(new RemoveRedundantWindowOperatorsRule()); consolidation.add(new RemoveRedundantVariablesRule()); return consolidation; }
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; }
/** * 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; }
normalization.add(new RemoveRedundantBooleanExpressionsRule()); normalization.add(new RemoveRedundantVariablesRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule()); normalization.add(new RemoveUnusedAssignAndAggregateRule());
condPushDownAndJoinInference.add(new RemoveUnusedAssignAndAggregateRule());