[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost
Repository: phoenix Updated Branches: refs/heads/5.x-HBase-2.0 f0b31ce19 -> 71537ed63 http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java index 00a92eb..22570e4 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java @@ -34,6 +34,10 @@ import org.apache.phoenix.compile.QueryPlan; import org.apache.phoenix.compile.RowProjector; import org.apache.phoenix.compile.StatementContext; import org.apache.phoenix.coprocessor.BaseScannerRegionObserver; +import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor; +import org.apache.phoenix.execute.visitor.ByteCountVisitor; +import org.apache.phoenix.execute.visitor.QueryPlanVisitor; +import org.apache.phoenix.execute.visitor.RowCountVisitor; import org.apache.phoenix.expression.Expression; import org.apache.phoenix.expression.OrderByExpression; import org.apache.phoenix.expression.aggregator.Aggregators; @@ -89,25 +93,30 @@ public class ClientAggregatePlan extends ClientProcessingPlan { @Override public Cost getCost() { -Long byteCount = null; -try { -byteCount = getEstimatedBytesToScan(); -} catch (SQLException e) { -// ignored. -} - -if (byteCount == null) { +Double outputBytes = this.accept(new ByteCountVisitor()); +Double inputRows = this.getDelegate().accept(new RowCountVisitor()); +Double rowWidth = this.accept(new AvgRowWidthVisitor()); +if (inputRows == null || outputBytes == null || rowWidth == null) { return Cost.UNKNOWN; } +double inputBytes = inputRows * rowWidth; +double rowsBeforeHaving = RowCountVisitor.aggregate( +RowCountVisitor.filter( +inputRows.doubleValue(), +RowCountVisitor.stripSkipScanFilter( +context.getScan().getFilter())), +groupBy); +double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, having); +double bytesBeforeHaving = rowWidth * rowsBeforeHaving; +double bytesAfterHaving = rowWidth * rowsAfterHaving; int parallelLevel = CostUtil.estimateParallelLevel( false, context.getConnection().getQueryServices()); -Cost cost = CostUtil.estimateAggregateCost(byteCount, -groupBy, clientAggregators.getEstimatedByteSize(), parallelLevel); +Cost cost = CostUtil.estimateAggregateCost( +inputBytes, bytesBeforeHaving, groupBy, parallelLevel); if (!orderBy.getOrderByExpressions().isEmpty()) { -double outputBytes = CostUtil.estimateAggregateOutputBytes( -byteCount, groupBy, clientAggregators.getEstimatedByteSize()); -Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, parallelLevel); +Cost orderByCost = CostUtil.estimateOrderByCost( +bytesAfterHaving, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return super.getCost().plus(cost); @@ -209,7 +218,16 @@ public class ClientAggregatePlan extends ClientProcessingPlan { public GroupBy getGroupBy() { return groupBy; } - + +@Override +public T accept(QueryPlanVisitor visitor) { +return visitor.visit(this); +} + +public Expression getHaving() { +return having; +} + private static class ClientGroupedAggregatingResultIterator extends BaseGroupedAggregatingResultIterator { private final List groupByExpressions; http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java index ac43919..75ba8f2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java @@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends DelegateQueryPlan { public FilterableStatement getStatement() { return statement; } + +public Expression getWhere() { +return where; +} } http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost
Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.2 ff4ad203b -> c73025115 http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java index a15ab35..21cbc2d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java @@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan; import org.apache.phoenix.compile.RowProjector; import org.apache.phoenix.compile.StatementContext; import org.apache.phoenix.coprocessor.BaseScannerRegionObserver; +import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor; +import org.apache.phoenix.execute.visitor.ByteCountVisitor; +import org.apache.phoenix.execute.visitor.QueryPlanVisitor; +import org.apache.phoenix.execute.visitor.RowCountVisitor; import org.apache.phoenix.expression.Expression; import org.apache.phoenix.expression.OrderByExpression; import org.apache.phoenix.expression.aggregator.Aggregators; @@ -90,25 +94,30 @@ public class ClientAggregatePlan extends ClientProcessingPlan { @Override public Cost getCost() { -Long byteCount = null; -try { -byteCount = getEstimatedBytesToScan(); -} catch (SQLException e) { -// ignored. -} - -if (byteCount == null) { +Double outputBytes = this.accept(new ByteCountVisitor()); +Double inputRows = this.getDelegate().accept(new RowCountVisitor()); +Double rowWidth = this.accept(new AvgRowWidthVisitor()); +if (inputRows == null || outputBytes == null || rowWidth == null) { return Cost.UNKNOWN; } +double inputBytes = inputRows * rowWidth; +double rowsBeforeHaving = RowCountVisitor.aggregate( +RowCountVisitor.filter( +inputRows.doubleValue(), +RowCountVisitor.stripSkipScanFilter( +context.getScan().getFilter())), +groupBy); +double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, having); +double bytesBeforeHaving = rowWidth * rowsBeforeHaving; +double bytesAfterHaving = rowWidth * rowsAfterHaving; int parallelLevel = CostUtil.estimateParallelLevel( false, context.getConnection().getQueryServices()); -Cost cost = CostUtil.estimateAggregateCost(byteCount, -groupBy, clientAggregators.getEstimatedByteSize(), parallelLevel); +Cost cost = CostUtil.estimateAggregateCost( +inputBytes, bytesBeforeHaving, groupBy, parallelLevel); if (!orderBy.getOrderByExpressions().isEmpty()) { -double outputBytes = CostUtil.estimateAggregateOutputBytes( -byteCount, groupBy, clientAggregators.getEstimatedByteSize()); -Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, parallelLevel); +Cost orderByCost = CostUtil.estimateOrderByCost( +bytesAfterHaving, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return super.getCost().plus(cost); @@ -210,7 +219,16 @@ public class ClientAggregatePlan extends ClientProcessingPlan { public GroupBy getGroupBy() { return groupBy; } - + +@Override +public T accept(QueryPlanVisitor visitor) { +return visitor.visit(this); +} + +public Expression getHaving() { +return having; +} + private static class ClientGroupedAggregatingResultIterator extends BaseGroupedAggregatingResultIterator { private final List groupByExpressions; http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java index ac43919..75ba8f2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java @@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends DelegateQueryPlan { public FilterableStatement getStatement() { return statement; } + +public Expression getWhere() { +return where; +} } http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost
Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.3 74b2dcc53 -> ab9070910 http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java index a15ab35..21cbc2d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java @@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan; import org.apache.phoenix.compile.RowProjector; import org.apache.phoenix.compile.StatementContext; import org.apache.phoenix.coprocessor.BaseScannerRegionObserver; +import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor; +import org.apache.phoenix.execute.visitor.ByteCountVisitor; +import org.apache.phoenix.execute.visitor.QueryPlanVisitor; +import org.apache.phoenix.execute.visitor.RowCountVisitor; import org.apache.phoenix.expression.Expression; import org.apache.phoenix.expression.OrderByExpression; import org.apache.phoenix.expression.aggregator.Aggregators; @@ -90,25 +94,30 @@ public class ClientAggregatePlan extends ClientProcessingPlan { @Override public Cost getCost() { -Long byteCount = null; -try { -byteCount = getEstimatedBytesToScan(); -} catch (SQLException e) { -// ignored. -} - -if (byteCount == null) { +Double outputBytes = this.accept(new ByteCountVisitor()); +Double inputRows = this.getDelegate().accept(new RowCountVisitor()); +Double rowWidth = this.accept(new AvgRowWidthVisitor()); +if (inputRows == null || outputBytes == null || rowWidth == null) { return Cost.UNKNOWN; } +double inputBytes = inputRows * rowWidth; +double rowsBeforeHaving = RowCountVisitor.aggregate( +RowCountVisitor.filter( +inputRows.doubleValue(), +RowCountVisitor.stripSkipScanFilter( +context.getScan().getFilter())), +groupBy); +double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, having); +double bytesBeforeHaving = rowWidth * rowsBeforeHaving; +double bytesAfterHaving = rowWidth * rowsAfterHaving; int parallelLevel = CostUtil.estimateParallelLevel( false, context.getConnection().getQueryServices()); -Cost cost = CostUtil.estimateAggregateCost(byteCount, -groupBy, clientAggregators.getEstimatedByteSize(), parallelLevel); +Cost cost = CostUtil.estimateAggregateCost( +inputBytes, bytesBeforeHaving, groupBy, parallelLevel); if (!orderBy.getOrderByExpressions().isEmpty()) { -double outputBytes = CostUtil.estimateAggregateOutputBytes( -byteCount, groupBy, clientAggregators.getEstimatedByteSize()); -Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, parallelLevel); +Cost orderByCost = CostUtil.estimateOrderByCost( +bytesAfterHaving, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return super.getCost().plus(cost); @@ -210,7 +219,16 @@ public class ClientAggregatePlan extends ClientProcessingPlan { public GroupBy getGroupBy() { return groupBy; } - + +@Override +public T accept(QueryPlanVisitor visitor) { +return visitor.visit(this); +} + +public Expression getHaving() { +return having; +} + private static class ClientGroupedAggregatingResultIterator extends BaseGroupedAggregatingResultIterator { private final List groupByExpressions; http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java index ac43919..75ba8f2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java @@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends DelegateQueryPlan { public FilterableStatement getStatement() { return statement; } + +public Expression getWhere() { +return where; +} } http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost
Repository: phoenix Updated Branches: refs/heads/master a6bf7350d -> 9461d0d6a http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java index a15ab35..21cbc2d 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java @@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan; import org.apache.phoenix.compile.RowProjector; import org.apache.phoenix.compile.StatementContext; import org.apache.phoenix.coprocessor.BaseScannerRegionObserver; +import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor; +import org.apache.phoenix.execute.visitor.ByteCountVisitor; +import org.apache.phoenix.execute.visitor.QueryPlanVisitor; +import org.apache.phoenix.execute.visitor.RowCountVisitor; import org.apache.phoenix.expression.Expression; import org.apache.phoenix.expression.OrderByExpression; import org.apache.phoenix.expression.aggregator.Aggregators; @@ -90,25 +94,30 @@ public class ClientAggregatePlan extends ClientProcessingPlan { @Override public Cost getCost() { -Long byteCount = null; -try { -byteCount = getEstimatedBytesToScan(); -} catch (SQLException e) { -// ignored. -} - -if (byteCount == null) { +Double outputBytes = this.accept(new ByteCountVisitor()); +Double inputRows = this.getDelegate().accept(new RowCountVisitor()); +Double rowWidth = this.accept(new AvgRowWidthVisitor()); +if (inputRows == null || outputBytes == null || rowWidth == null) { return Cost.UNKNOWN; } +double inputBytes = inputRows * rowWidth; +double rowsBeforeHaving = RowCountVisitor.aggregate( +RowCountVisitor.filter( +inputRows.doubleValue(), +RowCountVisitor.stripSkipScanFilter( +context.getScan().getFilter())), +groupBy); +double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, having); +double bytesBeforeHaving = rowWidth * rowsBeforeHaving; +double bytesAfterHaving = rowWidth * rowsAfterHaving; int parallelLevel = CostUtil.estimateParallelLevel( false, context.getConnection().getQueryServices()); -Cost cost = CostUtil.estimateAggregateCost(byteCount, -groupBy, clientAggregators.getEstimatedByteSize(), parallelLevel); +Cost cost = CostUtil.estimateAggregateCost( +inputBytes, bytesBeforeHaving, groupBy, parallelLevel); if (!orderBy.getOrderByExpressions().isEmpty()) { -double outputBytes = CostUtil.estimateAggregateOutputBytes( -byteCount, groupBy, clientAggregators.getEstimatedByteSize()); -Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, parallelLevel); +Cost orderByCost = CostUtil.estimateOrderByCost( +bytesAfterHaving, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return super.getCost().plus(cost); @@ -210,7 +219,16 @@ public class ClientAggregatePlan extends ClientProcessingPlan { public GroupBy getGroupBy() { return groupBy; } - + +@Override +public T accept(QueryPlanVisitor visitor) { +return visitor.visit(this); +} + +public Expression getHaving() { +return having; +} + private static class ClientGroupedAggregatingResultIterator extends BaseGroupedAggregatingResultIterator { private final List groupByExpressions; http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java -- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java index ac43919..75ba8f2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java @@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends DelegateQueryPlan { public FilterableStatement getStatement() { return statement; } + +public Expression getWhere() { +return where; +} } http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java