Skip to content

Commit

Permalink
Skip subquery plan if subqueryExpression List is empty for efficiency (
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelly authored Jan 10, 2025
1 parent e92be6f commit bdf36ba
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,39 @@ public PlanBuilder handleSubqueries(

public PlanBuilder handleSubqueries(
PlanBuilder builder, Expression expression, Analysis.SubqueryAnalysis subqueries) {
for (Cluster<InPredicate> cluster :
cluster(
builder.getScope(),
selectSubqueries(builder, expression, subqueries.getInPredicatesSubqueries()))) {
builder = planInPredicate(builder, cluster, subqueries);
}
for (Cluster<SubqueryExpression> cluster :
cluster(
builder.getScope(),
selectSubqueries(builder, expression, subqueries.getSubqueries()))) {
builder = planScalarSubquery(builder, cluster);
List<InPredicate> inPredicates = subqueries.getInPredicatesSubqueries();
if (!inPredicates.isEmpty()) {
for (Cluster<InPredicate> cluster :
cluster(builder.getScope(), selectSubqueries(builder, expression, inPredicates))) {
builder = planInPredicate(builder, cluster, subqueries);
}
}
for (Cluster<ExistsPredicate> cluster :
cluster(
builder.getScope(),
selectSubqueries(builder, expression, subqueries.getExistsSubqueries()))) {
builder = planExists(builder, cluster);

List<SubqueryExpression> scalarSubqueries = subqueries.getSubqueries();
if (!scalarSubqueries.isEmpty()) {
for (Cluster<SubqueryExpression> cluster :
cluster(builder.getScope(), selectSubqueries(builder, expression, scalarSubqueries))) {
builder = planScalarSubquery(builder, cluster);
}
}
for (Cluster<QuantifiedComparisonExpression> cluster :
cluster(
builder.getScope(),
selectSubqueries(
builder, expression, subqueries.getQuantifiedComparisonSubqueries()))) {
builder = planQuantifiedComparison(builder, cluster, subqueries);

List<ExistsPredicate> existsPredicates = subqueries.getExistsSubqueries();
if (!existsPredicates.isEmpty()) {
for (Cluster<ExistsPredicate> cluster :
cluster(builder.getScope(), selectSubqueries(builder, expression, existsPredicates))) {
builder = planExists(builder, cluster);
}
}

List<QuantifiedComparisonExpression> quantifiedComparisons =
subqueries.getQuantifiedComparisonSubqueries();
if (!quantifiedComparisons.isEmpty()) {
for (Cluster<QuantifiedComparisonExpression> cluster :
cluster(
builder.getScope(), selectSubqueries(builder, expression, quantifiedComparisons))) {
builder = planQuantifiedComparison(builder, cluster, subqueries);
}
}
return builder;
}

Expand Down

0 comments on commit bdf36ba

Please sign in to comment.