You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/09/03 00:16:07 UTC
[19/50] incubator-calcite git commit: [CALCITE-791] Optimize
RelOptUtil.pushFilterPastProject
[CALCITE-791] Optimize RelOptUtil.pushFilterPastProject
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/c9fe32b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/c9fe32b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/c9fe32b7
Branch: refs/heads/branch-release
Commit: c9fe32b7d693cff7dc337335029fe94d3a4d5c53
Parents: 9177063
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Jul 20 23:45:41 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jul 20 23:45:41 2015 -0700
----------------------------------------------------------------------
.../org/apache/calcite/plan/RelOptUtil.java | 57 +++++++-------------
.../rel/metadata/RelMdDistinctRowCount.java | 2 +-
.../calcite/rel/metadata/RelMdSelectivity.java | 2 +-
.../rel/rules/FilterProjectTransposeRule.java | 2 +-
4 files changed, 23 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9fe32b7/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
index 7a79aeb..6892dfd 100644
--- a/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
+++ b/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
@@ -58,7 +58,6 @@ import org.apache.calcite.rex.RexMultisetUtil;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.rex.RexOver;
import org.apache.calcite.rex.RexProgram;
-import org.apache.calcite.rex.RexProgramBuilder;
import org.apache.calcite.rex.RexShuttle;
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.rex.RexVisitorImpl;
@@ -2365,45 +2364,29 @@ public abstract class RelOptUtil {
return exps;
}
+ @Deprecated // to be removed before 2.0
+ public static RexNode pushFilterPastProject(RexNode filter,
+ final Project projRel) {
+ return pushPastProject(filter, projRel);
+ }
+
/**
- * Converts a filter to the new filter that would result if the filter is
- * pushed past a LogicalProject that it currently is referencing.
+ * Converts an expression that is based on the output fields of a
+ * {@link Project} to an equivalent expression on the Project's
+ * input fields.
*
- * @param filter the filter to be converted
- * @param projRel project rel underneath the filter
- * @return converted filter
+ * @param node The expression to be converted
+ * @param project Project underneath the expression
+ * @return converted expression
*/
- public static RexNode pushFilterPastProject(
- RexNode filter,
- Project projRel) {
- // use RexPrograms to merge the filter and LogicalProject into a
- // single program so we can convert the LogicalFilter condition to
- // directly reference the LogicalProject's child
- RexBuilder rexBuilder = projRel.getCluster().getRexBuilder();
- RexProgram bottomProgram =
- RexProgram.create(
- projRel.getInput().getRowType(),
- projRel.getProjects(),
- null,
- projRel.getRowType(),
- rexBuilder);
-
- RexProgramBuilder topProgramBuilder =
- new RexProgramBuilder(
- projRel.getRowType(),
- rexBuilder);
- topProgramBuilder.addIdentity();
- topProgramBuilder.addCondition(filter);
- RexProgram topProgram = topProgramBuilder.getProgram();
-
- RexProgram mergedProgram =
- RexProgramBuilder.mergePrograms(
- topProgram,
- bottomProgram,
- rexBuilder);
-
- return mergedProgram.expandLocalRef(
- mergedProgram.getCondition());
+ public static RexNode pushPastProject(RexNode node,
+ final Project project) {
+ return node.accept(
+ new RexShuttle() {
+ @Override public RexNode visitInputRef(RexInputRef ref) {
+ return project.getProjects().get(ref.getIndex());
+ }
+ });
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9fe32b7/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
index de76201..784e131 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistinctRowCount.java
@@ -236,7 +236,7 @@ public class RelMdDistinctRowCount {
if (childPred == null) {
modifiedPred = null;
} else {
- modifiedPred = RelOptUtil.pushFilterPastProject(childPred, rel);
+ modifiedPred = RelOptUtil.pushPastProject(childPred, rel);
}
Double distinctRowCount =
RelMetadataQuery.getDistinctRowCount(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9fe32b7/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
index 3bffe26..c59a005 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdSelectivity.java
@@ -169,7 +169,7 @@ public class RelMdSelectivity {
if (childPred == null) {
modifiedPred = null;
} else {
- modifiedPred = RelOptUtil.pushFilterPastProject(childPred, rel);
+ modifiedPred = RelOptUtil.pushPastProject(childPred, rel);
}
Double selectivity =
RelMetadataQuery.getSelectivity(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9fe32b7/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java b/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
index 802cf87..ff20f5a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/FilterProjectTransposeRule.java
@@ -88,7 +88,7 @@ public class FilterProjectTransposeRule extends RelOptRule {
// convert the filter to one that references the child of the project
RexNode newCondition =
- RelOptUtil.pushFilterPastProject(filter.getCondition(), project);
+ RelOptUtil.pushPastProject(filter.getCondition(), project);
// Remove cast of BOOLEAN NOT NULL to BOOLEAN or vice versa. Filter accepts
// nullable and not-nullable conditions, but a CAST might get in the way of