DRILL-6093 : Account for simple columns in project cpu costing close apache/drill#1093
Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/a2058fd1 Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/a2058fd1 Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/a2058fd1 Branch: refs/heads/master Commit: a2058fd16b555cebd0a539d5c9b993e0d628eced Parents: 7d1e81a Author: Gautam Parai <gpa...@maprtech.com> Authored: Tue Jan 16 15:16:16 2018 -0800 Committer: Aman Sinha <asi...@maprtech.com> Committed: Tue Jan 23 14:40:33 2018 -0800 ---------------------------------------------------------------------- .../drill/exec/planner/common/DrillProjectRelBase.java | 10 ++++++---- .../test/java/org/apache/drill/TestProjectPushDown.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/a2058fd1/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillProjectRelBase.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillProjectRelBase.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillProjectRelBase.java index 44d708e..8141a8c 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillProjectRelBase.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/common/DrillProjectRelBase.java @@ -74,10 +74,12 @@ public abstract class DrillProjectRelBase extends Project implements DrillRelNod if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) { return super.computeSelfCost(planner, mq).multiplyBy(.1); } - - // cost is proportional to the number of rows and number of columns being projected - double rowCount = nonSimpleFieldCount > 0 ? mq.getRowCount(this) : 0; - double cpuCost = DrillCostBase.PROJECT_CPU_COST * rowCount * nonSimpleFieldCount; + double rowCount = mq.getRowCount(this); + // Attribute small cost for projecting simple fields. In reality projecting simple columns in not free and + // this allows projection pushdown/project-merge rules to kick-in thereby eliminating unneeded columns from + // the projection. + double cpuCost = DrillCostBase.PROJECT_CPU_COST * rowCount * nonSimpleFieldCount + + (this.getRowType().getFieldCount() - nonSimpleFieldCount) * rowCount * DrillCostBase.BASE_CPU_COST; DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory(); return costFactory.makeCost(rowCount, cpuCost, 0, 0); http://git-wip-us.apache.org/repos/asf/drill/blob/a2058fd1/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java b/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java index ad55a0d..013c954 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java +++ b/exec/java-exec/src/test/java/org/apache/drill/TestProjectPushDown.java @@ -287,6 +287,17 @@ public class TestProjectPushDown extends PlanTestBase { } } + @Test + public void testProjectPushdownPastJoinWithJoinPushExpressions() throws Exception { + final String query = "SELECT L.L_QUANTITY FROM cp.`tpch/lineitem.parquet` L, cp.`tpch/orders.parquet` O" + + " WHERE cast(L.L_ORDERKEY as int) = cast(O.O_ORDERKEY as int)"; + final String[] expectedPatterns = { + ".*HashJoin.*", "Project.*\\(L_QUANTITY.*CAST\\(\\$0\\)\\:INTEGER.*", "Project.*CAST\\(\\$0\\)\\:INTEGER.*"}; + // L_ORDERKEY, O_ORDERKEY should not be present in the projects below the join + final String[] excludedPatterns = {".*Project\\(L_ORDERKEY=.*", ".*Project\\(O_ORDERKEY=.*"}; + PlanTestBase.testPlanMatchingPatterns(query, expectedPatterns, excludedPatterns); + } + protected void testPushDown(PushDownTestInstance test) throws Exception { testPhysicalPlan(test.getSql(), test.getExpected()); }