use of io.crate.planner.SubqueryPlanner in project crate by crate.
the class LogicalPlanner method planSubSelect.
public LogicalPlan planSubSelect(SelectSymbol selectSymbol, PlannerContext plannerContext) {
CoordinatorTxnCtx txnCtx = plannerContext.transactionContext();
AnalyzedRelation relation = selectSymbol.relation();
final int fetchSize;
final java.util.function.Function<LogicalPlan, LogicalPlan> maybeApplySoftLimit;
if (selectSymbol.getResultType() == SINGLE_COLUMN_SINGLE_VALUE) {
// SELECT (SELECT foo FROM t)
// ^^^^^^^^^^^^^^^^^
// The subquery must return at most 1 row, if more than 1 row is returned semantics require us to throw an error.
// So we limit the query to 2 if there is no limit to avoid retrieval of many rows while being able to validate max1row
fetchSize = 2;
maybeApplySoftLimit = plan -> new Limit(plan, Literal.of(2L), Literal.of(0L));
} else {
fetchSize = 0;
maybeApplySoftLimit = plan -> plan;
}
PlannerContext subSelectPlannerContext = PlannerContext.forSubPlan(plannerContext, fetchSize);
SubqueryPlanner subqueryPlanner = new SubqueryPlanner(s -> planSubSelect(s, subSelectPlannerContext));
var planBuilder = new PlanBuilder(subqueryPlanner, txnCtx, tableStats, subSelectPlannerContext.params());
LogicalPlan plan = relation.accept(planBuilder, relation.outputs());
plan = tryOptimizeForInSubquery(selectSymbol, relation, plan);
LogicalPlan optimizedPlan = optimizer.optimize(maybeApplySoftLimit.apply(plan), tableStats, txnCtx);
return new RootRelationBoundary(optimizedPlan);
}
use of io.crate.planner.SubqueryPlanner in project crate by crate.
the class UpdatePlanner method plan.
public static Plan plan(AnalyzedUpdateStatement update, PlannerContext plannerCtx, SubqueryPlanner subqueryPlanner) {
if (update.outputs() != null && !plannerCtx.clusterState().getNodes().getMinNodeVersion().onOrAfter(Version.V_4_2_0)) {
throw new UnsupportedFeatureException(RETURNING_VERSION_ERROR_MSG);
}
AbstractTableRelation<?> table = update.table();
Plan plan;
if (table instanceof DocTableRelation) {
DocTableRelation docTable = (DocTableRelation) table;
plan = plan(docTable, update.assignmentByTargetCol(), update.query(), plannerCtx, update.outputs());
} else {
plan = new Update((plannerContext, params, subQueryValues) -> sysUpdate(plannerContext, (TableRelation) table, update.assignmentByTargetCol(), update.query(), params, subQueryValues, update.outputs()));
}
Map<LogicalPlan, SelectSymbol> subQueries = subqueryPlanner.planSubQueries(update);
return MultiPhasePlan.createIfNeeded(plan, subQueries);
}
Aggregations