use of io.crate.profile.Timer in project crate by crate.
the class ExplainPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
if (context != null) {
assert subPlan instanceof LogicalPlan : "subPlan must be a LogicalPlan";
LogicalPlan plan = (LogicalPlan) subPlan;
/**
* EXPLAIN ANALYZE does not support analyzing {@link io.crate.planner.MultiPhasePlan}s
*/
if (plan.dependencies().isEmpty()) {
UUID jobId = plannerContext.jobId();
BaseResultReceiver resultReceiver = new BaseResultReceiver();
RowConsumer noopRowConsumer = new RowConsumerToResultReceiver(resultReceiver, 0, t -> {
});
Timer timer = context.createTimer(Phase.Execute.name());
timer.start();
NodeOperationTree operationTree = LogicalPlanner.getNodeOperationTree(plan, dependencies, plannerContext, params, subQueryResults);
resultReceiver.completionFuture().whenComplete(createResultConsumer(dependencies, consumer, jobId, timer, operationTree));
LogicalPlanner.executeNodeOpTree(dependencies, plannerContext.transactionContext(), jobId, noopRowConsumer, true, operationTree);
} else {
consumer.accept(null, new UnsupportedOperationException("EXPLAIN ANALYZE does not support profiling multi-phase plans, " + "such as queries with scalar subselects."));
}
} else {
if (subPlan instanceof LogicalPlan) {
PrintContext printContext = new PrintContext();
((LogicalPlan) subPlan).print(printContext);
consumer.accept(InMemoryBatchIterator.of(new Row1(printContext.toString()), SENTINEL), null);
} else if (subPlan instanceof CopyFromPlan) {
ExecutionPlan executionPlan = CopyFromPlan.planCopyFromExecution(((CopyFromPlan) subPlan).copyFrom(), dependencies.clusterService().state().nodes(), plannerContext, params, subQueryResults);
String planAsJson = DataTypes.STRING.implicitCast(PlanPrinter.objectMap(executionPlan));
consumer.accept(InMemoryBatchIterator.of(new Row1(planAsJson), SENTINEL), null);
} else {
consumer.accept(InMemoryBatchIterator.of(new Row1("EXPLAIN not supported for " + subPlan.getClass().getSimpleName()), SENTINEL), null);
}
}
}
use of io.crate.profile.Timer in project crate by crate.
the class ExplainStatementAnalyzer method analyze.
public ExplainAnalyzedStatement analyze(Explain node, Analysis analysis) {
Statement statement = node.getStatement();
statement.accept(CHECK_VISITOR, null);
final AnalyzedStatement subStatement;
ProfilingContext profilingContext;
if (node.isAnalyze()) {
profilingContext = new ProfilingContext(List.of());
Timer timer = profilingContext.createAndStartTimer(ExplainPlan.Phase.Analyze.name());
subStatement = analyzer.analyzedStatement(statement, analysis);
profilingContext.stopTimerAndStoreDuration(timer);
} else {
profilingContext = null;
subStatement = analyzer.analyzedStatement(statement, analysis);
}
String columnName = SqlFormatter.formatSql(node);
return new ExplainAnalyzedStatement(columnName, subStatement, profilingContext);
}
use of io.crate.profile.Timer in project crate by crate.
the class Planner method visitExplainStatement.
@Override
public Plan visitExplainStatement(ExplainAnalyzedStatement explainAnalyzedStatement, PlannerContext context) {
ProfilingContext ctx = explainAnalyzedStatement.context();
if (ctx == null) {
return new ExplainPlan(explainAnalyzedStatement.statement().accept(this, context), null);
} else {
Timer timer = ctx.createAndStartTimer(ExplainPlan.Phase.Plan.name());
Plan subPlan = explainAnalyzedStatement.statement().accept(this, context);
ctx.stopTimerAndStoreDuration(timer);
return new ExplainPlan(subPlan, ctx);
}
}
Aggregations