caoweicw commented on issue #32166:
URL: 
https://github.com/apache/shardingsphere/issues/32166#issuecomment-2245130191

   > I believe it is very difficult to determine how to reproduce from a debug 
screenshot, as it hides too much information. For example: whether it is in a 
multi-threads, how the execution was performed, how many steps were taken after 
the breakpoint before entering this state, and how many times this breakpoint 
was hit.
   > 
   > Anyway, could you please clarify the purpose of this issue, what error 
occurred during the process, and what operations were performed when the error 
was reported?
   
   
   First,I create shardingSphereDatasource with java api,and set shardingrule 
with tb_order 
   Sencond,I execute sql as follows:
   
![微信图片_1](https://github.com/user-attachments/assets/14f06122-70a5-49ea-966b-d82727554932)
   it will throw exception as follows:
   ```
   
org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException:
 Table or view 't_order' does not exist.
        at 
org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.lambda$checkTableExists$4(SimpleTableSegmentBinder.java:151)
        at 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions.checkState(ShardingSpherePreconditions.java:41)
        at 
org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.checkTableExists(SimpleTableSegmentBinder.java:148)
        at 
org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.bind(SimpleTableSegmentBinder.java:84)
        at 
org.apache.shardingsphere.infra.binder.segment.from.TableSegmentBinder.bind(TableSegmentBinder.java:55)
        at 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.lambda$bind$1(SelectStatementBinder.java:60)
        at java.base/java.util.Optional.map(Optional.java:265)
        at 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.bind(SelectStatementBinder.java:60)
        at 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementBinder.bind(SelectStatementBinder.java:48)
        at 
org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bindDMLStatement(SQLBindEngine.java:82)
        at 
org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bind(SQLBindEngine.java:72)
        at 
org.apache.shardingsphere.infra.binder.engine.SQLBindEngine.bind(SQLBindEngine.java:63)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:207)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.<init>(ShardingSpherePreparedStatement.java:172)
   ```
   I debug and find in 
org.apache.shardingsphere.infra.binder.segment.from.impl.SimpleTableSegmentBinder.checkTableExists,
 the logic_db->shemas->tables is empty  ,it cause exeception。
   ```
   private static void checkTableExists(String tableName, 
SQLStatementBinderContext statementBinderContext, String databaseName, String 
schemaName) {
       if (!"dual".equalsIgnoreCase(tableName)) {
         if (!SystemSchemaManager.isSystemTable(schemaName, tableName)) {
           if 
(!statementBinderContext.getExternalTableBinderContexts().containsKey(tableName))
 {
             
ShardingSpherePreconditions.checkState(statementBinderContext.getMetaData().containsDatabase(databaseName)
 && 
statementBinderContext.getMetaData().getDatabase(databaseName).containsSchema(schemaName)
 && 
statementBinderContext.getMetaData().getDatabase(databaseName).getSchema(schemaName).containsTable(tableName),
 () -> {
               return new TableNotFoundException(tableName);
             });
           }
         }
       }
     }
   ```
   
   
![微信图片_2](https://github.com/user-attachments/assets/aea965f5-bcd7-4e43-89d4-3e6b53eef78f)
   


-- 
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]

Reply via email to