Issue 1:
shardingsphere/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java

Lines 73 to 78
in
1ea6d35

private static List<RouteMapper> getRouteTableRouteMappers(final Collection<RouteMapper> tableMappers) {

if (null == tableMappers) {

return Collections.emptyList();

}

return tableMappers.stream().map(routeMapper -> new RouteMapper(routeMapper.getLogicName(), routeMapper.getActualName())).collect(Collectors.toList());

}

They are equal but not the same instances. Could we reuse the instances?

Issue 2:
Bug Report

Which version of ShardingSphere did you use?

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>4.0.1</version>
</dependency>

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

sql execute ok, and return the result

Actual behavior

SQL: SELECT * from test_user where id = ( select test_user_id from test_user_bind where uid =? and start_time <= now() and end_time > now() order by id desc limit 1 ) Cause: java.lang.IllegalStateException: Must have sharding column with subquery. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76) at sun.reflect.GeneratedMethodAccessor910.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ... 108 more Caused by: java.lang.IllegalStateException: Must have sharding column with subquery. at com.google.common.base.Preconditions.checkState(Preconditions.java:444) at org.apache.shardingsphere.core.route.router.sharding.ShardingRouter.checkSubqueryShardingValues(ShardingRouter.java:148) at org.apache.shardingsphere.core.route.router.sharding.ShardingRouter.route(ShardingRouter.java:109) at org.apache.shardingsphere.core.route.PreparedStatementRoutingEngine.route(PreparedStatementRoutingEngine.java:63) at org.apache.shardingsphere.core.PreparedQueryShardingEngine.route(PreparedQueryShardingEngine.java:59) at org.apache.shardingsphere.core.BaseShardingEngine.executeRoute(BaseShardingEngine.java:85) at org.apache.shardingsphere.core.BaseShardingEngine.shard(BaseShardingEngine.java:68) at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.shard(ShardingPreparedStatement.java:249) at org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:190) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at sun.reflect.GeneratedMethodAccessor825.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy202.query(Unknown Source) at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:67) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:163) at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:90) at sun.reflect.GeneratedMethodAccessor823.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy199.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ... 114 more

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

The sharding yaml config：

ds_user: !!com.mchange.v2.c3p0.ComboPooledDataSource
driverClass: @jdbc.driverClassName@
jdbcUrl: @jdbc.db_user.url@
user: @jdbc.db_user.user@
password: @jdbc.db_user.password@
ds0: !!com.mchange.v2.c3p0.ComboPooledDataSource
driverClass: @jdbc.driverClassName@
jdbcUrl: @jdbc.db0.url@
user: @jdbc.db0.user@
password: @jdbc.db0.password@
ds1: !!com.mchange.v2.c3p0.ComboPooledDataSource
driverClass: @jdbc.driverClassName@
jdbcUrl: @jdbc.db1.url@
user: @jdbc.db1.user@
password: @jdbc.db1.password@
shardingRule:
tables:
zoom_user_bind:
actualDataNodes: ds_user.zoom_user_bind
databaseStrategy:
none: {}
tableStrategy:
none: {}
zoom_user:
actualDataNodes: ds_user.zoom_user
databaseStrategy:
none: {}
tableStrategy:
none: {}

defaultDataSourceName: ds_user
defaultDatabaseStrategy:
none: {}
defaultTableStrategy:
none: {}
props:
sql.show: false```

### Example codes for reproduce this issue (such as a github link).