Revert "PHOENIX-2678 Replace calcite default RelOptCostFactory"

This reverts commit 69a2f2437bf0d6513d3f6c46ec34094279f0f411.


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

Branch: refs/heads/calcite
Commit: bc4b89172180e963267b1588c3f31a3d94491777
Parents: 58ec257
Author: maryannxue <maryann....@gmail.com>
Authored: Tue Feb 23 10:28:45 2016 -0500
Committer: maryannxue <maryann....@gmail.com>
Committed: Tue Feb 23 10:28:45 2016 -0500

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteIT.java   |   8 +-
 .../apache/phoenix/calcite/CalciteIndexIT.java  |   2 +-
 .../calcite/jdbc/PhoenixPrepareImpl.java        |   2 -
 .../phoenix/calcite/plan/PhoenixCost.java       | 227 -------------------
 .../calcite/rel/PhoenixAbstractAggregate.java   |   2 +-
 .../calcite/rel/PhoenixAbstractSort.java        |   2 +-
 .../calcite/rel/PhoenixClientAggregate.java     |   3 +-
 .../phoenix/calcite/rel/PhoenixClientJoin.java  |   4 +-
 .../calcite/rel/PhoenixClientProject.java       |   3 +-
 .../calcite/rel/PhoenixClientSemiJoin.java      |   4 +-
 .../phoenix/calcite/rel/PhoenixClientSort.java  |   3 +-
 .../calcite/rel/PhoenixCompactClientSort.java   |   3 +-
 .../phoenix/calcite/rel/PhoenixCorrelate.java   |  21 +-
 .../phoenix/calcite/rel/PhoenixFilter.java      |   4 +-
 .../phoenix/calcite/rel/PhoenixLimit.java       |   4 +-
 .../calcite/rel/PhoenixMergeSortUnion.java      |   4 +-
 .../apache/phoenix/calcite/rel/PhoenixRel.java  |   7 +
 .../calcite/rel/PhoenixServerAggregate.java     |   3 +-
 .../phoenix/calcite/rel/PhoenixServerJoin.java  |   4 +-
 .../calcite/rel/PhoenixServerProject.java       |   3 +-
 .../calcite/rel/PhoenixServerSemiJoin.java      |   4 +-
 .../phoenix/calcite/rel/PhoenixServerSort.java  |   3 +-
 .../phoenix/calcite/rel/PhoenixTableScan.java   |   6 +-
 .../phoenix/calcite/rel/PhoenixUncollect.java   |  15 +-
 .../phoenix/calcite/rel/PhoenixUnion.java       |   4 +-
 .../phoenix/calcite/rel/PhoenixValues.java      |   5 +-
 .../calcite/rules/PhoenixConverterRules.java    |   3 +-
 27 files changed, 60 insertions(+), 293 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
index 820c2d4..df6ac81 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
@@ -293,17 +293,17 @@ public class CalciteIT extends BaseCalciteIT {
         
         start(false, 1000f).sql("select t1.entity_id, t2.a_string, 
t3.organization_id from aTable t1 join aTable t2 on t1.entity_id = t2.entity_id 
and t1.organization_id = t2.organization_id join atable t3 on t1.entity_id = 
t3.entity_id and t1.organization_id = t3.organization_id")
                 .explainIs("PhoenixToEnumerableConverter\n" +
-                           "  PhoenixClientProject(ENTITY_ID=[$1], 
A_STRING=[$4], ORGANIZATION_ID=[$5])\n" +
-                           "    PhoenixClientJoin(condition=[AND(=($1, $6), 
=($0, $5))], joinType=[inner])\n" +
+                           "  PhoenixClientProject(ENTITY_ID=[$1], 
A_STRING=[$6], ORGANIZATION_ID=[$2])\n" +
+                           "    PhoenixClientJoin(condition=[AND(=($1, $5), 
=($0, $4))], joinType=[inner])\n" +
                            "      PhoenixClientJoin(condition=[AND(=($1, $3), 
=($0, $2))], joinType=[inner])\n" +
                            "        PhoenixServerSort(sort0=[$1], sort1=[$0], 
dir0=[ASC], dir1=[ASC])\n" +
                            "          
PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1])\n" +
                            "            PhoenixTableScan(table=[[phoenix, 
ATABLE]])\n" +
                            "        PhoenixServerSort(sort0=[$1], sort1=[$0], 
dir0=[ASC], dir1=[ASC])\n" +
-                           "          
PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1], A_STRING=[$2])\n" +
+                           "          
PhoenixServerProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1])\n" +
                            "            PhoenixTableScan(table=[[phoenix, 
ATABLE]])\n" +
                            "      PhoenixServerSort(sort0=[$1], sort1=[$0], 
dir0=[ASC], dir1=[ASC])\n" +
-                           "        PhoenixServerProject(ORGANIZATION_ID=[$0], 
ENTITY_ID=[$1])\n" +
+                           "        PhoenixServerProject(ORGANIZATION_ID=[$0], 
ENTITY_ID=[$1], A_STRING=[$2])\n" +
                            "          PhoenixTableScan(table=[[phoenix, 
ATABLE]])\n")
                 .resultIs(false, new Object[][] {
                           {"00A123122312312", "a", "00D300000000XHP"},

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/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 1b2423b..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
@@ -168,7 +168,7 @@ public class CalciteIndexIT extends BaseCalciteIT {
                            "    PhoenixTableScan(table=[[phoenix, 
IDXSALTED_SALTED_TEST_TABLE]], filter=[>(CAST($0):INTEGER, 4)])\n")
                 .resultIs(false, new Object[][]{{999L}})
                 .close();
-        start(true, 0.001f).sql("select * from " + SALTED_TABLE_NAME + " where 
col1 <= 5 order by col1")
+        start(true, 1f).sql("select * from " + SALTED_TABLE_NAME + " where 
col1 <= 5 order by col1")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixServerProject(MYPK0=[$1], MYPK1=[$2], 
COL0=[$3], COL1=[CAST($0):INTEGER])\n" +
                            "    PhoenixTableScan(table=[[phoenix, 
IDXSALTED_SALTED_TEST_TABLE]], filter=[<=(CAST($0):INTEGER, 5)], 
scanOrder=[FORWARD])\n")

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
index b5968f7..ae09b42 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/jdbc/PhoenixPrepareImpl.java
@@ -27,7 +27,6 @@ import org.apache.calcite.util.Pair;
 import org.apache.phoenix.calcite.PhoenixSchema;
 import org.apache.phoenix.calcite.parse.SqlCreateView;
 import org.apache.phoenix.calcite.parser.PhoenixParserImpl;
-import org.apache.phoenix.calcite.plan.PhoenixCost;
 import org.apache.phoenix.calcite.rel.PhoenixRel;
 import org.apache.phoenix.calcite.rel.PhoenixServerProject;
 import org.apache.phoenix.calcite.rel.PhoenixTemporarySort;
