shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

when insert sql have "role" column,sharding-jdbc can not route divided table

Open wang7241 opened this issue 6 years ago • 16 comments

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

4.0.0-RC1

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

When I insert some sql ,it can route some sharding table

Actual behavior

insert sql can not route some sharding table

Reason analyze (If you can)

Maybe be my insert sql have "role" column

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

1.sharding rule configuration spring.shardingsphere.datasource.names = m1 spring.shardingsphere.sharding.default-data-source-name = m1

spring.shardingsphere.datasource.m1.type = com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.m1.driver-class-name = com.mysql.jdbc.Driver spring.shardingsphere.datasource.m1.jdbc-url = jdbc:mysql://127.0.0.1/test?characterEncoding=UTF-8&useUnicode=true&allowMultiQueries=true&&useSSL=true spring.shardingsphere.datasource.m1.username = root spring.shardingsphere.datasource.m1.password = 123456

spring.shardingsphere.sharding.tables.product_info.table-strategy.inline.sharding-column = product_info_id spring.shardingsphere.sharding.tables.product_info.table-strategy.inline.algorithm-expression = product_info_$->{product_info_id%2+1} 2.sql insert into product_info(product_info_id,store_info_id,product_name,spec,region_code,price,role) values (#{productInfoId},#{storeInfoId},#{productName},#{spec},#{regionCode},#{price},#{role}) 2.

Example codes for reproduce this issue (such as a github link).

code is very easy ,as follow 1.table -----I create product_info_1 and product_info_2 they are construction is same SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0;


-- Table structure for product_info_1


DROP TABLE IF EXISTS product_info_1; CREATE TABLE product_info_1 ( product_info_id bigint(20) NOT NULL COMMENT 'id', store_info_id bigint(20) NULL DEFAULT NULL COMMENT '所属店铺id', product_name varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商品名称', spec varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '规 格', region_code varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产地', price decimal(10, 0) NULL DEFAULT NULL COMMENT '商品价格', image_url varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商品图片', PRIMARY KEY (product_info_id) USING BTREE, INDEX FK_Reference_1(store_info_id) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; SET FOREIGN_KEY_CHECKS = 1; 2.entity @Data public class ProductInfo { private Long productInfoId; /** * 所属店铺id / private Long storeInfoId; /* * 商品名称 / private String productName; /* * 规格 / private String spec; /* * 产地 / private String regionCode; /* * 商品价格 / private BigDecimal price; /* * 商品图片 / private String imageUrl; /* * 角色 */ private Integer role; } 3.code @Mapper @Component public interface ProductDao { //添加商品基本信息 @Insert("insert into product_info(product_info_id,store_info_id,product_name,spec,region_code,price,role) values (#{productInfoId},#{storeInfoId},#{productName},#{spec},#{regionCode},#{price},#{role})") @Options(useGeneratedKeys = true,keyProperty = "productInfoId",keyColumn = "product_info_id") int insertProductInfo(ProductInfo productInfo);} 4.test @RunWith(SpringRunner.class) @SpringBootTest(classes = DemoApplication.class) class DemoApplicationTests { @Autowired ProductService productService; //添加商品 @Test public void testCreateProduct(){ for (int i=11;i<21;i++){ ProductInfo productInfo = new ProductInfo(); productInfo.setProductInfoId(2L); productInfo.setStoreInfoId(2L);//店铺id productInfo.setProductName("Java编程思想"+i);//商品名称 productInfo.setSpec("大号"); productInfo.setPrice(new BigDecimal(60)); productInfo.setRegionCode("110100"); productDao.insertProductInfo(productInfo); } }}

wang7241 avatar May 15 '20 12:05 wang7241

Hi @wang7241 , 4.0.0-RC1 is an old version, you can try the newest release version, 4.1.0.

dongzl avatar May 16 '20 13:05 dongzl

@ wang7241,您好:4.0.0-RC1是旧版本,您可以尝试使用最新发行版本4.1.0。

I have changed the version to 4.1.0, but the problem still exists

wang7241 avatar May 19 '20 01:05 wang7241

Hi @wang7241 , 4.0.0-RC1 is an old version, you can try the newest release version, 4.1.0.

Excuse me for my questions,I think it is common to have a "role" field in a table.Did your team ever have a problem with me

wang7241 avatar May 19 '20 02:05 wang7241

Hi @wang7241 , 4.0.0-RC1 is an old version, you can try the newest release version, 4.1.0.

Excuse me for my questions,I think it is common to have a "role" field in a table.Did your team ever have a problem with me

OK, I will try and reproduce this problem.

dongzl avatar May 20 '20 01:05 dongzl

Hi @wang7241 , 4.0.0-RC1 is an old version, you can try the newest release version, 4.1.0.

Excuse me for my questions,I think it is common to have a "role" field in a table.Did your team ever have a problem with me

OK, I will try and reproduce this problem.

Thank you very much

wang7241 avatar May 20 '20 01:05 wang7241

Hi @wang7241 , 4.0.0-RC1 is an old version, you can try the newest release version, 4.1.0.

Excuse me for my questions,I think it is common to have a "role" field in a table.Did your team ever have a problem with me

OK, I will try and reproduce this problem.

Is there any good news?

wang7241 avatar May 22 '20 09:05 wang7241

Hi @wang7241 , I test this problem with 4.1.0 version, It's OK.

Can you create a github project, and submit test code which can reproduce this problem, Thanks.

dongzl avatar May 23 '20 10:05 dongzl

Hi @wang7241 , I test this problem with 4.1.0 version, It's OK.

Can you create a github project, and submit test code which can reproduce this problem, Thanks.

Sorry,I made a mistake,I ever said that "I have changed the version to 4.1.0, but the problem still exists" it is wrong.

wang7241 avatar May 26 '20 01:05 wang7241

Hi @wang7241 , I test this problem with 4.1.0 version, It's OK.

Can you create a github project, and submit test code which can reproduce this problem, Thanks.

Now I use 4.1.0 to test my problem,there is a exception when I run my project,the exception as follow: ActualDataNodes must be configured if want to shard tables for logicTable [ku_challenge_rec]. it reminds me to configured ActualDataNodes,but my table "ku_challenge_rec" according to field "school_id" to dynamic devide tables. what should I do,please give me a help.On the other hand,when I used 4.0.0-RC1 there is no such exception.My springboot properties as follow: spring.shardingsphere.sharding.tables.ku_challenge_rec.table-strategy.inline.sharding-column = school_id spring.shardingsphere.sharding.tables.ku_challenge_rec.table-strategy.inline.algorithm-expression = ku_challenge_rec_$->{school_id}

wang7241 avatar May 26 '20 01:05 wang7241

Hi @wang7241 , according to your describe, add actual-data-nodes config and test it:

your can reference shardingsphere-example:

spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=ds_$->{0..1}.t_order_$->{0..1}

dongzl avatar May 27 '20 01:05 dongzl

Hi @wang7241 , according to your describe, add actual-data-nodes config and test it:

your can reference shardingsphere-example:

spring.shardingsphere.sharding.tables.t_order.actual-data-nodes=ds_$->{0..1}.t_order_$->{0..1}

shardingsphere-example without dynamic devide tables information,and the official documentation does not mention the configuration of dynamic tables

wang7241 avatar May 27 '20 01:05 wang7241

dynamic devide tables, I am sorry, I don't understand what's your want, can we discuss with 'WeChat', you can send WeChat account to [email protected]?

dongzl avatar May 27 '20 02:05 dongzl

ok,no problem

wang7241 avatar May 27 '20 07:05 wang7241

ref: #3680 #3963

dongzl avatar May 27 '20 10:05 dongzl

Hi @wang7241 , Do you have any other questions?

dongzl avatar Jun 08 '20 01:06 dongzl

Hi @wang7241 , Do you have any other questions?

No,I dont, thank you for your help

wang7241 avatar Jun 08 '20 01:06 wang7241