Skip to content

Commit

Permalink
Merge 722827a into a0d6901
Browse files Browse the repository at this point in the history
  • Loading branch information
jingshanglu committed Sep 24, 2020
2 parents a0d6901 + 722827a commit 29364c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Expand Up @@ -79,6 +79,9 @@ private Map<RouteUnit, Collection<String>> getDerivedProjectionTexts(final Selec
result.get(routeUnit).add(getDerivedProjectionText(each));
}
}
if (result.get(routeUnit).isEmpty()) {
result.remove(routeUnit);
}
}
return result;
}
Expand Down
Expand Up @@ -64,6 +64,12 @@
<output sql="SELECT (select id from t_account_0 limit 1) as myid FROM (select b.account_id from (select t_account_0.account_id from t_account_0) b where b.account_id=?) a WHERE account_id >= (select account_id from t_account_0 limit 1)" parameters="100"/>
</rewrite-assertion>

<rewrite-assertion id="select_with_subquery_only_in_projection" db-type="MySQL">
<input sql="SELECT (select id from t_account)"/>
<output sql="SELECT (select id from t_account_0)"/>
<output sql="SELECT (select id from t_account_1)"/>
</rewrite-assertion>

<rewrite-assertion id="select_with_subquery_for_where_in_predicate" db-type="MySQL">
<input sql="SELECT * FROM t_account WHERE account_id = ? AND amount IN (SELECT amount FROM t_account WHERE account_id = ?)" parameters="100, 100"/>
<output sql="SELECT * FROM t_account_0 WHERE account_id = ? AND amount IN (SELECT amount FROM t_account_0 WHERE account_id = ?)" parameters="100, 100"/>
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.type.TableAvailable;
import org.apache.shardingsphere.sql.parser.binder.type.WhereAvailable;
import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
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;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.IndexOrderByItemSegment;
Expand All @@ -44,7 +45,6 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import org.apache.shardingsphere.sql.parser.sql.common.util.WhereSegmentExtractUtils;

import java.util.Collection;
Expand Down
Expand Up @@ -303,7 +303,7 @@ private ASTNode createCompareSegment(final BooleanPrimaryContext ctx) {
if (null != ctx.predicate()) {
right = (ExpressionSegment) visit(ctx.predicate());
} else {
right = (ExpressionSegment) visit(ctx.subquery());
right = new SubqueryExpressionSegment(new SubquerySegment(ctx.subquery().start.getStartIndex(), ctx.subquery().stop.getStopIndex(), (MySQLSelectStatement) visit(ctx.subquery())));
}
String operator = null != ctx.SAFE_EQ_() ? ctx.SAFE_EQ_().getText() : ctx.comparisonOperator().getText();
String text = ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
Expand Down

0 comments on commit 29364c8

Please sign in to comment.