private HashJoinPlan(SelectStatement statement, QueryPlan plan, HashJoinInfo joinInfo, SubPlan[] subPlans, boolean recompileWhereClause, Map<ImmutableBytesPtr,ServerCache> dependencies) throws SQLException { super(plan); this.dependencies.putAll(dependencies); this.statement = statement; this.joinInfo = joinInfo; this.subPlans = subPlans; this.recompileWhereClause = recompileWhereClause; this.tableRefs = Sets.newHashSetWithExpectedSize(subPlans.length + plan.getSourceRefs().size()); this.tableRefs.addAll(plan.getSourceRefs()); this.hasSubPlansWithPersistentCache = false; for (SubPlan subPlan : subPlans) { tableRefs.addAll(subPlan.getInnerPlan().getSourceRefs()); if (subPlan instanceof HashSubPlan && ((HashSubPlan)subPlan).usePersistentCache) { this.hasSubPlansWithPersistentCache = true; } } QueryServices services = plan.getContext().getConnection().getQueryServices(); this.maxServerCacheTimeToLive = services.getProps().getInt( QueryServices.MAX_SERVER_CACHE_TIME_TO_LIVE_MS_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_TIME_TO_LIVE_MS); this.serverCacheLimit = services.getProps().getLong( QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_SIZE); }
@Override public ExplainPlan getExplainPlan() throws SQLException { List<String> planSteps = Lists.newArrayList(delegate.getExplainPlan().getPlanSteps()); int count = subPlans.length; for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPreSteps(this)); } for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPostSteps(this)); } if (joinInfo != null && joinInfo.getPostJoinFilterExpression() != null) { planSteps.add(" AFTER-JOIN SERVER FILTER BY " + joinInfo.getPostJoinFilterExpression().toString()); } if (joinInfo != null && joinInfo.getLimit() != null) { planSteps.add(" JOIN-SCANNER " + joinInfo.getLimit() + " ROW LIMIT"); } return new ExplainPlan(planSteps); }
dependencies.put(new ImmutableBytesPtr(result.getId()),result); subPlans[i].postProcess(result, this); } catch (InterruptedException e) { Thread.currentThread().interrupt();
dependencies.put(new ImmutableBytesPtr(result.getId()),result); subPlans[i].postProcess(result, this); } catch (InterruptedException e) { Thread.currentThread().interrupt();
dependencies.put(new ImmutableBytesPtr(result.getId()),result); subPlans[i].postProcess(result, this); } catch (InterruptedException e) { Thread.currentThread().interrupt();
for (int i = 0; i < subPlans.length; i++) { double lhsBytes = bytes; Double rhsRows = subPlans[i].getInnerPlan().accept(new RowCountVisitor()); Double rhsWidth = subPlans[i].getInnerPlan().accept(new AvgRowWidthVisitor()); if (rhsRows == null || rhsWidth == null) { return Cost.UNKNOWN; bytes = rowWidth * rows; cost = cost.plus(CostUtil.estimateHashJoinCost( lhsBytes, rhsBytes, bytes, subPlans[i].hasKeyRangeExpression(), parallelLevel)); rhsByteSum += rhsBytes; Cost rhsCost = Cost.ZERO; for (SubPlan subPlan : subPlans) { rhsCost = rhsCost.plus(subPlan.getInnerPlan().getCost());
for (int i = 0; i < subPlans.length; i++) { double lhsBytes = bytes; Double rhsRows = subPlans[i].getInnerPlan().accept(new RowCountVisitor()); Double rhsWidth = subPlans[i].getInnerPlan().accept(new AvgRowWidthVisitor()); if (rhsRows == null || rhsWidth == null) { return Cost.UNKNOWN; bytes = rowWidth * rows; cost = cost.plus(CostUtil.estimateHashJoinCost( lhsBytes, rhsBytes, bytes, subPlans[i].hasKeyRangeExpression(), parallelLevel)); rhsByteSum += rhsBytes; Cost rhsCost = Cost.ZERO; for (SubPlan subPlan : subPlans) { rhsCost = rhsCost.plus(subPlan.getInnerPlan().getCost());
@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(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; }
private void getEstimates() throws SQLException { getEstimatesCalled = true; for (SubPlan subPlan : subPlans) { if (subPlan.getInnerPlan().getEstimatedBytesToScan() == null || subPlan.getInnerPlan().getEstimatedRowsToScan() == null || subPlan.getInnerPlan().getEstimateInfoTimestamp() == null) { /* * If any of the sub plans doesn't have the estimate info available, then we don't * provide estimate for the overall plan */ estimatedBytes = null; estimatedRows = null; estimateInfoTs = null; break; } else { estimatedBytes = add(estimatedBytes, subPlan.getInnerPlan().getEstimatedBytesToScan()); estimatedRows = add(estimatedRows, subPlan.getInnerPlan().getEstimatedRowsToScan()); estimateInfoTs = getMin(estimateInfoTs, subPlan.getInnerPlan().getEstimateInfoTimestamp()); } } } }
private void getEstimates() throws SQLException { getEstimatesCalled = true; for (SubPlan subPlan : subPlans) { if (subPlan.getInnerPlan().getEstimatedBytesToScan() == null || subPlan.getInnerPlan().getEstimatedRowsToScan() == null || subPlan.getInnerPlan().getEstimateInfoTimestamp() == null) { /* * If any of the sub plans doesn't have the estimate info available, then we don't * provide estimate for the overall plan */ estimatedBytes = null; estimatedRows = null; estimateInfoTs = null; break; } else { estimatedBytes = add(estimatedBytes, subPlan.getInnerPlan().getEstimatedBytesToScan()); estimatedRows = add(estimatedRows, subPlan.getInnerPlan().getEstimatedRowsToScan()); estimateInfoTs = getMin(estimateInfoTs, subPlan.getInnerPlan().getEstimateInfoTimestamp()); } } } }
private HashJoinPlan(SelectStatement statement, QueryPlan plan, HashJoinInfo joinInfo, SubPlan[] subPlans, boolean recompileWhereClause, Map<ImmutableBytesPtr,ServerCache> dependencies) throws SQLException { super(plan); this.dependencies.putAll(dependencies); this.statement = statement; this.joinInfo = joinInfo; this.subPlans = subPlans; this.recompileWhereClause = recompileWhereClause; this.tableRefs = Sets.newHashSetWithExpectedSize(subPlans.length + plan.getSourceRefs().size()); this.tableRefs.addAll(plan.getSourceRefs()); this.hasSubPlansWithPersistentCache = false; for (SubPlan subPlan : subPlans) { tableRefs.addAll(subPlan.getInnerPlan().getSourceRefs()); if (subPlan instanceof HashSubPlan && ((HashSubPlan)subPlan).usePersistentCache) { this.hasSubPlansWithPersistentCache = true; } } QueryServices services = plan.getContext().getConnection().getQueryServices(); this.maxServerCacheTimeToLive = services.getProps().getInt( QueryServices.MAX_SERVER_CACHE_TIME_TO_LIVE_MS_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_TIME_TO_LIVE_MS); this.serverCacheLimit = services.getProps().getLong( QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_SIZE); }
private HashJoinPlan(SelectStatement statement, QueryPlan plan, HashJoinInfo joinInfo, SubPlan[] subPlans, boolean recompileWhereClause, Map<ImmutableBytesPtr,ServerCache> dependencies) throws SQLException { super(plan); this.dependencies.putAll(dependencies); this.statement = statement; this.joinInfo = joinInfo; this.subPlans = subPlans; this.recompileWhereClause = recompileWhereClause; this.tableRefs = Sets.newHashSetWithExpectedSize(subPlans.length + plan.getSourceRefs().size()); this.tableRefs.addAll(plan.getSourceRefs()); for (SubPlan subPlan : subPlans) { tableRefs.addAll(subPlan.getInnerPlan().getSourceRefs()); } QueryServices services = plan.getContext().getConnection().getQueryServices(); this.maxServerCacheTimeToLive = services.getProps().getInt( QueryServices.MAX_SERVER_CACHE_TIME_TO_LIVE_MS_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_TIME_TO_LIVE_MS); this.serverCacheLimit = services.getProps().getLong( QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, QueryServicesOptions.DEFAULT_MAX_SERVER_CACHE_SIZE); }
@Override public Double visit(HashJoinPlan plan) { Double lhsWidth = plan.getDelegate().accept(this); if (lhsWidth == null) { return null; } JoinTableNode.JoinType[] joinTypes = plan.getJoinInfo().getJoinTypes(); HashJoinPlan.SubPlan[] subPlans = plan.getSubPlans(); Double width = lhsWidth; for (int i = 0; i < joinTypes.length; i++) { Double rhsWidth = subPlans[i].getInnerPlan().accept(this); if (rhsWidth == null) { return null; } width = join(width, rhsWidth, joinTypes[i]); } return width; }
@Override public ExplainPlan getExplainPlan() throws SQLException { List<String> planSteps = Lists.newArrayList(delegate.getExplainPlan().getPlanSteps()); int count = subPlans.length; for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPreSteps(this)); } for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPostSteps(this)); } if (joinInfo != null && joinInfo.getPostJoinFilterExpression() != null) { planSteps.add(" AFTER-JOIN SERVER FILTER BY " + joinInfo.getPostJoinFilterExpression().toString()); } if (joinInfo != null && joinInfo.getLimit() != null) { planSteps.add(" JOIN-SCANNER " + joinInfo.getLimit() + " ROW LIMIT"); } return new ExplainPlan(planSteps); }
@Override public Double visit(HashJoinPlan plan) { Double lhsWidth = plan.getDelegate().accept(this); if (lhsWidth == null) { return null; } JoinTableNode.JoinType[] joinTypes = plan.getJoinInfo().getJoinTypes(); HashJoinPlan.SubPlan[] subPlans = plan.getSubPlans(); Double width = lhsWidth; for (int i = 0; i < joinTypes.length; i++) { Double rhsWidth = subPlans[i].getInnerPlan().accept(this); if (rhsWidth == null) { return null; } width = join(width, rhsWidth, joinTypes[i]); } return width; }
@Override public ExplainPlan getExplainPlan() throws SQLException { List<String> planSteps = Lists.newArrayList(delegate.getExplainPlan().getPlanSteps()); int count = subPlans.length; for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPreSteps(this)); } for (int i = 0; i < count; i++) { planSteps.addAll(subPlans[i].getPostSteps(this)); } if (joinInfo != null && joinInfo.getPostJoinFilterExpression() != null) { planSteps.add(" AFTER-JOIN SERVER FILTER BY " + joinInfo.getPostJoinFilterExpression().toString()); } if (joinInfo != null && joinInfo.getLimit() != null) { planSteps.add(" JOIN-SCANNER " + joinInfo.getLimit() + " ROW LIMIT"); } return new ExplainPlan(planSteps); }
@Override public ServerCache call() throws Exception { ServerCache cache = subPlans[index].execute(HashJoinPlan.this); return cache; }
@Override public ServerCache call() throws Exception { ServerCache cache = subPlans[index].execute(HashJoinPlan.this); return cache; }
for (int i = 0; i < subPlans.length; i++) { double lhsBytes = bytes; Double rhsRows = subPlans[i].getInnerPlan().accept(new RowCountVisitor()); Double rhsWidth = subPlans[i].getInnerPlan().accept(new AvgRowWidthVisitor()); if (rhsRows == null || rhsWidth == null) { return Cost.UNKNOWN; bytes = rowWidth * rows; cost = cost.plus(CostUtil.estimateHashJoinCost( lhsBytes, rhsBytes, bytes, subPlans[i].hasKeyRangeExpression(), parallelLevel)); rhsByteSum += rhsBytes; Cost rhsCost = Cost.ZERO; for (SubPlan subPlan : subPlans) { rhsCost = rhsCost.plus(subPlan.getInnerPlan().getCost());