@@ -78,7 +77,6 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
             final CalcitePrepare.Context prepareContext,
             org.apache.calcite.plan.Context externalContext,
             RelOptCostFactory costFactory) {
-        costFactory = PhoenixCost.FACTORY;
         RelOptPlanner planner = super.createPlanner(prepareContext, 
externalContext, costFactory);
         
         planner.removeRule(EnumerableRules.ENUMERABLE_SEMI_JOIN_RULE);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/plan/PhoenixCost.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/plan/PhoenixCost.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/plan/PhoenixCost.java
deleted file mode 100644
index 3bbd403..0000000
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/plan/PhoenixCost.java
+++ /dev/null
@@ -1,227 +0,0 @@
-package org.apache.phoenix.calcite.plan;
-
-import java.util.Objects;
-
-import org.apache.calcite.plan.RelOptCost;
-import org.apache.calcite.plan.RelOptCostFactory;
-import org.apache.calcite.plan.RelOptUtil;
-
-/**
- * Implementation of Calcite {@link org.apache.calcite.plan.RelOptCost}
- * for Phoenix.
- */
-public class PhoenixCost implements RelOptCost, Comparable<RelOptCost> {
-    //~ Static fields/initializers 
---------------------------------------------
-
-    static final PhoenixCost INFINITY =
-            new PhoenixCost(
-                    Double.POSITIVE_INFINITY,
-                    Double.POSITIVE_INFINITY,
-                    Double.POSITIVE_INFINITY) {
-        public String toString() {
-            return "{inf}";
-        }
-    };
-
-    static final PhoenixCost HUGE =
-            new PhoenixCost(
-                    Double.MAX_VALUE,
-                    Double.MAX_VALUE,
-                    Double.MAX_VALUE) {
-        public String toString() {
-            return "{huge}";
-        }
-    };
-
-    static final PhoenixCost ZERO =
-            new PhoenixCost(0.0, 0.0, 0.0) {
-        public String toString() {
-            return "{zero}";
-        }
-    };
-
-    static final PhoenixCost TINY =
-            new PhoenixCost(1.0, 1.0, 1.0) {
-        public String toString() {
-            return "{tiny}";
-        }
-    };
-
-    public static final RelOptCostFactory FACTORY = new Factory();
-
-    //~ Instance fields 
--------------------------------------------------------
-
-    final double cpu;
-    final double io;
-    final double rowCount;
-
-    //~ Constructors 
-----------------------------------------------------------
-
-    PhoenixCost(double rowCount, double cpu, double io) {
-        this.rowCount = rowCount;
-        this.cpu = cpu;
-        this.io = io;
-    }
-
-    //~ Methods 
----------------------------------------------------------------
-
-    @Override
-    public double getRows() {
-        return rowCount;
-    }
-
-    @Override
-    public double getCpu() {
-        return cpu;
-    }
-
-    @Override
-    public double getIo() {
-        return io;
-    }
-
-    @Override
-    public boolean isInfinite() {
-        return (this == INFINITY)
-                || (this.rowCount == Double.POSITIVE_INFINITY)
-                || (this.cpu == Double.POSITIVE_INFINITY)
-                || (this.io == Double.POSITIVE_INFINITY);
-    }
-
-    @Override
-    public boolean isLe(RelOptCost other) {
-        return this.compareTo(other) <= 0;
-    }
-
-    public boolean isLt(RelOptCost other) {
-        return this.compareTo(other) < 0;
-    }
-
-    @Override
-    public int compareTo(RelOptCost other) {
-        if (this == other) {
-            return 0;
-        }
-        
-        PhoenixCost that = (PhoenixCost) other;
-        if (this.rowCount != that.rowCount) {
-            return this.rowCount < that.rowCount ? -1 : 1;
-        }
-        
-        double thisSum = this.cpu + this.io;
-        double thatSum = that.cpu + that.io;
-        return thisSum == thatSum ? 0 : (thisSum < thatSum ? -1 : 1);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(rowCount, cpu, io);
-    }
-
-    @Override
-    public boolean equals(RelOptCost other) {
-        return (other instanceof PhoenixCost)
-                && this.compareTo(other) == 0;
-    }
-
-    public boolean isEqWithEpsilon(RelOptCost other) {
-        if (!(other instanceof PhoenixCost)) {
-            return false;
-        }
-        PhoenixCost that = (PhoenixCost) other;
-        return (this == that)
-                || ((Math.abs(this.rowCount - that.rowCount) < 
RelOptUtil.EPSILON)
-                        && (Math.abs(this.cpu - that.cpu) < RelOptUtil.EPSILON)
-                        && (Math.abs(this.io - that.io) < RelOptUtil.EPSILON));
-    }
-
-    public RelOptCost minus(RelOptCost other) {
-        if (this == INFINITY) {
-            return this;
-        }
-        PhoenixCost that = (PhoenixCost) other;
-        return new PhoenixCost(
-                this.rowCount - that.rowCount,
-                this.cpu - that.cpu,
-                this.io - that.io);
-    }
-
-    public RelOptCost multiplyBy(double factor) {
-        if (this == INFINITY) {
-            return this;
-        }
-        return new PhoenixCost(rowCount * factor, cpu * factor, io * factor);
-    }
-
-    public double divideBy(RelOptCost cost) {
-        // Compute the geometric average of the ratios of all of the factors
-        // which are non-zero and finite.
-        PhoenixCost that = (PhoenixCost) cost;
-        double d = 1;
-        double n = 0;
-        if ((this.rowCount != 0)
-                && !Double.isInfinite(this.rowCount)
-                && (that.rowCount != 0)
-                && !Double.isInfinite(that.rowCount)) {
-            d *= this.rowCount / that.rowCount;
-            ++n;
-        }
-        if ((this.cpu != 0)
-                && !Double.isInfinite(this.cpu)
-                && (that.cpu != 0)
-                && !Double.isInfinite(that.cpu)) {
-            d *= this.cpu / that.cpu;
-            ++n;
-        }
-        if ((this.io != 0)
-                && !Double.isInfinite(this.io)
-                && (that.io != 0)
-                && !Double.isInfinite(that.io)) {
-            d *= this.io / that.io;
-            ++n;
-        }
-        if (n == 0) {
-            return 1.0;
-        }
-        return Math.pow(d, 1 / n);
-    }
-
-    public RelOptCost plus(RelOptCost other) {
-        PhoenixCost that = (PhoenixCost) other;
-        if ((this == INFINITY) || (that == INFINITY)) {
-            return INFINITY;
-        }
-        return new PhoenixCost(
-                this.rowCount + that.rowCount,
-                this.cpu + that.cpu,
-                this.io + that.io);
-    }
-
-    public String toString() {
-        return "{" + rowCount + " rows, " + cpu + " cpu, " + io + " io}";
-    }
-
-    /** Implementation of {@link org.apache.calcite.plan.RelOptCostFactory}
-     * that creates {@link org.apache.phoenix.calcite.plan.PhoenixCost}s. */
-    private static class Factory implements RelOptCostFactory {
-      public RelOptCost makeCost(double dRows, double dCpu, double dIo) {
-        return new PhoenixCost(dRows, dCpu, dIo);
-      }
-
-      public RelOptCost makeHugeCost() {
-        return PhoenixCost.HUGE;
-      }
-
-      public RelOptCost makeInfiniteCost() {
-        return PhoenixCost.INFINITY;
-      }
-
-      public RelOptCost makeTinyCost() {
-        return PhoenixCost.TINY;
-      }
-
-      public RelOptCost makeZeroCost() {
-        return PhoenixCost.ZERO;
-      }
-    }
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/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 26d64dc..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
@@ -118,7 +118,7 @@ abstract public class PhoenixAbstractAggregate extends 
Aggregate implements Phoe
             multiplier += 0.0125f;
           }
         }
