@Override public Double visit(ScanPlan plan) { try { Long b = plan.getEstimatedRowsToScan(); if (b != null) { return limit( filter( b.doubleValue(), stripSkipScanFilter(plan.getContext().getScan().getFilter())), plan.getLimit()); } } catch (SQLException e) { } return null; }
@Override public Cost getCost() { Long byteCount = null; try { byteCount = getEstimatedBytesToScan(); } catch (SQLException e) { // ignored. } Double outputBytes = this.accept(new ByteCountVisitor()); if (byteCount == null || outputBytes == null) { return Cost.UNKNOWN; } int parallelLevel = CostUtil.estimateParallelLevel( true, context.getConnection().getQueryServices()); Cost cost = new Cost(0, 0, byteCount); if (!orderBy.getOrderByExpressions().isEmpty()) { Cost orderByCost = CostUtil.estimateOrderByCost(byteCount, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return cost; }
private ScanPlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, OrderBy orderBy, ParallelIteratorFactory parallelIteratorFactory, boolean allowPageFilter, Expression dynamicFilter, QueryPlan dataPlan) throws SQLException { super(context, statement, table, projector, context.getBindManager().getParameterMetaData(), limit,offset, orderBy, GroupBy.EMPTY_GROUP_BY, parallelIteratorFactory != null ? parallelIteratorFactory : buildResultIteratorFactory(context, statement, table, orderBy, limit, offset, allowPageFilter), dynamicFilter, dataPlan); this.allowPageFilter = allowPageFilter; boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty(); if (isOrdered) { // TopN int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt( QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES); ScanRegionObserver.serializeIntoScan(context.getScan(), thresholdBytes, limit == null ? -1 : QueryUtil.getOffsetLimit(limit, offset), orderBy.getOrderByExpressions(), projector.getEstimatedRowByteSize()); } Integer perScanLimit = !allowPageFilter || isOrdered ? null : limit; perScanLimit = QueryUtil.getOffsetLimit(perScanLimit, offset); Pair<Long, Long> estimate = getEstimateOfDataSizeToScanIfWithinThreshold(context, table.getTable(), perScanLimit); this.isDataToScanWithinThreshold = estimate != null; this.isSerial = isSerial(context, statement, tableRef, orderBy, isDataToScanWithinThreshold); if (isSerial) { serialBytesEstimate = estimate.getFirst(); serialRowsEstimate = estimate.getSecond(); serialEstimateInfoTs = StatisticsUtil.NOT_STATS_BASED_TS; } }
@Override public Double visit(ScanPlan 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; }
TableRef tableRef = this.getTableRef(); PTable table = tableRef.getTable(); boolean isSalted = table.getBucketNum() != null; boolean isOffsetOnServer = isOffsetPossibleOnServer(context, orderBy, offset, isSalted, table.getIndexType()); } else if (useRoundRobinIterator()) {
@SuppressWarnings("deprecation") private static ParallelIteratorFactory buildResultIteratorFactory(StatementContext context, FilterableStatement statement, TableRef tableRef, OrderBy orderBy, Integer limit,Integer offset, boolean allowPageFilter) throws SQLException { if ((isSerial(context, statement, tableRef, orderBy, getEstimateOfDataSizeToScanIfWithinThreshold(context, tableRef.getTable(), QueryUtil.getOffsetLimit(limit, offset)) != null) || isRoundRobinPossible(orderBy, context) || isPacingScannersPossible(context))) { return ParallelIteratorFactory.NOOP_FACTORY; } ParallelIteratorFactory spoolingResultIteratorFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory( context.getConnection().getQueryServices()); // If we're doing an order by then we need the full result before we can do anything, // so we don't bother chunking it. If we're just doing a simple scan then we chunk // the scan to have a quicker initial response. if (!orderBy.getOrderByExpressions().isEmpty()) { return spoolingResultIteratorFactory; } else { return new ChunkedResultIterator.ChunkedResultIteratorFactory( spoolingResultIteratorFactory, context.getConnection().getMutationState(), tableRef); } }
assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); ScanPlan innerScanPlan=(ScanPlan)((TupleProjectionPlan)lhsOuterPlan.getDelegate()).getDelegate(); orderBy=innerScanPlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AGE")); assertTrue(innerScanPlan.getLimit().intValue() == 3); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("BID")); innerScanPlan=(ScanPlan)((TupleProjectionPlan)rhsOuterPlan.getDelegate()).getDelegate(); orderBy=innerScanPlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("CODE")); assertTrue(innerScanPlan.getLimit().intValue() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); innerScanPlan=(ScanPlan)((HashJoinPlan)((TupleProjectionPlan)lhsOuterPlan.getDelegate()).getDelegate()).getDelegate(); orderBy=innerScanPlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("B.CODE")); assertTrue(innerScanPlan.getLimit().intValue() == 3); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("AID")); innerScanPlan=(ScanPlan)((HashJoinPlan)((TupleProjectionPlan)rhsOuterPlan.getDelegate()).getDelegate()).getDelegate(); orderBy=innerScanPlan.getOrderBy(); assertTrue(orderBy.getOrderByExpressions().size() == 1); assertTrue(orderBy.getOrderByExpressions().get(0).toString().equals("C.REGION DESC")); assertTrue(innerScanPlan.getLimit().intValue() == 1);
? new AggregatePlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, groupBy, having, dataPlan) : new ScanPlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, allowPageFilter, dataPlan));
TableRef tableRef = this.getTableRef(); PTable table = tableRef.getTable(); boolean isSalted = table.getBucketNum() != null; boolean isOffsetOnServer = isOffsetPossibleOnServer(context, orderBy, offset, isSalted, table.getIndexType()); } else if (useRoundRobinIterator()) {
@Override public Double visit(ScanPlan 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; }
@SuppressWarnings("deprecation") private static ParallelIteratorFactory buildResultIteratorFactory(StatementContext context, FilterableStatement statement, TableRef tableRef, OrderBy orderBy, Integer limit,Integer offset, boolean allowPageFilter) throws SQLException { if ((isSerial(context, statement, tableRef, orderBy, getEstimateOfDataSizeToScanIfWithinThreshold(context, tableRef.getTable(), QueryUtil.getOffsetLimit(limit, offset)) != null) || isRoundRobinPossible(orderBy, context) || isPacingScannersPossible(context))) { return ParallelIteratorFactory.NOOP_FACTORY; } ParallelIteratorFactory spoolingResultIteratorFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory( context.getConnection().getQueryServices()); // If we're doing an order by then we need the full result before we can do anything, // so we don't bother chunking it. If we're just doing a simple scan then we chunk // the scan to have a quicker initial response. if (!orderBy.getOrderByExpressions().isEmpty()) { return spoolingResultIteratorFactory; } else { return new ChunkedResultIterator.ChunkedResultIteratorFactory( spoolingResultIteratorFactory, context.getConnection().getMutationState(), tableRef); } }
? new AggregatePlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, groupBy, having, dataPlan) : new ScanPlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, allowPageFilter, dataPlan));
@Override public Double visit(ScanPlan plan) { try { Long b = plan.getEstimatedRowsToScan(); if (b != null) { return limit( filter( b.doubleValue(), stripSkipScanFilter(plan.getContext().getScan().getFilter())), plan.getLimit()); } } catch (SQLException e) { } return null; }
private ScanPlan(StatementContext context, FilterableStatement statement, TableRef table, RowProjector projector, Integer limit, Integer offset, OrderBy orderBy, ParallelIteratorFactory parallelIteratorFactory, boolean allowPageFilter, Expression dynamicFilter, QueryPlan dataPlan) throws SQLException { super(context, statement, table, projector, context.getBindManager().getParameterMetaData(), limit,offset, orderBy, GroupBy.EMPTY_GROUP_BY, parallelIteratorFactory != null ? parallelIteratorFactory : buildResultIteratorFactory(context, statement, table, orderBy, limit, offset, allowPageFilter), dynamicFilter, dataPlan); this.allowPageFilter = allowPageFilter; boolean isOrdered = !orderBy.getOrderByExpressions().isEmpty(); if (isOrdered) { // TopN int thresholdBytes = context.getConnection().getQueryServices().getProps().getInt( QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, QueryServicesOptions.DEFAULT_SPOOL_THRESHOLD_BYTES); ScanRegionObserver.serializeIntoScan(context.getScan(), thresholdBytes, limit == null ? -1 : QueryUtil.getOffsetLimit(limit, offset), orderBy.getOrderByExpressions(), projector.getEstimatedRowByteSize()); } Integer perScanLimit = !allowPageFilter || isOrdered ? null : limit; perScanLimit = QueryUtil.getOffsetLimit(perScanLimit, offset); Pair<Long, Long> estimate = getEstimateOfDataSizeToScanIfWithinThreshold(context, table.getTable(), perScanLimit); this.isDataToScanWithinThreshold = estimate != null; this.isSerial = isSerial(context, statement, tableRef, orderBy, isDataToScanWithinThreshold); if (isSerial) { serialBytesEstimate = estimate.getFirst(); serialRowsEstimate = estimate.getSecond(); serialEstimateInfoTs = StatisticsUtil.NOT_STATS_BASED_TS; } }
TableRef tableRef = this.getTableRef(); PTable table = tableRef.getTable(); boolean isSalted = table.getBucketNum() != null; boolean isOffsetOnServer = isOffsetPossibleOnServer(context, orderBy, offset, isSalted, table.getIndexType()); } else if (useRoundRobinIterator()) {
@Override public Double visit(ScanPlan 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; }
@SuppressWarnings("deprecation") private static ParallelIteratorFactory buildResultIteratorFactory(StatementContext context, FilterableStatement statement, TableRef tableRef, OrderBy orderBy, Integer limit,Integer offset, boolean allowPageFilter) throws SQLException { if ((isSerial(context, statement, tableRef, orderBy, getEstimateOfDataSizeToScanIfWithinThreshold(context, tableRef.getTable(), QueryUtil.getOffsetLimit(limit, offset)) != null) || isRoundRobinPossible(orderBy, context) || isPacingScannersPossible(context))) { return ParallelIteratorFactory.NOOP_FACTORY; } ParallelIteratorFactory spoolingResultIteratorFactory = new SpoolingResultIterator.SpoolingResultIteratorFactory( context.getConnection().getQueryServices()); // If we're doing an order by then we need the full result before we can do anything, // so we don't bother chunking it. If we're just doing a simple scan then we chunk // the scan to have a quicker initial response. if (!orderBy.getOrderByExpressions().isEmpty()) { return spoolingResultIteratorFactory; } else { return new ChunkedResultIterator.ChunkedResultIteratorFactory( spoolingResultIteratorFactory, context.getConnection().getMutationState(), tableRef); } }
@Override public Cost getCost() { Long byteCount = null; try { byteCount = getEstimatedBytesToScan(); } catch (SQLException e) { // ignored. } Double outputBytes = this.accept(new ByteCountVisitor()); if (byteCount == null || outputBytes == null) { return Cost.UNKNOWN; } int parallelLevel = CostUtil.estimateParallelLevel( true, context.getConnection().getQueryServices()); Cost cost = new Cost(0, 0, byteCount); if (!orderBy.getOrderByExpressions().isEmpty()) { Cost orderByCost = CostUtil.estimateOrderByCost(byteCount, outputBytes, parallelLevel); cost = cost.plus(orderByCost); } return cost; }
plan = new SingleKeyQueryPlan(context, select, tableRef, projector, limit, offset, where, orderBy); } else { plan = new ScanPlan(context, select, tableRef, projector, limit, offset, orderBy, parallelIteratorFactory, allowPageFilter, dataPlan);
@Override public Double visit(ScanPlan plan) { try { Long b = plan.getEstimatedRowsToScan(); if (b != null) { return limit( filter( b.doubleValue(), stripSkipScanFilter(plan.getContext().getScan().getFilter())), plan.getLimit()); } } catch (SQLException e) { } return null; }