strongduanmu commented on a change in pull request #14307:
URL: https://github.com/apache/shardingsphere/pull/14307#discussion_r775094260
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
##########
@@ -228,7 +228,8 @@ private static boolean isShardingFederatedQuery(final
ShardingRule shardingRule,
if (select.getPaginationContext().isHasPagination() ||
(shardingConditions.isNeedMerge() &&
shardingConditions.isSameShardingCondition())) {
return false;
}
- if (select.isContainsSubquery() || select.isContainsHaving() ||
select.isContainsUnion() || select.isContainsPartialDistinctAggregation()) {
+ if ((select.isContainsSubquery() &&
!shardingRule.isAllTablesInSameDataSource(tableNames)) ||
select.isContainsHaving() || select.isContainsUnion()
Review comment:
@cheese8 Why change sharding route logic?
##########
File path:
shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
##########
@@ -74,22 +74,25 @@
<rewrite-assertion
id="select_with_subquery_and_different_sharding_conditions" db-types="MySQL">
<input sql="SELECT * FROM (select t_account.account_id from t_account
where t_account.account_id=?) a WHERE account_id = 101" parameters="100" />
- <output sql="SELECT * FROM (select t_account.account_id from t_account
where t_account.account_id=?) a WHERE account_id = 101" parameters="100" />
+ <output sql="SELECT * FROM (select t_account_0.account_id from
t_account_0 where t_account_0.account_id=?) a WHERE account_id = 101"
parameters="100" />
+ <output sql="SELECT * FROM (select t_account_1.account_id from
t_account_1 where t_account_1.account_id=?) a WHERE account_id = 101"
parameters="100" />
</rewrite-assertion>
<rewrite-assertion id="select_with_subquery_with_subquery"
db-types="MySQL">
<input sql="SELECT * FROM (select b.account_id from (select
t_account.account_id from t_account) b where b.account_id=?) a WHERE account_id
= 100" parameters="100" />
- <output sql="SELECT * FROM (select b.account_id from (select
t_account.account_id from t_account) b where b.account_id=?) a WHERE account_id
= 100" parameters="100" />
+ <output sql="SELECT * 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 = 100" parameters="100" />
Review comment:
@cheese8 This rewriting seems to be incorrect. The inner subquery needs
to query the account_id on all shards instead of t_account_0 shard.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]