terrymanu commented on issue #36442:
URL:
https://github.com/apache/shardingsphere/issues/36442#issuecomment-3565028579
• Issue Understanding
- Using ShardingSphere-JDBC 5.5.2 with a multi-level WITH/CTE query, an
UnknownDatabaseException is thrown during the bind/preparation phase at
SelectStatementContext#getTableMapperRuleAttributes.
- The error occurs before routing to physical databases.
Root Cause
- During binding, ShardingSphere fetches rule attributes (e.g.,
encrypt/broadcast) by the current logical database name from
ShardingSphereMetaData. If that logical database name is not registered, it
throws
UnknownDatabaseException.
- Common triggers:
1. The databaseName used when creating the data source differs from
the logical database name used to obtain the connection.
2. When using
ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, ruleConfigs,
props), the default logical database name is logic_db, but the connection is
switched to a different name.
3. Logical database name mismatches due to case or surrounding spaces.
Analysis
- The SQL complexity (CTE/UNION) does not cause UnknownDatabaseException;
with a correctly registered logical database, binding should pass.
- From the stack, the failure happens at database-name validation before
enhanced-table checks. Please verify configuration/connection context first:
- The logical database name in your YAML or DataSource construction.
- The logical database name used when obtaining the connection
(ShardingSphereConnection#getCurrentDatabaseName() or getSchema()/getCatalog()).
- The database names registered in ContextManager.
- Current information suggests a configuration/context mismatch rather
than a product defect.
Conclusion / Next Steps
- Ensure the logical database name used by the connection matches the name
registered in configuration.
- If the issue persists after this check, please provide:
- Your YAML or DataSource construction config (including databaseName,
datasource names, rule configs).
- The logical database name actually used on the connection.
- The list of database names in ContextManager.
- Physical database type and version.
- Official docs:
- DataSource creation and databaseName:
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/rules/
- YAML configuration examples (JDBC):
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/
--
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]