-        return planner.getCostFactory().makeCost(0, rowCount * multiplier * 
bytesPerRow, 0);
+        return planner.getCostFactory().makeCost(rowCount * multiplier * 
bytesPerRow, 0, 0);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractSort.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractSort.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractSort.java
index 4719426..b8c0136 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractSort.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractSort.java
@@ -41,7 +41,7 @@ abstract public class PhoenixAbstractSort extends Sort 
implements PhoenixRel {
         double rowCount = mq.getRowCount(this);
         double bytesPerRow = mq.getAverageRowSize(this);
         return planner.getCostFactory().makeCost(
-                0, Util.nLogN(rowCount) * bytesPerRow, 0);
+                Util.nLogN(rowCount) * bytesPerRow, rowCount, 0);
     }
 
     protected static OrderBy getOrderBy(RelCollation collation, Implementor 
implementor, TupleProjector tupleProjector) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientAggregate.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientAggregate.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientAggregate.java
index 9bf633e..5aaff2f 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientAggregate.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientAggregate.java
@@ -53,7 +53,8 @@ public class PhoenixClientAggregate extends 
PhoenixAbstractAggregate {
         if (!getInput().getConvention().satisfies(PhoenixConvention.CLIENT))
             return planner.getCostFactory().makeInfiniteCost();
         
-        return super.computeSelfCost(planner, mq);
+        return super.computeSelfCost(planner, mq)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientJoin.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientJoin.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientJoin.java
index 1593b9d..2df5f74 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientJoin.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientJoin.java
@@ -103,9 +103,9 @@ public class PhoenixClientJoin extends PhoenixAbstractJoin {
                 rowCount += rightRowCount;
             }
         }            
-        RelOptCost cost = planner.getCostFactory().makeCost(0, rowCount, 0);
+        RelOptCost cost = planner.getCostFactory().makeCost(rowCount, 0, 0);
 
