shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

unconfigured table can not query with schema name because of missing rewrite

Open zero2hj opened this issue 6 years ago • 6 comments

Question

I wish to not configure every no sharding table's actual nodes to ds0. At version 4.1 there is one prop named defaultDataSourceName, after configuring it, if I query the table with its schema name select * from schema.table it will route to ds0 but not rewrite to ignore schema name and because of DB sharding, we actually have mapped schema to schema{0...3}.

zero2hj avatar Sep 14 '20 06:09 zero2hj

@chana71 Please provide your configuration.

menghaoranss avatar Sep 14 '20 07:09 menghaoranss

@menghaoranss Now I am testing on the master version. Please check.

schemaName: cust
dataSourceCommon:
  ...
dataSources:
  ds0:
    url: jdbc:mysql://192.168.1.175:3306/cust0?useSSL=false
  ds1:
    url: jdbc:mysql://192.168.1.175:3306/cust1?useSSL=false
  ds2:
    url: jdbc:mysql://192.168.1.186:3306/cust2?useSSL=false
  ds3:
    url: jdbc:mysql://192.168.1.186:3306/cust3?useSSL=false
rules:
  - !SHARDING
    tables:
      sched_job_extend:
        actualDataNodes: ds${0..3}.sched_job_extend
        databaseStrategy:
          standard:
            shardingAlgorithmName: database_mod
            shardingColumn: dbid
    defaultDatabaseStrategy:
      none:
    shardingAlgorithms:
      database_mod:
        type: MOD
        props:
          sharding.count: 4

Thx

zero2hj avatar Sep 14 '20 07:09 zero2hj

@menghaoranss This is 4.1 version configuration. We have some table sharding across ds0-4 and others only exist at ds0

defaultDataSourceName: ds0
tables:
  
  t_order:
    actualDataNodes: ds${0..3}.t_order
    databaseStrategy:
      inline:
        algorithmExpression: ds${id% 4}
        shardingColumn: id
    logicTable: t_order

zero2hj avatar Sep 14 '20 07:09 zero2hj

@menghaoranss This is 4.1 version configuration. We have some table sharding across ds0-4 and others only exist at ds0

defaultDataSourceName: ds0
tables:
  
  t_order:
    actualDataNodes: ds${0..3}.t_order
    databaseStrategy:
      inline:
        algorithmExpression: ds${id% 4}
        shardingColumn: id
    logicTable: t_order

what's your SQL and the actual SQL in the log?

menghaoranss avatar Sep 14 '20 08:09 menghaoranss

@menghaoranss Logic SQL: select count() from cust.SQL_BIZ_HIS Actual SQL: ds0 ::: select count() from cust.SQL_BIZ_HIS SQL_BIZ_HIS is unconfigured

Thanks for your feedback, this is a Bug, just similer with #7342 , It's being solved now,you can pay attention.

zero2hj avatar Sep 14 '20 08:09 zero2hj

Just remove schema prefix for unconfigured tables. In recent version of ShardingSphere, if we config some real datasources in a logic schema, then only use logic names for sharding tables, and real names for unconfigured tables. The original mysql schema does not exist for users.

kimmking avatar Sep 14 '20 11:09 kimmking