org.apache.calcite.rel.rules.JoinCommuteRule Java Examples
The following examples show how to use
org.apache.calcite.rel.rules.JoinCommuteRule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VolcanoPlanner.java From Bats with Apache License 2.0 | 6 votes |
public void registerAbstractRelationalRules() { addRule(FilterJoinRule.FILTER_ON_JOIN); addRule(FilterJoinRule.JOIN); addRule(AbstractConverter.ExpandConversionRule.INSTANCE); addRule(JoinCommuteRule.INSTANCE); addRule(SemiJoinRule.PROJECT); addRule(SemiJoinRule.JOIN); if (CalciteSystemProperty.COMMUTE.value()) { addRule(JoinAssociateRule.INSTANCE); } addRule(AggregateRemoveRule.INSTANCE); addRule(UnionToDistinctRule.INSTANCE); addRule(ProjectRemoveRule.INSTANCE); addRule(AggregateJoinTransposeRule.INSTANCE); addRule(AggregateProjectMergeRule.INSTANCE); addRule(CalcRemoveRule.INSTANCE); addRule(SortRemoveRule.INSTANCE); // todo: rule which makes Project({OrdinalRef}) disappear }
Example #2
Source File: Programs.java From Bats with Apache License 2.0 | 5 votes |
/** Creates a program that invokes heuristic join-order optimization * (via {@link org.apache.calcite.rel.rules.JoinToMultiJoinRule}, * {@link org.apache.calcite.rel.rules.MultiJoin} and * {@link org.apache.calcite.rel.rules.LoptOptimizeJoinRule}) * if there are 6 or more joins (7 or more relations). */ public static Program heuristicJoinOrder( final Iterable<? extends RelOptRule> rules, final boolean bushy, final int minJoinCount) { return (planner, rel, requiredOutputTraits, materializations, lattices) -> { final int joinCount = RelOptUtil.countJoins(rel); final Program program; if (joinCount < minJoinCount) { program = ofRules(rules); } else { // Create a program that gathers together joins as a MultiJoin. final HepProgram hep = new HepProgramBuilder() .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN) .addMatchOrder(HepMatchOrder.BOTTOM_UP) .addRuleInstance(JoinToMultiJoinRule.INSTANCE) .build(); final Program program1 = of(hep, false, DefaultRelMetadataProvider.INSTANCE); // Create a program that contains a rule to expand a MultiJoin // into heuristically ordered joins. // We use the rule set passed in, but remove JoinCommuteRule and // JoinPushThroughJoinRule, because they cause exhaustive search. final List<RelOptRule> list = Lists.newArrayList(rules); list.removeAll( ImmutableList.of(JoinCommuteRule.INSTANCE, JoinAssociateRule.INSTANCE, JoinPushThroughJoinRule.LEFT, JoinPushThroughJoinRule.RIGHT)); list.add(bushy ? MultiJoinOptimizeBushyRule.INSTANCE : LoptOptimizeJoinRule.INSTANCE); final Program program2 = ofRules(list); program = sequence(program1, program2); } return program.run( planner, rel, requiredOutputTraits, materializations, lattices); }; }
Example #3
Source File: Programs.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a program that invokes heuristic join-order optimization * (via {@link org.apache.calcite.rel.rules.JoinToMultiJoinRule}, * {@link org.apache.calcite.rel.rules.MultiJoin} and * {@link org.apache.calcite.rel.rules.LoptOptimizeJoinRule}) * if there are 6 or more joins (7 or more relations). */ public static Program heuristicJoinOrder( final Iterable<? extends RelOptRule> rules, final boolean bushy, final int minJoinCount) { return (planner, rel, requiredOutputTraits, materializations, lattices) -> { final int joinCount = RelOptUtil.countJoins(rel); final Program program; if (joinCount < minJoinCount) { program = ofRules(rules); } else { // Create a program that gathers together joins as a MultiJoin. final HepProgram hep = new HepProgramBuilder() .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN) .addMatchOrder(HepMatchOrder.BOTTOM_UP) .addRuleInstance(JoinToMultiJoinRule.INSTANCE) .build(); final Program program1 = of(hep, false, DefaultRelMetadataProvider.INSTANCE); // Create a program that contains a rule to expand a MultiJoin // into heuristically ordered joins. // We use the rule set passed in, but remove JoinCommuteRule and // JoinPushThroughJoinRule, because they cause exhaustive search. final List<RelOptRule> list = Lists.newArrayList(rules); list.removeAll( ImmutableList.of(JoinCommuteRule.INSTANCE, JoinAssociateRule.INSTANCE, JoinPushThroughJoinRule.LEFT, JoinPushThroughJoinRule.RIGHT)); list.add(bushy ? MultiJoinOptimizeBushyRule.INSTANCE : LoptOptimizeJoinRule.INSTANCE); final Program program2 = ofRules(list); program = sequence(program1, program2); } return program.run( planner, rel, requiredOutputTraits, materializations, lattices); }; }
Example #4
Source File: TopDownOptTest.java From calcite with Apache License 2.0 | 5 votes |
private Query(String sql) { this.sql = sql; planner = new VolcanoPlanner(); // Always use top-down optimization planner.setTopDownOpt(true); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(RelCollationTraitDef.INSTANCE); RelOptUtil.registerDefaultRules(planner, false, false); // Remove to Keep deterministic join order. planner.removeRule(JoinCommuteRule.INSTANCE); planner.removeRule(JoinPushThroughJoinRule.LEFT); planner.removeRule(JoinPushThroughJoinRule.RIGHT); // Always use sorted agg. planner.addRule(EnumerableRules.ENUMERABLE_SORTED_AGGREGATE_RULE); planner.removeRule(EnumerableRules.ENUMERABLE_AGGREGATE_RULE); // pushing down sort should be handled by top-down optimization. planner.removeRule(SortProjectTransposeRule.INSTANCE); // Sort will only be pushed down by traits propagation. planner.removeRule(SortJoinTransposeRule.INSTANCE); planner.removeRule(SortJoinCopyRule.INSTANCE); }
Example #5
Source File: OLAPTableScan.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public void register(RelOptPlanner planner) { // force clear the query context before traversal relational operators OLAPContext.clearThreadLocalContexts(); // register OLAP rules addRules(planner, kylinConfig.getCalciteAddRule()); planner.addRule(OLAPToEnumerableConverterRule.INSTANCE); planner.addRule(OLAPFilterRule.INSTANCE); planner.addRule(OLAPProjectRule.INSTANCE); planner.addRule(OLAPAggregateRule.INSTANCE); planner.addRule(OLAPJoinRule.INSTANCE); planner.addRule(OLAPLimitRule.INSTANCE); planner.addRule(OLAPSortRule.INSTANCE); planner.addRule(OLAPUnionRule.INSTANCE); planner.addRule(OLAPWindowRule.INSTANCE); planner.addRule(OLAPValuesRule.INSTANCE); planner.addRule(AggregateProjectReduceRule.INSTANCE); // CalcitePrepareImpl.CONSTANT_REDUCTION_RULES if (kylinConfig.isReduceExpressionsRulesEnabled()) { planner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE); planner.addRule(ReduceExpressionsRule.FILTER_INSTANCE); planner.addRule(ReduceExpressionsRule.CALC_INSTANCE); planner.addRule(ReduceExpressionsRule.JOIN_INSTANCE); } // the ValuesReduceRule breaks query test somehow... // planner.addRule(ValuesReduceRule.FILTER_INSTANCE); // planner.addRule(ValuesReduceRule.PROJECT_FILTER_INSTANCE); // planner.addRule(ValuesReduceRule.PROJECT_INSTANCE); removeRules(planner, kylinConfig.getCalciteRemoveRule()); if (!kylinConfig.isEnumerableRulesEnabled()) { for (RelOptRule rule : CalcitePrepareImpl.ENUMERABLE_RULES) { planner.removeRule(rule); } } // since join is the entry point, we can't push filter past join planner.removeRule(FilterJoinRule.FILTER_ON_JOIN); planner.removeRule(FilterJoinRule.JOIN); // since we don't have statistic of table, the optimization of join is too cost planner.removeRule(JoinCommuteRule.INSTANCE); planner.removeRule(JoinPushThroughJoinRule.LEFT); planner.removeRule(JoinPushThroughJoinRule.RIGHT); // keep tree structure like filter -> aggregation -> project -> join/table scan, implementOLAP() rely on this tree pattern planner.removeRule(AggregateJoinTransposeRule.INSTANCE); planner.removeRule(AggregateProjectMergeRule.INSTANCE); planner.removeRule(FilterProjectTransposeRule.INSTANCE); planner.removeRule(SortJoinTransposeRule.INSTANCE); planner.removeRule(JoinPushExpressionsRule.INSTANCE); planner.removeRule(SortUnionTransposeRule.INSTANCE); planner.removeRule(JoinUnionTransposeRule.LEFT_UNION); planner.removeRule(JoinUnionTransposeRule.RIGHT_UNION); planner.removeRule(AggregateUnionTransposeRule.INSTANCE); planner.removeRule(DateRangeRules.FILTER_INSTANCE); planner.removeRule(SemiJoinRule.JOIN); planner.removeRule(SemiJoinRule.PROJECT); // distinct count will be split into a separated query that is joined with the left query planner.removeRule(AggregateExpandDistinctAggregatesRule.INSTANCE); // see Dec 26th email @ http://mail-archives.apache.org/mod_mbox/calcite-dev/201412.mbox/browser planner.removeRule(ExpandConversionRule.INSTANCE); }
Example #6
Source File: OLAPTableScan.java From kylin with Apache License 2.0 | 4 votes |
@Override public void register(RelOptPlanner planner) { // force clear the query context before traversal relational operators OLAPContext.clearThreadLocalContexts(); // register OLAP rules addRules(planner, kylinConfig.getCalciteAddRule()); planner.addRule(OLAPToEnumerableConverterRule.INSTANCE); planner.addRule(OLAPFilterRule.INSTANCE); planner.addRule(OLAPProjectRule.INSTANCE); planner.addRule(OLAPAggregateRule.INSTANCE); planner.addRule(OLAPJoinRule.INSTANCE); planner.addRule(OLAPLimitRule.INSTANCE); planner.addRule(OLAPSortRule.INSTANCE); planner.addRule(OLAPUnionRule.INSTANCE); planner.addRule(OLAPWindowRule.INSTANCE); planner.addRule(OLAPValuesRule.INSTANCE); planner.addRule(AggregateProjectReduceRule.INSTANCE); // CalcitePrepareImpl.CONSTANT_REDUCTION_RULES if (kylinConfig.isReduceExpressionsRulesEnabled()) { planner.addRule(ReduceExpressionsRule.PROJECT_INSTANCE); planner.addRule(ReduceExpressionsRule.FILTER_INSTANCE); planner.addRule(ReduceExpressionsRule.CALC_INSTANCE); planner.addRule(ReduceExpressionsRule.JOIN_INSTANCE); } // the ValuesReduceRule breaks query test somehow... // planner.addRule(ValuesReduceRule.FILTER_INSTANCE); // planner.addRule(ValuesReduceRule.PROJECT_FILTER_INSTANCE); // planner.addRule(ValuesReduceRule.PROJECT_INSTANCE); removeRules(planner, kylinConfig.getCalciteRemoveRule()); if (!kylinConfig.isEnumerableRulesEnabled()) { for (RelOptRule rule : CalcitePrepareImpl.ENUMERABLE_RULES) { planner.removeRule(rule); } } // since join is the entry point, we can't push filter past join planner.removeRule(FilterJoinRule.FILTER_ON_JOIN); planner.removeRule(FilterJoinRule.JOIN); // since we don't have statistic of table, the optimization of join is too cost planner.removeRule(JoinCommuteRule.INSTANCE); planner.removeRule(JoinPushThroughJoinRule.LEFT); planner.removeRule(JoinPushThroughJoinRule.RIGHT); // keep tree structure like filter -> aggregation -> project -> join/table scan, implementOLAP() rely on this tree pattern planner.removeRule(AggregateJoinTransposeRule.INSTANCE); planner.removeRule(AggregateProjectMergeRule.INSTANCE); planner.removeRule(FilterProjectTransposeRule.INSTANCE); planner.removeRule(SortJoinTransposeRule.INSTANCE); planner.removeRule(JoinPushExpressionsRule.INSTANCE); planner.removeRule(SortUnionTransposeRule.INSTANCE); planner.removeRule(JoinUnionTransposeRule.LEFT_UNION); planner.removeRule(JoinUnionTransposeRule.RIGHT_UNION); planner.removeRule(AggregateUnionTransposeRule.INSTANCE); planner.removeRule(DateRangeRules.FILTER_INSTANCE); planner.removeRule(SemiJoinRule.JOIN); planner.removeRule(SemiJoinRule.PROJECT); // distinct count will be split into a separated query that is joined with the left query planner.removeRule(AggregateExpandDistinctAggregatesRule.INSTANCE); // see Dec 26th email @ http://mail-archives.apache.org/mod_mbox/calcite-dev/201412.mbox/browser planner.removeRule(ExpandConversionRule.INSTANCE); // KYLIN-4464 do not pushdown sort when there is a window function in projection planner.removeRule(SortProjectTransposeRule.INSTANCE); planner.addRule(KylinSortProjectTransposeRule.INSTANCE); }