-        return cost.multiplyBy(SERVER_FACTOR);
+        return cost.multiplyBy(SERVER_FACTOR).multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientProject.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientProject.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientProject.java
index 09eff65..799513d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientProject.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientProject.java
@@ -63,7 +63,8 @@ public class PhoenixClientProject extends 
PhoenixAbstractProject {
         if (!getInput().getConvention().satisfies(PhoenixConvention.GENERIC))
             return planner.getCostFactory().makeInfiniteCost();
         
-        return super.computeSelfCost(planner, mq);
+        return super.computeSelfCost(planner, mq)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSemiJoin.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSemiJoin.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSemiJoin.java
index 08da3fb..31dfc3d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSemiJoin.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSemiJoin.java
@@ -87,9 +87,9 @@ public class PhoenixClientSemiJoin extends 
PhoenixAbstractSemiJoin implements
                 rowCount += rightRowCount;
             }
         }            
-        RelOptCost cost = planner.getCostFactory().makeCost(0, rowCount, 0);
+        RelOptCost cost = planner.getCostFactory().makeCost(rowCount, 0, 0);
 
-        return cost.multiplyBy(SERVER_FACTOR);
+        return cost.multiplyBy(SERVER_FACTOR).multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSort.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSort.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSort.java
index 80061c8..59fb639 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSort.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixClientSort.java
@@ -48,7 +48,8 @@ public class PhoenixClientSort extends PhoenixAbstractSort {
         if (!getInput().getConvention().satisfies(PhoenixConvention.CLIENT))
             return planner.getCostFactory().makeInfiniteCost();
         
-        return super.computeSelfCost(planner, mq);
+        return super.computeSelfCost(planner, mq)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCompactClientSort.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCompactClientSort.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCompactClientSort.java
index be4c6c1..8d68a57 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCompactClientSort.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCompactClientSort.java
@@ -43,7 +43,8 @@ public class PhoenixCompactClientSort extends 
PhoenixAbstractSort {
             return planner.getCostFactory().makeInfiniteCost();
         
         return super.computeSelfCost(planner, mq)
-                .multiplyBy(SERVER_FACTOR);
+                .multiplyBy(SERVER_FACTOR)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCorrelate.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCorrelate.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCorrelate.java
index b27a4be..496dfdb 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCorrelate.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixCorrelate.java
@@ -65,25 +65,8 @@ public class PhoenixCorrelate extends Correlate implements 
PhoenixRel {
         if (!getLeft().getConvention().satisfies(PhoenixConvention.GENERIC)
                 || 
!getRight().getConvention().satisfies(PhoenixConvention.GENERIC))
             return planner.getCostFactory().makeInfiniteCost();
-
-        double rowCount = mq.getRowCount(this);
-
-        final double rightRowCount = right.estimateRowCount(mq);
-        final double leftRowCount = left.estimateRowCount(mq);
-        if (Double.isInfinite(leftRowCount) || 
Double.isInfinite(rightRowCount)) {
-            return planner.getCostFactory().makeInfiniteCost();
-        }
-
-        Double restartCount = mq.getRowCount(getLeft());
-        // RelMetadataQuery.getCumulativeCost(getRight()); does not work for
-        // RelSubset, so we ask planner to cost-estimate right relation
-        RelOptCost rightCost = planner.getCost(getRight(), mq);
-        RelOptCost rescanCost =
-                rightCost.multiplyBy(Math.max(1.0, restartCount - 1));
-
-        return planner.getCostFactory().makeCost(0,
-                rowCount /* generate results */ + leftRowCount /* scan left 
results */,
-                0).plus(rescanCost);
+        
+        return super.computeSelfCost(planner, mq).multiplyBy(PHOENIX_FACTOR);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixFilter.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixFilter.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixFilter.java
index d3367af..0a0ab8e 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixFilter.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixFilter.java
@@ -57,9 +57,7 @@ public class PhoenixFilter extends Filter implements 
PhoenixRel {
         if (!getInput().getConvention().satisfies(PhoenixConvention.GENERIC))
             return planner.getCostFactory().makeInfiniteCost();
         
-        double rows = mq.getRowCount(this);
-        double inputRows = mq.getRowCount(getInput());
-        return planner.getCostFactory().makeCost(0, rows + inputRows, 0);
+        return super.computeSelfCost(planner, mq).multiplyBy(PHOENIX_FACTOR);
     }
 
     public QueryPlan implement(Implementor implementor) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
index 44f8229..3edcf60 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
@@ -69,7 +69,9 @@ public class PhoenixLimit extends SingleRel implements 
PhoenixRel {
             return planner.getCostFactory().makeInfiniteCost();
         
         double rowCount = mq.getRowCount(this);
-        return planner.getCostFactory().makeCost(0, rowCount, 0);
+        return planner.getCostFactory()
+                .makeCost(rowCount, 0, 0)
+                .multiplyBy(PHOENIX_FACTOR);
     }
     
     @Override 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixMergeSortUnion.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixMergeSortUnion.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixMergeSortUnion.java
index 395a164..9695662 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixMergeSortUnion.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixMergeSortUnion.java
@@ -59,9 +59,9 @@ public class PhoenixMergeSortUnion extends Union implements 
PhoenixRel {
             }
         }
         
-        double rowCount = mq.getRowCount(this);
         double mergeSortFactor = 1.1;
-        return planner.getCostFactory().makeCost(0, rowCount * 
mergeSortFactor, 0);
+        return super.computeSelfCost(planner, mq)
+                .multiplyBy(PHOENIX_FACTOR).multiplyBy(mergeSortFactor);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/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 cff8f70..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
@@ -34,6 +34,13 @@ public interface PhoenixRel extends RelNode {
   /** For test purpose */
   String ROW_COUNT_FACTOR = "phoenix.calcite.metadata.rowcount.factor";
 
+  /** Relative cost of Phoenix versus Enumerable convention.
+   *
+   * <p>Multiply by the value (which is less than unity), and you will get a 
cheaper cost.
+   * Phoenix is cheaper.
+   */
+  double PHOENIX_FACTOR = 0.0001;
+
   /** Relative cost of server plan versus client plan.
    *
    * <p>Multiply by the value (which is less than unity), and you will get a 
cheaper cost.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerAggregate.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerAggregate.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerAggregate.java
index f7d02f8..7ea2581 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerAggregate.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerAggregate.java
@@ -49,7 +49,8 @@ public class PhoenixServerAggregate extends 
PhoenixAbstractAggregate {
             return planner.getCostFactory().makeInfiniteCost();
         
         return super.computeSelfCost(planner, mq)
-                .multiplyBy(SERVER_FACTOR);
+                .multiplyBy(SERVER_FACTOR)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
index 39a3e9d..2f09a9d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
@@ -99,9 +99,9 @@ public class PhoenixServerJoin extends PhoenixAbstractJoin {
             }
         }            
         
-        RelOptCost cost = planner.getCostFactory().makeCost(0, rowCount, 0);
+        RelOptCost cost = planner.getCostFactory().makeCost(rowCount, 0, 0);
 
-        return cost.multiplyBy(SERVER_FACTOR);
+        return cost.multiplyBy(SERVER_FACTOR).multiplyBy(PHOENIX_FACTOR);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerProject.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerProject.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerProject.java
index ed90c5c..ba0854b 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerProject.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerProject.java
@@ -53,7 +53,8 @@ public class PhoenixServerProject extends 
PhoenixAbstractProject {
             return planner.getCostFactory().makeInfiniteCost();
         
         return super.computeSelfCost(planner, mq)
-                .multiplyBy(SERVER_FACTOR);
+                .multiplyBy(SERVER_FACTOR)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSemiJoin.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSemiJoin.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSemiJoin.java
index 50b4ba1..74c3e4d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSemiJoin.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSemiJoin.java
@@ -86,9 +86,9 @@ public class PhoenixServerSemiJoin extends 
PhoenixAbstractSemiJoin {
             }
         }            
         
-        RelOptCost cost = planner.getCostFactory().makeCost(0, rowCount, 0);
+        RelOptCost cost = planner.getCostFactory().makeCost(rowCount, 0, 0);
 
-        return cost.multiplyBy(SERVER_FACTOR);
+        return cost.multiplyBy(SERVER_FACTOR).multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSort.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSort.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSort.java
index 104c3da..3053cca 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSort.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerSort.java
@@ -44,7 +44,8 @@ public class PhoenixServerSort extends PhoenixAbstractSort {
             return planner.getCostFactory().makeInfiniteCost();
         
         return super.computeSelfCost(planner, mq)
-                .multiplyBy(SERVER_FACTOR);
+                .multiplyBy(SERVER_FACTOR)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/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 6dbe5b1..db6ac24 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
@@ -262,8 +262,10 @@ public class PhoenixTableScan extends TableScan implements 
PhoenixRel {
                 byteCount = addEpsilon(byteCount);
             }
         }
-        return planner.getCostFactory().makeCost(0, byteCount, 0)
-                .multiplyBy(SERVER_FACTOR);
+        return planner.getCostFactory()
+                .makeCost(byteCount, byteCount + 1, 0)
+                .multiplyBy(SERVER_FACTOR)
+                .multiplyBy(PHOENIX_FACTOR);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUncollect.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUncollect.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUncollect.java
index cf090c3..0d64868 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUncollect.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUncollect.java
@@ -20,30 +20,29 @@ import org.apache.phoenix.schema.types.PDataType;
 
 public class PhoenixUncollect extends Uncollect implements PhoenixRel {
     
-    public static PhoenixUncollect create(RelNode input, boolean 
withOrdinality) {
+    public static PhoenixUncollect create(RelNode input) {
         RelOptCluster cluster = input.getCluster();
         RelTraitSet traits = cluster.traitSetOf(PhoenixConvention.CLIENT);
-        return new PhoenixUncollect(cluster, traits, input, withOrdinality);
+        return new PhoenixUncollect(cluster, traits, input);
     }
 
     private PhoenixUncollect(RelOptCluster cluster, RelTraitSet traitSet,
-            RelNode child, boolean withOrdinality) {
-        super(cluster, traitSet, child, withOrdinality);
+            RelNode child) {
+        super(cluster, traitSet, child);
     }
 
     @Override
     public PhoenixUncollect copy(RelTraitSet traitSet,
         RelNode newInput) {
-        return create(newInput, withOrdinality);
+        return create(newInput);
     }
 
     @Override
     public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery 
mq) {
         if (!getInput().getConvention().satisfies(PhoenixConvention.GENERIC))
             return planner.getCostFactory().makeInfiniteCost();
-                
-        double rowCount = mq.getRowCount(this);
-        return planner.getCostFactory().makeCost(0, rowCount, 0);
+        
+        return super.computeSelfCost(planner, mq).multiplyBy(PHOENIX_FACTOR);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUnion.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUnion.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUnion.java
index b0978ea..70bc71c 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUnion.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixUnion.java
@@ -47,8 +47,8 @@ public class PhoenixUnion extends Union implements PhoenixRel 
{
             }
         }
         
-        double rowCount = mq.getRowCount(this);
-        return planner.getCostFactory().makeCost(0, rowCount, 0);
+        return super.computeSelfCost(planner, mq)
+                .multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
index 5422583..9af3f52 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
@@ -101,9 +101,8 @@ public class PhoenixValues extends Values implements 
PhoenixRel {
     }
 
     @Override
-    public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery 
mq) {        
-        double rowCount = mq.getRowCount(this);
-        return planner.getCostFactory().makeCost(0, rowCount, 0);
+    public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery 
mq) {
+        return super.computeSelfCost(planner, mq).multiplyBy(PHOENIX_FACTOR);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bc4b8917/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
index 396974d..81dbe21 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rules/PhoenixConverterRules.java
@@ -680,8 +680,7 @@ public class PhoenixConverterRules {
             return PhoenixUncollect.create(
                 convert(
                         uncollect.getInput(), 
-                        
uncollect.getInput().getTraitSet().replace(PhoenixConvention.GENERIC)),
-                uncollect.withOrdinality);
+                        
uncollect.getInput().getTraitSet().replace(PhoenixConvention.GENERIC)));
         }
     }
 

Reply via email to