Issue 1:
First of all

my English is suck

Question

when I only configured the default-database-strategy ( no specific table rule are configured ) , My defaul-database-strategy didn't work. (I use hintManager.setDatabaseShardingValue() )

Version

4.0.0

Detail

my configuration as follow :

spring.shardingsphere.datasource.names=psghz,psgother
# psghz库配置
spring.shardingsphere.datasource.psghz.url=jdbc:postgresql://*******************:****/*****?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.shardingsphere.datasource.psghz.username=****
spring.shardingsphere.datasource.psghz.password=********
spring.shardingsphere.datasource.psghz.driverClassName=org.postgresql.Driver
spring.shardingsphere.datasource.psghz.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.psghz.max-active=10
# psgother库配置
spring.shardingsphere.datasource.psgother.url=jdbc:postgresql://*******************:****/*****?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.shardingsphere.datasource.psgother.username=****
spring.shardingsphere.datasource.psgother.password=********
spring.shardingsphere.datasource.psgother.driverClassName=org.postgresql.Driver
spring.shardingsphere.datasource.psgother.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.psgother.max-active=10
# 默认hint配置
spring.shardingsphere.sharding.default-database-strategy.hint.algorithm-class-name=com.ibuscloud.pubtrans.analysis.plugin.sharding.HintShardingStrategy
#起初打开default-data-srouce-name,结果走了DefaultDatabaseRoutingEngine,关闭则走了UnicastRoutingEngine
#spring.shardingsphere.sharding.default-data-source-name=psghz
spring.shardingsphere.props.sql.show=true

I follow the code and see the RoutingEngineFactory.java create UnicastRoutingEngine.java

if (sqlStatementContext.getSqlStatement() instanceof DMLStatement && tableNames.isEmpty() && shardingRule.hasDefaultDataSourceName()) {
return new DefaultDatabaseRoutingEngine(shardingRule, tableNames);
}
if (sqlStatementContext.getSqlStatement() instanceof DMLStatement && shardingConditions.isAlwaysFalse() || tableNames.isEmpty() || !shardingRule.tableRuleExists(tableNames)) {
return new UnicastRoutingEngine(shardingRule, tableNames);
}

and !shardingRule.tableRuleExists(tableNames) is true .

so back to the question , how does the configuration default-database-strategy work.

Issue 2:
Anomalies:

duplicate database ID production

abnormal query data

Which version of ShardingSphere did you use?

org.apache.shardingsphere:sharding-jdbc-spring-boot-starter:4.1.1

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

Please use the code repository I provided github

Execute com.example.demo.rest.AcontrollerTest#gen method passing in parameter 2023，The data is presented in the database as follows

818114806320992257	device_1	2023-02-01 00:00:00	6	89	290	5851	60390
818114806320992258	device_2	2023-02-01 00:00:00	1	14	301	0018	21050
818114806320992259	device_3	2023-02-01 00:00:00	9	77	919	5078	00798

Execute com.example.demo.rest.AcontrollerTest#gen method passing in parameter 2024，The data is presented in the database as follows

818114806320992257	device_1	2024-02-01 00:00:00	5	30	077	9618	52059
818114806320992258	device_2	2024-02-01 00:00:00	7	85	481	9165	91450
818114806320992259	device_3	2024-02-01 00:00:00	6	16	941	3355	62767

The above operation shows that the ID production results are duplicated

Execute the com.example.demo.rest.AcontrollerTest#data method in this case，The returned data results in an exception。The data for 2023 was repeated 2 times, and the data for 2024 was not successfully queried

The result of the function execution is shown in the figure

The execution log is as follows

2023-01-07 11:33:50.291 INFO 10316 --- [ Test worker] ShardingSphere-SQL : Actual SQL: ds ::: select sampledata0_.id as id1_0_, sampledata0_.device_id as device_i2_0_, sampledata0_.time as time3_0_, sampledata0_.v1 as v4_0_, sampledata0_.v2 as v5_0_, sampledata0_.v3 as v6_0_, sampledata0_.v4 as v7_0_, sampledata0_.v5 as v8_0_ from sample_data_2023_2 sampledata0_ where sampledata0_.time<? ::: [2077-01-01 00:00:00.0]
2023-01-07 11:33:50.291 INFO 10316 --- [ Test worker] ShardingSphere-SQL : Actual SQL: ds ::: select sampledata0_.id as id1_0_, sampledata0_.device_id as device_i2_0_, sampledata0_.time as time3_0_, sampledata0_.v1 as v4_0_, sampledata0_.v2 as v5_0_, sampledata0_.v3 as v6_0_, sampledata0_.v4 as v7_0_, sampledata0_.v5 as v8_0_ from sample_data_2024_2 sampledata0_ where sampledata0_.time<? ::: [2077-01-01 00:00:00.0]