You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/07/07 16:13:03 UTC
[shardingsphere] branch master updated: Avoid to call
SQLUtil.getExactlyValue out of parser module to enhance performance
(#11206)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 54aa29c Avoid to call SQLUtil.getExactlyValue out of parser module to enhance performance (#11206)
54aa29c is described below
commit 54aa29c2a3650dee0a154cfbec2a80a454812532
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Jul 8 00:12:34 2021 +0800
Avoid to call SQLUtil.getExactlyValue out of parser module to enhance performance (#11206)
* Avoid use String.format to enhance the performance
* Avoid to call SQLUtil.getExactlyValue out of parser module to enhance performance
---
.../segment/select/orderby/engine/OrderByContextEngine.java | 12 +++++++-----
.../parser/sql/common/value/identifier/IdentifierValue.java | 7 ++++---
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
index 519e5be..a98dee9 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/select/orderby/engine/OrderByContextEngine.java
@@ -17,15 +17,13 @@
package org.apache.shardingsphere.infra.binder.segment.select.orderby.engine;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
import org.apache.shardingsphere.infra.binder.segment.select.groupby.GroupByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByContext;
import org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.constant.OrderDirection;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
@@ -39,6 +37,10 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+
/**
* Order by context engine.
*/
@@ -77,7 +79,7 @@ public final class OrderByContextEngine {
private OrderByContext getDefaultOrderByContextWithoutOrderBy(final GroupByContext groupByContext) {
return new OrderByContext(groupByContext.getItems(), !groupByContext.getItems().isEmpty());
}
-
+
private OrderByContext createOrderByContextForDistinctRowWithoutGroupBy(final SelectStatement selectStatement, final GroupByContext groupByContext) {
if (groupByContext.getItems().isEmpty() && selectStatement.getProjections().isDistinctRow()) {
int index = 0;
@@ -109,7 +111,7 @@ public final class OrderByContextEngine {
return Optional.empty();
}
for (String each : tableMetaData.getPrimaryKeyColumns()) {
- ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue(each));
+ ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue(each, QuoteCharacter.NONE));
OrderByItem item = new OrderByItem(new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC));
item.setIndex(index++);
orderByItems.add(item);
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
index f5dce65..c0c9fb8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/identifier/IdentifierValue.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.sql.parser.sql.common.value.identifier;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
@@ -26,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.ValueASTNode;
/**
* Identifier value.
*/
+@RequiredArgsConstructor
@Getter
@ToString
public final class IdentifierValue implements ValueASTNode<String> {
@@ -35,10 +37,9 @@ public final class IdentifierValue implements ValueASTNode<String> {
private final QuoteCharacter quoteCharacter;
public IdentifierValue(final String text) {
- value = SQLUtil.getExactlyValue(text);
- quoteCharacter = QuoteCharacter.getQuoteCharacter(text);
+ this(SQLUtil.getExactlyValue(text), QuoteCharacter.getQuoteCharacter(text));
}
-
+
/**
* Get value with quote characters, i.e. `table1` or `field1`
*