@Override public Double visit(AggregatePlan plan) { try { Long b = plan.getEstimatedRowsToScan(); if (b != null) { return limit( filter( aggregate( filter( b.doubleValue(), stripSkipScanFilter( plan.getContext().getScan().getFilter())), plan.getGroupBy()), plan.getHaving()), plan.getLimit()); } } catch (SQLException e) { } return null; }
? new SerialIterators(this, null, null, wrapParallelIteratorFactory(), scanGrouper, scan, caches, dataPlan) : new ParallelIterators(this, null, wrapParallelIteratorFactory(), scan, false, caches, dataPlan); estimatedRows = iterators.getEstimatedRowCount(); estimatedSize = iterators.getEstimatedByteCount(); aggResultIterator = new UngroupedAggregatingResultIterator(new ConcatResultIterator(iterators), aggregators); } else if (groupBy.isOrderPreserving() && !(this.getTableRef().getTable().getBucketNum() != null || this.getTableRef().getTable().getIndexType() == IndexType.LOCAL)) { aggResultIterator = new RowKeyOrderedAggregateResultIterator(iterators, aggregators); } else { aggResultIterator = new GroupedAggregatingResultIterator( new MergeSortRowKeyResultIterator(iterators, 0, this.getOrderBy() == OrderBy.REV_ROW_KEY_ORDER_BY),aggregators); aggResultIterator = new DistinctAggregatingResultIterator(aggResultIterator, getProjector());
@Override public Cost getCost() { Double outputBytes = this.accept(new ByteCountVisitor()); Double rowWidth = this.accept(new AvgRowWidthVisitor()); Long inputRows = null; try { inputRows = getEstimatedRowsToScan(); } catch (SQLException e) {
@Override public Double visit(AggregatePlan plan) { try { Long byteCount = plan.getEstimatedBytesToScan(); Long rowCount = plan.getEstimatedRowsToScan(); if (byteCount != null && rowCount != null) { if (byteCount == 0) { return 0.0; } if (rowCount != 0) { return ((double) byteCount) / rowCount; } } } catch (SQLException e) { } return null; }
@Override public Double visit(HashJoinPlan plan) { try { QueryPlan lhsPlan = plan.getDelegate(); Long b = lhsPlan.getEstimatedRowsToScan(); if (b == null) { return null; } Double rows = filter(b.doubleValue(), stripSkipScanFilter(lhsPlan.getContext().getScan().getFilter())); JoinTableNode.JoinType[] joinTypes = plan.getJoinInfo().getJoinTypes(); HashJoinPlan.SubPlan[] subPlans = plan.getSubPlans(); for (int i = 0; i < joinTypes.length; i++) { Double rhsRows = subPlans[i].getInnerPlan().accept(this); if (rhsRows == null) { return null; } rows = join(rows, rhsRows.doubleValue(), joinTypes[i]); } if (lhsPlan instanceof AggregatePlan) { AggregatePlan aggPlan = (AggregatePlan) lhsPlan; rows = filter(aggregate(rows, aggPlan.getGroupBy()), aggPlan.getHaving()); } return limit(rows, lhsPlan.getLimit()); } catch (SQLException e) { } return null; }
assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); AggregatePlan innerAggregatePlan=(AggregatePlan)((TupleProjectionPlan)lhsOuterPlan.getDelegate()).getDelegate(); orderBy=innerAggregatePlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("SUM(AGE)")); assertTrue(innerAggregatePlan.getLimit().intValue() == 3); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("BID")); innerAggregatePlan=(AggregatePlan)((TupleProjectionPlan)rhsOuterPlan.getDelegate()).getDelegate(); orderBy=innerAggregatePlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("SUM(CODE)")); assertTrue(innerAggregatePlan.getLimit().intValue() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); innerAggregatePlan=(AggregatePlan)((HashJoinPlan)((TupleProjectionPlan)lhsOuterPlan.getDelegate()).getDelegate()).getDelegate(); orderBy=innerAggregatePlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("SUM(B.CODE)")); assertTrue(innerAggregatePlan.getLimit().intValue() == 3); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); innerAggregatePlan=(AggregatePlan)((HashJoinPlan)((TupleProjectionPlan)rhsOuterPlan.getDelegate()).getDelegate()).getDelegate(); orderBy=innerAggregatePlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("SUM(C.REGION) DESC")); assertTrue(innerAggregatePlan.getLimit().intValue() == 2); orderBy=innerAggregatePlan.getOrderBy();
final QueryPlan aggPlan = new AggregatePlan(context, select, dataPlan.getTableRef(), projector, null, null, OrderBy.EMPTY_ORDER_BY, null, GroupBy.EMPTY_GROUP_BY, null, dataPlan); return new ServerSelectDeleteMutationPlan(dataPlan, connection, aggPlan, projector, maxSize, maxSizeBytes);
private ParallelIteratorFactory wrapParallelIteratorFactory () { ParallelIteratorFactory innerFactory; QueryServices services = context.getConnection().getQueryServices(); if (groupBy.isEmpty() || groupBy.isOrderPreserving()) { if (ScanUtil.isPacingScannersPossible(context)) { innerFactory = ParallelIteratorFactory.NOOP_FACTORY; } else { innerFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory(services); } } else { innerFactory = new OrderingResultIteratorFactory(services,this.getOrderBy()); } if (parallelIteratorFactory == null) { return innerFactory; } // wrap any existing parallelIteratorFactory return new WrappingResultIteratorFactory(innerFactory, parallelIteratorFactory); }
private static Expressions compileStatement(String query, List<Object> binds) throws SQLException { PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query); TestUtil.bindParams(pstmt, binds); QueryPlan plan = pstmt.compileQuery(); assertTrue(plan instanceof AggregatePlan); Filter filter = plan.getContext().getScan().getFilter(); assertTrue(filter == null || filter instanceof BooleanExpressionFilter); BooleanExpressionFilter boolFilter = (BooleanExpressionFilter)filter; AggregatePlan aggPlan = (AggregatePlan)plan; return new Expressions(boolFilter == null ? null : boolFilter.getExpression(), aggPlan.getHaving()); }
double rowsBeforeHaving = RowCountVisitor.aggregate(rows, aggPlan.getGroupBy()); double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, aggPlan.getHaving()); double bytesBeforeHaving = rowWidth * rowsBeforeHaving; double bytesAfterHaving = rowWidth * rowsAfterHaving; Cost aggCost = CostUtil.estimateAggregateCost( bytes, bytesBeforeHaving, aggPlan.getGroupBy(), parallelLevel); cost = cost.plus(aggCost); rows = rowsAfterHaving;
@Override public Double visit(AggregatePlan plan) { try { Long byteCount = plan.getEstimatedBytesToScan(); Long rowCount = plan.getEstimatedRowsToScan(); if (byteCount != null && rowCount != null) { if (byteCount == 0) { return 0.0; } if (rowCount != 0) { return ((double) byteCount) / rowCount; } } } catch (SQLException e) { } return null; }
final QueryPlan aggPlan = new AggregatePlan(context, select, statementContext.getCurrentTable(), aggProjector, null,null, OrderBy.EMPTY_ORDER_BY, null, GroupBy.EMPTY_GROUP_BY, null, originalQueryPlan); return new ServerUpsertSelectMutationPlan(queryPlan, tableRef, originalQueryPlan, context, connection, scan, aggPlan, aggProjector, maxSize, maxSizeBytes);
private ParallelIteratorFactory wrapParallelIteratorFactory () { ParallelIteratorFactory innerFactory; QueryServices services = context.getConnection().getQueryServices(); if (groupBy.isEmpty() || groupBy.isOrderPreserving()) { if (ScanUtil.isPacingScannersPossible(context)) { innerFactory = ParallelIteratorFactory.NOOP_FACTORY; } else { innerFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory(services); } } else { innerFactory = new OrderingResultIteratorFactory(services,this.getOrderBy()); } if (parallelIteratorFactory == null) { return innerFactory; } // wrap any existing parallelIteratorFactory return new WrappingResultIteratorFactory(innerFactory, parallelIteratorFactory); }
@Override public Double visit(AggregatePlan plan) { try { Long b = plan.getEstimatedRowsToScan(); if (b != null) { return limit( filter( aggregate( filter( b.doubleValue(), stripSkipScanFilter( plan.getContext().getScan().getFilter())), plan.getGroupBy()), plan.getHaving()), plan.getLimit()); } } catch (SQLException e) { } return null; }
? new SerialIterators(this, null, null, wrapParallelIteratorFactory(), scanGrouper, scan, caches, dataPlan) : new ParallelIterators(this, null, wrapParallelIteratorFactory(), scan, false, caches, dataPlan); estimatedRows = iterators.getEstimatedRowCount(); estimatedSize = iterators.getEstimatedByteCount(); aggResultIterator = new UngroupedAggregatingResultIterator(new ConcatResultIterator(iterators), aggregators); } else if (groupBy.isOrderPreserving() && !(this.getTableRef().getTable().getBucketNum() != null || this.getTableRef().getTable().getIndexType() == IndexType.LOCAL)) { aggResultIterator = new RowKeyOrderedAggregateResultIterator(iterators, aggregators); } else { aggResultIterator = new GroupedAggregatingResultIterator( new MergeSortRowKeyResultIterator(iterators, 0, this.getOrderBy() == OrderBy.REV_ROW_KEY_ORDER_BY),aggregators); aggResultIterator = new DistinctAggregatingResultIterator(aggResultIterator, getProjector());
@Override public Double visit(HashJoinPlan plan) { try { QueryPlan lhsPlan = plan.getDelegate(); Long b = lhsPlan.getEstimatedRowsToScan(); if (b == null) { return null; } Double rows = filter(b.doubleValue(), stripSkipScanFilter(lhsPlan.getContext().getScan().getFilter())); JoinTableNode.JoinType[] joinTypes = plan.getJoinInfo().getJoinTypes(); HashJoinPlan.SubPlan[] subPlans = plan.getSubPlans(); for (int i = 0; i < joinTypes.length; i++) { Double rhsRows = subPlans[i].getInnerPlan().accept(this); if (rhsRows == null) { return null; } rows = join(rows, rhsRows.doubleValue(), joinTypes[i]); } if (lhsPlan instanceof AggregatePlan) { AggregatePlan aggPlan = (AggregatePlan) lhsPlan; rows = filter(aggregate(rows, aggPlan.getGroupBy()), aggPlan.getHaving()); } return limit(rows, lhsPlan.getLimit()); } catch (SQLException e) { } return null; }
@Override public Double visit(AggregatePlan plan) { try { Long byteCount = plan.getEstimatedBytesToScan(); Long rowCount = plan.getEstimatedRowsToScan(); if (byteCount != null && rowCount != null) { if (byteCount == 0) { return 0.0; } if (rowCount != 0) { return ((double) byteCount) / rowCount; } } } catch (SQLException e) { } return null; }
@Override public Cost getCost() { Double outputBytes = this.accept(new ByteCountVisitor()); Double rowWidth = this.accept(new AvgRowWidthVisitor()); Long inputRows = null; try { inputRows = getEstimatedRowsToScan(); } catch (SQLException e) {
parallelIteratorFactory) : (select.isAggregate() || select.isDistinct() ? new AggregatePlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, groupBy, having, dataPlan) : new ScanPlan(context, select, tableRef, projector, limit, offset, orderBy,
private ParallelIteratorFactory wrapParallelIteratorFactory () { ParallelIteratorFactory innerFactory; QueryServices services = context.getConnection().getQueryServices(); if (groupBy.isEmpty() || groupBy.isOrderPreserving()) { if (ScanUtil.isPacingScannersPossible(context)) { innerFactory = ParallelIteratorFactory.NOOP_FACTORY; } else { innerFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory(services); } } else { innerFactory = new OrderingResultIteratorFactory(services,this.getOrderBy()); } if (parallelIteratorFactory == null) { return innerFactory; } // wrap any existing parallelIteratorFactory return new WrappingResultIteratorFactory(innerFactory, parallelIteratorFactory); }