private OSelectExecutionPlan createExecutionPlan(OResult nextItem, OCommandContext ctx) { OSelectExecutionPlan plan = new OSelectExecutionPlan(ctx); plan.chain(new AbstractExecutionStep(ctx, profilingEnabled) { boolean executed = false; @Override public OResultSet syncPull(OCommandContext ctx, int nRecords) throws OTimeoutException { OInternalResultSet result = new OInternalResultSet(); if (!executed) { result.add(copy(nextItem)); executed = true; } return result; } private OResult copy(OResult nextItem) { OResultInternal result = new OResultInternal(); for (String prop : nextItem.getPropertyNames()) { result.setProperty(prop, nextItem.getProperty(prop)); } for (String md : nextItem.getMetadataKeys()) { result.setMetadata(md, nextItem.getMetadata(md)); } return result; } }); subSteps.stream().forEach(step -> plan.chain(step)); return plan; }
@Override public boolean canBeCached() { return super.canBeCached(); } }
@Override public OInternalExecutionPlan copy(OCommandContext ctx) { OSelectExecutionPlan copy = new OSelectExecutionPlan(ctx); copyOn(copy, ctx); return copy; }
for (OExecutionStep step : localSteps.getSteps()) { result.chain((OExecutionStepInternal) step); OSelectExecutionPlan subPlan = info.distributedFetchExecutionPlans.get(node); DistributedExecutionStep step = new DistributedExecutionStep(subPlan, node, ctx, enableProfiling); result.chain(step); } else { DistributedExecutionStep step = new DistributedExecutionStep(entry.getValue(), entry.getKey(), ctx, enableProfiling); OSelectExecutionPlan subPlan = new OSelectExecutionPlan(ctx); subPlan.chain(step); subPlans.add(subPlan); result.chain(new ParallelExecStep((List) subPlans, ctx, enableProfiling));
private void handleFindReferences(OSelectExecutionPlan plan, OCommandContext ctx, boolean profilingEnabled) { List<OIdentifier> classes = targets == null ? null : targets.stream().filter(x -> x instanceof OIdentifier).map(y -> ((OIdentifier) y)).collect(Collectors.toList()); List<OCluster> clusters = targets == null ? null : targets.stream().filter(x -> x instanceof OCluster).map(y -> ((OCluster) y)).collect(Collectors.toList()); plan.chain(new FindReferencesStep(classes, clusters, ctx, profilingEnabled)); }
public OResult serialize() { OResultInternal result = new OResultInternal(); result.setProperty("type", "QueryExecutionPlan"); result.setProperty(JAVA_TYPE, getClass().getName()); result.setProperty("cost", getCost()); result.setProperty("prettyPrint", prettyPrint(0, 2)); result.setProperty("steps", steps == null ? null : steps.stream().map(x -> x.serialize()).collect(Collectors.toList())); return result; }
OSelectExecutionPlan stubPlan = new OSelectExecutionPlan(ctx); boolean prevCreatedDist = info.distributedPlanCreated; info.distributedPlanCreated = true; //little hack, check this!!! handleLet(stubPlan, info, ctx, profilingEnabled); for (OExecutionStep step : stubPlan.getSteps()) { result.add((OExecutionStepInternal) step);
OSelectExecutionPlan result = new OSelectExecutionPlan(ctx); if (useCache && !enableProfiling && statement.executinPlanCanBeCached() && result.canBeCached() && OExecutionPlanCache.getLastInvalidation(db) < planningStart) { OExecutionPlanCache.put(statement.getOriginalStatement(), result, (ODatabaseDocumentInternal) ctx.getDatabase());
private boolean matchesPattern(OResult nextItem, OCommandContext ctx) { OSelectExecutionPlan plan = createExecutionPlan(nextItem, ctx); try (OResultSet rs = plan.fetchNext(1)) { return rs.hasNext(); } }
@Override public OResult toResult() { OResultInternal res = (OResultInternal) super.toResult(); res.setProperty("type", "UpdateExecutionPlan"); return res; }
@Override public void reset(OCommandContext ctx) { result.clear(); next = 0; super.reset(ctx); executeInternal(); }
public OInternalExecutionPlan createExecutionPlan(OCommandContext ctx, boolean enableProfiling) { OSelectExecutionPlan plan = new OSelectExecutionPlan(ctx); handleRidSource(plan, ctx, enableProfiling); handleSubQuerySource(plan, ctx, enableProfiling); handleFindReferences(plan, ctx, enableProfiling); return plan; }
@Override public OInternalExecutionPlan copy(OCommandContext ctx) { OInsertExecutionPlan copy = new OInsertExecutionPlan(ctx); super.copyOn(copy, ctx); return copy; }
@Override public String prettyPrint(int depth, int indent) { StringBuilder builder = new StringBuilder(); String ind = OExecutionStepInternal.getIndent(depth, indent); builder.append(ind); builder.append("+ EXECUTE ON NODE " + nodeName + "----------- \n"); builder.append(subExecuitonPlan.prettyPrint(depth + 1, indent)); builder.append(" ------------------------------------------- \n"); builder.append(" |\n"); builder.append(" V\n"); return builder.toString(); } }
protected void copyOn(OSelectExecutionPlan copy, OCommandContext ctx) { OExecutionStep lastStep = null; for (OExecutionStep step : this.steps) { OExecutionStepInternal newStep = (OExecutionStepInternal) ((OExecutionStepInternal) step).copy(ctx); newStep.setPrevious((OExecutionStepInternal) lastStep); if (lastStep != null) { ((OExecutionStepInternal) lastStep).setNext(newStep); } lastStep = newStep; copy.getSteps().add(newStep); } copy.lastStep = copy.steps.size() == 0 ? null : copy.steps.get(copy.steps.size() - 1); copy.location = this.location; copy.statement = this.statement; }
public static void handleUnwind(OSelectExecutionPlan result, QueryPlanningInfo info, OCommandContext ctx, boolean profilingEnabled) { if (info.unwind != null) { result.chain(new UnwindStep(info.unwind, ctx, profilingEnabled)); } }
@Override public OResult toResult() { OResultInternal result = new OResultInternal(); result.setProperty("type", "QueryExecutionPlan"); result.setProperty(JAVA_TYPE, getClass().getName()); result.setProperty("cost", getCost()); result.setProperty("prettyPrint", prettyPrint(0, 2)); result.setProperty("steps", steps == null ? null : steps.stream().map(x -> x.toResult()).collect(Collectors.toList())); return result; }
public void executeInternal() throws OCommandExecutionException { while (true) { OResultSet nextBlock = super.fetchNext(100); if (!nextBlock.hasNext()) { return; } while (nextBlock.hasNext()) { result.add(nextBlock.next()); } } }
@Override public OResult toResult() { OResultInternal res = (OResultInternal) super.toResult(); res.setProperty("type", "InsertExecutionPlan"); return res; }
@Override public void reset(OCommandContext ctx) { result.clear(); next = 0; super.reset(ctx); executeInternal(); }