Repository: phoenix
Updated Branches:
  refs/heads/calcite 8b68b1c4e -> 52ba5d24d


PHOENIX-2090 Refine PhoenixTableScan.computeSelfCost() when scanRanges is 
available


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/52ba5d24
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/52ba5d24
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/52ba5d24

Branch: refs/heads/calcite
Commit: 52ba5d24d6217b0f619f3dd143142ef86cbab02e
Parents: 8b68b1c
Author: maryannxue <maryann....@gmail.com>
Authored: Fri Feb 12 21:43:12 2016 -0500
Committer: maryannxue <maryann....@gmail.com>
Committed: Fri Feb 12 21:43:12 2016 -0500

----------------------------------------------------------------------
 .../it/java/org/apache/phoenix/calcite/CalciteIndexIT.java  | 2 +-
 .../main/java/org/apache/phoenix/calcite/PhoenixTable.java  | 5 +----
 .../phoenix/calcite/rel/PhoenixAbstractAggregate.java       | 3 ++-
 .../java/org/apache/phoenix/calcite/rel/PhoenixRel.java     | 2 +-
 .../org/apache/phoenix/calcite/rel/PhoenixTableScan.java    | 9 +++++++--
 5 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
index 3f0f754..d1aea74 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIndexIT.java
@@ -93,7 +93,7 @@ public class CalciteIndexIT extends BaseCalciteIT {
                        "  PhoenixServerProject(A_STRING=[$0])\n" +
                        "    PhoenixTableScan(table=[[phoenix, IDX1]], 
scanOrder=[FORWARD])\n")
             .close();
-        start(true, 1000f).sql("select a_string from aTable order by 
organization_id")
+        start(true, 1000000f).sql("select a_string from aTable order by 
organization_id")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixServerProject(A_STRING=[$2], 
ORGANIZATION_ID=[$0])\n" +
                        "    PhoenixTableScan(table=[[phoenix, ATABLE]], 
scanOrder=[FORWARD])\n")

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
index 1539dcd..fea4c8a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixTable.java
@@ -21,7 +21,6 @@ import org.apache.calcite.schema.impl.AbstractTable;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.util.ImmutableBitSet;
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.phoenix.calcite.rel.PhoenixRel;
 import org.apache.phoenix.calcite.rel.PhoenixTableScan;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.QueryServices;
@@ -185,9 +184,7 @@ public class PhoenixTable extends AbstractTable implements 
TranslatableTable {
         return new Statistic() {
             @Override
             public Double getRowCount() {
-                float f = pc.getQueryServices().getProps().getFloat(
-                        PhoenixRel.ROW_COUNT_FACTOR, 1f);
-                return (double) (rowCount * f);
+                return (double) rowCount;
             }
 
             @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
index 9d76f59..de9f0c2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractAggregate.java
@@ -105,6 +105,7 @@ abstract public class PhoenixAbstractAggregate extends 
Aggregate implements Phoe
             return planner.getCostFactory().makeInfiniteCost();
         
         double rowCount = mq.getRowCount(this);
+        double bytesPerRow = mq.getAverageRowSize(this);
         if (isOrderedGroupBy) {
             rowCount = (rowCount * rowCount) / Util.nLogN(rowCount);
         }
@@ -117,7 +118,7 @@ abstract public class PhoenixAbstractAggregate extends 
Aggregate implements Phoe
             multiplier += 0.0125f;
           }
         }
-        return planner.getCostFactory().makeCost(rowCount * multiplier, 0, 0);
+        return planner.getCostFactory().makeCost(rowCount * multiplier * 
bytesPerRow, 0, 0);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRel.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRel.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRel.java
index 501060e..f6b0e97 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRel.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixRel.java
@@ -46,7 +46,7 @@ public interface PhoenixRel extends RelNode {
    * <p>Multiply by the value (which is less than unity), and you will get a 
cheaper cost.
    * Server is cheaper.
    */
-  double SERVER_FACTOR = 0.1;
+  double SERVER_FACTOR = 0.2;
 
   QueryPlan implement(Implementor implementor);
   

http://git-wip-us.apache.org/repos/asf/phoenix/blob/52ba5d24/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
index d9fa23f..0841006 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixTableScan.java
@@ -73,6 +73,7 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
     public final ScanRanges scanRanges;
     
     protected final GuidePostsInfo filteredGuideposts;
+    protected final float rowCountFactor;
     
     public static PhoenixTableScan create(RelOptCluster cluster, final 
RelOptTable table) {
         return create(cluster, table, null,
@@ -100,6 +101,9 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
         super(cluster, traits, table);
         this.filter = filter;
         this.scanOrder = scanOrder;
+        final PhoenixTable phoenixTable = table.unwrap(PhoenixTable.class);
+        this.rowCountFactor = phoenixTable.pc.getQueryServices()
+                .getProps().getFloat(PhoenixRel.ROW_COUNT_FACTOR, 1f);
         
         ScanRanges scanRanges = null;
         GuidePostsInfo info = null;
@@ -107,7 +111,6 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
         if (filter != null) {
             try {
                 // TODO simplify this code
-                final PhoenixTable phoenixTable = 
table.unwrap(PhoenixTable.class);
                 PTable pTable = phoenixTable.getTable();
                 TableRef tableRef = new 
TableRef(CalciteUtils.createTempAlias(), pTable, HConstants.LATEST_TIMESTAMP, 
false);
                 // We use a implementor with a special implementation for 
field access
@@ -239,6 +242,7 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
         } else {
             byteCount = phoenixTable.byteCount;
         }
+        byteCount *= rowCountFactor;
         if (scanOrder != ScanOrder.NONE) {
             // We don't want to make a big difference here. The idea is to 
avoid
             // forcing row key order whenever the order is absolutely useless.
@@ -257,6 +261,7 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
         }
         return planner.getCostFactory()
                 .makeCost(byteCount, byteCount + 1, 0)
+                .multiplyBy(SERVER_FACTOR)
                 .multiplyBy(PHOENIX_FACTOR);
     }
     
@@ -267,7 +272,7 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
             rows = rows * mq.getSelectivity(this, filter);
         }
         
-        return rows;
+        return rows * rowCountFactor;
     }
     
     @Override

Reply via email to