alex-plekhanov commented on a change in pull request #9282:
URL: https://github.com/apache/ignite/pull/9282#discussion_r679147830



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/PlannerPhase.java
##########
@@ -70,13 +70,70 @@
  */
 public enum PlannerPhase {
     /** */
-    HEURISTIC_OPTIMIZATION("Heuristic optimization phase") {
+    HEP_DECORRELATE("Heuristic phase to decorrelate subqueries") {
         /** {@inheritDoc} */
         @Override public RuleSet getRules(PlanningContext ctx) {
             return RuleSets.ofList(
                 CoreRules.FILTER_SUB_QUERY_TO_CORRELATE,
                 CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE,
-                CoreRules.JOIN_SUB_QUERY_TO_CORRELATE);
+                CoreRules.JOIN_SUB_QUERY_TO_CORRELATE
+            );
+        }
+
+        /** {@inheritDoc} */
+        @Override public Program getProgram(PlanningContext ctx) {
+            return hep(getRules(ctx));
+        }
+    },
+
+    /** */
+    HEP_FILTER_PUSH_DOWN("Heuristic phase to push down filters") {
+        /** {@inheritDoc} */
+        @Override public RuleSet getRules(PlanningContext ctx) {
+            return RuleSets.ofList(
+                CoreRules.FILTER_MERGE,
+                CoreRules.FILTER_AGGREGATE_TRANSPOSE,
+                CoreRules.FILTER_SET_OP_TRANSPOSE,
+                CoreRules.JOIN_CONDITION_PUSH,
+
+                FilterIntoJoinRule.Config.DEFAULT
+                    .withOperandSupplier(b0 ->
+                        b0.operand(LogicalFilter.class).oneInput(b1 ->
+                            
b1.operand(LogicalJoin.class).anyInputs())).toRule(),
+
+                FilterProjectTransposeRule.Config.DEFAULT
+                        .withOperandFor(LogicalFilter.class, f -> true, 
LogicalProject.class, p -> true).toRule()
+            );
+        }
+
+        /** {@inheritDoc} */
+        @Override public Program getProgram(PlanningContext ctx) {
+            return hep(getRules(ctx));
+        }
+    },
+
+    /** */
+    HEP_PROJECT_PUSH_DOWN("Heuristic phase to push down and merge projects") {
+        /** {@inheritDoc} */
+        @Override public RuleSet getRules(PlanningContext ctx) {
+            return RuleSets.ofList(
+                ProjectScanMergeRule.TABLE_SCAN_SKIP_CORRELATED,
+                ProjectScanMergeRule.INDEX_SCAN_SKIP_CORRELATED,
+
+                CoreRules.JOIN_PUSH_EXPRESSIONS,
+
+                ProjectFilterTransposeRule.Config.DEFAULT
+                    .withOperandFor(LogicalProject.class, 
LogicalFilter.class).toRule(),
+
+                ProjectMergeRule.Config.DEFAULT
+                    .withOperandFor(LogicalProject.class).toRule(),
+
+                ProjectRemoveRule.Config.DEFAULT
+                    .withOperandSupplier(b ->
+                        b.operand(LogicalProject.class)
+                            .predicate(ProjectRemoveRule::isTrivial)
+                            .anyInputs()).toRule()

Review comment:
       Why can't we use `CoreRules` instances for these rules? It looks like 
`CoreRules` instances have the same configuration as here. For some rules 
extended operand is used in core rules, for example, `Project` instead of 
`LogicalProject`, but as far as I understand `LogicalProject` is the only type 
of `Project` available on this phase. The same for `HEP_FILTER_PUSH_DOWN`.

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteTableImpl.java
##########
@@ -107,21 +108,32 @@ public IgniteTableImpl(GridKernalContext ctx, 
TableDescriptor desc) {
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteLogicalTableScan toRel(RelOptCluster cluster, 
RelOptTable relOptTbl) {
-        RelTraitSet traitSet = cluster.traitSetOf(distribution())
-            .replace(RewindabilityTrait.REWINDABLE);
-
-        return IgniteLogicalTableScan.create(cluster, traitSet, relOptTbl, 
null, null, null);
+    @Override public boolean rewindable() {
+        return true;
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteLogicalIndexScan toRel(RelOptCluster cluster, 
RelOptTable relOptTbl, String idxName) {
-        RelTraitSet traitSet = cluster.traitSetOf(Convention.Impl.NONE)
-            .replace(distribution())
-            .replace(RewindabilityTrait.REWINDABLE)
-            .replace(getIndex(idxName).collation());
+    @Override public IgniteLogicalTableScan toRel(
+        RelOptCluster cluster,
+        RelOptTable relOptTbl,
+        @Nullable List<RexNode> proj,
+        @Nullable RexNode cond,
+        @Nullable ImmutableBitSet requiredColumns
+    ) {
+        return IgniteLogicalTableScan.create(cluster, cluster.traitSet(), 
relOptTbl, proj, cond, requiredColumns);
+    }
 
-        return IgniteLogicalIndexScan.create(cluster, traitSet, relOptTbl, 
idxName, null, null, null);
+    /** {@inheritDoc} */
+    @Override public IgniteLogicalIndexScan toRel(
+        RelOptCluster cluster,
+        RelOptTable relOptTbl,
+        String idxName,
+        @Nullable List<RexNode> proj,
+        @Nullable RexNode cond,
+        @Nullable ImmutableBitSet requiredColumns
+    ) {
+

Review comment:
       Redundant NL

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rule/logical/ExposeIndexRule.java
##########
@@ -51,8 +53,7 @@ public ExposeIndexRule(Config config) {
 
     /** */
     private static boolean preMatch(IgniteLogicalTableScan scan) {
-        return scan.simple() // was not modified by ProjectScanMergeRule or 
FilterScanMergeRule

Review comment:
       It was the only usage of the `simple()` method, perhaps this method 
should be removed too. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to