shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Cause: org.apache.shardingsphere.infra.exception.TableNotExistsException: Table or view `***` does not exist.

Open prefect1005 opened this issue 2 years ago • 10 comments

use 5.4.1

config ` mode: type: Standalone

databaseName: db1`

sql1: "select * from db1.table" sql2:"select * form db2.table2"

sql1 no problem but db2.table2 will TableNotExistsException Caused by: org.apache.shardingsphere.infra.exception.TableNotExistsException: Table or view table2 does not exist.

prefect1005 avatar Dec 27 '23 12:12 prefect1005

@prefect1005 So did you configured database db2 and create (or load) table2 in it?

RaigorJiang avatar Dec 27 '23 16:12 RaigorJiang

@RaigorJiang Of course . in other word, if one project need to select db1 and db2 database, just db1.table1 need sharding config,so how to config that we can execute db2`s sql correcttly

prefect1005 avatar Dec 28 '23 02:12 prefect1005

@RaigorJiang Of course . in other word, if one project need to select db1 and db2 database, just db1.table1 need sharding config,so how to config that we can execute db2`s sql correcttly

Create two logic databases, named db1 and db2.

RaigorJiang avatar Dec 28 '23 08:12 RaigorJiang

@RaigorJiang im sorry that i used "ShardingSphere-JDBC", and i dont know how to create logic databases, can you give me one demo or config file ? thank you.

prefect1005 avatar Dec 28 '23 09:12 prefect1005

image i try to config like this, but it not used

prefect1005 avatar Dec 28 '23 10:12 prefect1005

@prefect1005 OK, so you just want to access tables in multiple data sources, not multiple logic data bases. let's do two things:

  1. Configure single rule *.*; (link)
  2. Use table name directly when executing SQL (select * from table2)

Note that this only applies to the case where there are no tables with the same name in data source 1 and data source 2.

RaigorJiang avatar Dec 28 '23 13:12 RaigorJiang

well, i got it. in my project, every sql has point db, like 'select * from db1.table1' in this case, its not work until i config 'databaseName:db1' lets coding not used default databaseName - 'logic_db' and then, other sql 'select * from db2.table2' will execute wrong because that dbMap not containskey 'db2'. so it well success after i delete all point database(and config db1/db2 datasource both, eventhough all database in the same entity database(same ip and port)). but in this way, the code will confusion because i can`t recognize the table from which db directtly . finally, Is there a plan to support the SQL that point db like 'select * from db3.table3'?

prefect1005 avatar Dec 28 '23 15:12 prefect1005

+1 ,this scenario is very common.

well, i got it. in my project, every sql has point db, like 'select * from db1.table1' in this case, its not work until i config 'databaseName:db1' lets coding not used default databaseName - 'logic_db' and then, other sql 'select * from db2.table2' will execute wrong because that dbMap not containskey 'db2'. so it well success after i delete all point database(and config db1/db2 datasource both, eventhough all database in the same entity database(same ip and port)). but in this way, the code will confusion because i can`t recognize the table from which db directtly . finally, Is there a plan to support the SQL that point db like 'select * from db3.table3'?

6z7 avatar Jan 10 '24 15:01 6z7

@prefect1005 @6z7 It is possible that duplicate beanName for multiple datasources causes the datasource to not load,like db2 is used db1 datasource。

vaqsummer avatar Jan 12 '24 08:01 vaqsummer

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

github-actions[bot] avatar Feb 11 '24 20:02 github-actions[bot]

I think you can try hybrid-architecture - https://shardingsphere.apache.org/document/current/en/overview/#hybrid-architecture. You can use Proxy to manage, create multiple logical databases, and then JDBC to access these logical databases.

strongduanmu avatar Mar 12 '24 08:03 strongduanmu

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.

github-actions[bot] avatar Apr 12 '24 20:04 github-actions[bot]