qifengzhang007 opened a new issue #8050:
URL: https://github.com/apache/shardingsphere/issues/8050


   ###  问题描述  
   >  数据源按照id % 2进行切分,如果执行的是  insert  into 表(字段1) values (值1),(值2),(值3);
   > 最终发现 ds0 和 ds1 有两份相同数据。  我的表ID 是用 snowflak 框架自动生成的。  
   
   ###  关键配置项如下
   ```code
   shardingRule:
     tables:
       # 表名: t_order
       tb_order:
         actualDataNodes: ds_${0..1}.tb_order_${0..1}
         # table 表的行内规则
         tableStrategy:
           inline:
             #分表字段,开发者生成
             shardingColumn: order_id
             #算法, order_id 是偶数,就存入  t_order_0 表
             algorithmExpression: tb_order_${order_id % 2}
         #主键生成规则:雪花算法+该表(t_order)的主键:id   ,id 字段会自动生成
         keyGenerator:
           type: SNOWFLAKE
           column: id
       tb_order_item:
         actualDataNodes: ds_${0..1}.tb_order_item_${0..3}
         tableStrategy:
           inline:
             # t_order_item 表的数据就是t_order表的明细数据,两个表的关联键是  order_id
             shardingColumn: order_id
             algorithmExpression: tb_order_item_${order_id % 4}
         #主键生成规则:雪花算法+该表(t_order_item)的主键:id ,字段会自动生成
         keyGenerator:
           type: SNOWFLAKE
           column: id
     #设置哪些表需要分库分表
     bindingTables:
       - tb_order,tb_order_item
     #数据源配置策略  
     defaultDatabaseStrategy:
       inline:
         # 每个表设置了id字段,id由 sharding-proxy 使用snowflak自动生生
         shardingColumn: id
         algorithmExpression: ds_${id % 2}
     defaultTableStrategy:
       none:
   ```
   
   ###  问题复现代码  
   >   我批量插入了10条数据,但是最终查询的时候ds0  和  ds1 拥有相同的10条数据,最总变成了20条。
   >  如果依次逐条执行以下命令的话,就是正确的。
   >  求解
   ```code
   
   INSERT   INTO 
tb_order_item(order_id,item_name,price,num,total_price,`status`,remark)  VALUES
   (20201106001,'小米手10',2,4999.00,9998.00,1,'小米手机白色版')  ,
   (20201106001,'小米手10 至尊版',2,4999.00,9998.00,1,'小米手机至尊版')  , 
   
   (20201106002,'华为手机 meta40',1,6000.00,6000.00,1,'meta40')  , 
   (20201106002,'华为手机 meta40 pro',1,6500.00,6500.00,1,'meta40 pro')  ,
   
   (20201106003,'华为手机 p40',2,5000.00,10000.00,1,'p40')  , 
   (20201106003,'华为手机 p40 pro',1,5000.00,5000.00,1,'p40 pro')  ,  
   
   
   (20201106004,'苹果手机13',2,6500.00,13000.00,1,'iphone 13')  , 
   (20201106004,'苹果手机13 plus',1,5000.00,5000.00,1,'iphone 13 plus')  ,
   
   
   (20201106005,'荣耀v30',1,1999.00,1999.00,1,'荣耀v30')  , 
   (20201106005,'荣耀v30 plus',2,1999.00,3998.00,1,'荣耀v30 13 plus')  
   
   ```


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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to