You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/12/06 02:10:00 UTC

[GitHub] [shardingsphere] oneslideicywater opened a new issue #13937: How to explictly set table's defaultDatabaseStrategy?

oneslideicywater opened a new issue #13937:
URL: https://github.com/apache/shardingsphere/issues/13937


   ## Question
   
   Notice in the [example](https://github.com/apache/shardingsphere/blob/master/examples/shardingsphere-proxy-example/shardingsphere-proxy-boot-mybatis-example/src/main/resources/conf/config-sharding.yaml) that multiple table can have it's table-spliting inline algor, but share a common database-spliting inline algor.
   
   the drawback is that, if I use a default database strategy such as:
   
   ```yaml
     defaultDatabaseStrategy:
       standard:
         shardingColumn: user_id
         shardingAlgorithmName: database_inline
   
   ```
   
   then every logical table is this sharding-proxy instance should have a column `user_id`. otherwise,you'll encounter 
   errors when insert row into it. 
   
   ยท```bash
   sharding_db=> insert into t_employee(id,name,age,address,salary,deposit,birthday) values(479375,'WsfnVet6',33,'tSI8e1y5',841775.9513489738,723867.6766348411,'2012-05-28');
   ERROR:  Insert statement does not support sharding table routing to multiple data nodes.
   ```
   
   this error complains that I don't have a column `user_id` in table ` t_employee`,so sharding-proxy can't apply default database-spliting rules . but how can I explicitly set tables database-spliting rules? e.g. like that:
   
   ```yaml
   rules:
   - !SHARDING
     tables:
       t_order:
         actualDataNodes: ds_${0..1}.t_order_${0..3}
         tableStrategy:
           standard:
             shardingColumn: order_id
             shardingAlgorithmName: t_order_inline
         keyGenerateStrategy:
             column: order_id
             keyGeneratorName: snowflake
       t_employee:
         actualDataNodes: ds_${0..1}.t_employee_${0..3}
         tableStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: t_employee_inline
         defaultDatabaseStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: database_inline_employee
   ````
   
   
   
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] oneslideicywater closed issue #13937: How to explictly set table's defaultDatabaseStrategy?

Posted by GitBox <gi...@apache.org>.
oneslideicywater closed issue #13937:
URL: https://github.com/apache/shardingsphere/issues/13937


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] oneslideicywater commented on issue #13937: How to explictly set table's defaultDatabaseStrategy?

Posted by GitBox <gi...@apache.org>.
oneslideicywater commented on issue #13937:
URL: https://github.com/apache/shardingsphere/issues/13937#issuecomment-986401979


   ok, it's in the sharding-jdbc section hahah!


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #13937: How to explictly set table's defaultDatabaseStrategy?

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #13937:
URL: https://github.com/apache/shardingsphere/issues/13937#issuecomment-986380998


   Hi @oneslideicywater, thank you for your question. The `defaultDatabaseStrategy` is only used when the sharding table is not configured with a `databaseStrategy`. If the sharding table needs to customize the database sharding strategy, just define the `databaseStrategy` under the table.
   
   ```yaml
       t_employee:
         actualDataNodes: ds_${0..1}.t_employee_${0..3}
         tableStrategy:
           standard:
             shardingColumn: id
             shardingAlgorithmName: t_employee_inline
         #  explictly set database-spliting rules here, so the tables doesn't to be forced have a column user_id 
         databaseStrategy: 
           standard:
             shardingColumn: id  
             shardingAlgorithmName: database_inline_employee
   ```


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] RaigorJiang commented on issue #13937: How to explictly set table's defaultDatabaseStrategy?

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #13937:
URL: https://github.com/apache/shardingsphere/issues/13937#issuecomment-986383742


   Here is the document:
   https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/sharding/
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org