You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/08/04 03:15:13 UTC
[shardingsphere] branch master updated: Reduce invocation of
getSubquerySegments in SelectStatementContext (#11622)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b9b8e91 Reduce invocation of getSubquerySegments in SelectStatementContext (#11622)
b9b8e91 is described below
commit b9b8e91c1f8bf2092140aed69ee327de6da92bc1
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Wed Aug 4 11:14:30 2021 +0800
Reduce invocation of getSubquerySegments in SelectStatementContext (#11622)
---
.../binder/statement/dml/SelectStatementContext.java | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index 5c5c76c..77ac0df 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -38,6 +38,7 @@ import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ExpressionOrderByItemSegment;
@@ -93,9 +94,10 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
this.orderByContext = orderByContext;
this.projectionsContext = projectionsContext;
this.paginationContext = paginationContext;
- containsSubquery = containsSubquery();
+ Collection<SubquerySegment> subquerySegments = SubqueryExtractUtil.getSubquerySegments(getSqlStatement());
+ containsSubquery = !subquerySegments.isEmpty();
generateOrderByStartIndex = generateOrderByStartIndex();
- containsSubqueyAggregation = containsSubqueyAggregation();
+ containsSubqueyAggregation = containsSubqueryAggregation(subquerySegments);
}
public SelectStatementContext(final Map<String, ShardingSphereMetaData> metaDataMap, final List<Object> parameters, final SelectStatement sqlStatement, final String defaultSchemaName) {
@@ -106,9 +108,10 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
orderByContext = new OrderByContextEngine().createOrderBy(schema, sqlStatement, groupByContext);
projectionsContext = new ProjectionsContextEngine(schema).createProjectionsContext(getFromSimpleTableSegments(), getSqlStatement().getProjections(), groupByContext, orderByContext);
paginationContext = new PaginationContextEngine().createPaginationContext(sqlStatement, projectionsContext, parameters);
- containsSubquery = containsSubquery();
+ Collection<SubquerySegment> subquerySegments = SubqueryExtractUtil.getSubquerySegments(getSqlStatement());
+ containsSubquery = !subquerySegments.isEmpty();
generateOrderByStartIndex = generateOrderByStartIndex();
- containsSubqueyAggregation = containsSubqueyAggregation();
+ containsSubqueyAggregation = containsSubqueryAggregation(subquerySegments);
}
private ShardingSphereSchema getSchema(final Map<String, ShardingSphereMetaData> metaDataMap, final String defaultSchemaName) {
@@ -120,13 +123,8 @@ public final class SelectStatementContext extends CommonSQLStatementContext<Sele
return metaData.getSchema();
}
- private boolean containsSubquery() {
- return !SubqueryExtractUtil.getSubquerySegments(getSqlStatement()).isEmpty();
- }
-
- private boolean containsSubqueyAggregation() {
- return SubqueryExtractUtil.getSubquerySegments(getSqlStatement()).stream().flatMap(each
- -> each.getSelect().getProjections().getProjections().stream()).anyMatch(each -> each instanceof AggregationProjectionSegment);
+ private boolean containsSubqueryAggregation(final Collection<SubquerySegment> subquerySegments) {
+ return subquerySegments.stream().flatMap(each -> each.getSelect().getProjections().getProjections().stream()).anyMatch(each -> each instanceof AggregationProjectionSegment);
}
private int generateOrderByStartIndex() {