apache / shardingsphere

Distributed SQL transaction & query engine for data sharding, scaling, encryption, and more - on any database.
Apache License 2.0
19.87k stars 6.73k forks source link

Use mybatis to insert in batches, each of which needs to be routed for multiple inserted data. It is recommended to add an internal cache to reduce routing frequency and improve performanc #27502

Closed honestAnt closed 3 months ago

honestAnt commented 1 year ago

Question

I use shardingsphere-jdbc-core-spring-boot-starter(v5.1.1) 、mybatis-plus-boot-starter(3.5.1) into my springBoot project. When I use native sql to batch insert data in mapper.xml, I found that the incoming collection data will be used as the sharding condition of shardingConditions after grammar and lexical analysis, and then each condition must be sharded to find the matching dataNode , the performance is poor when the amount of data inserted in batches is large (most of the shard keys are repeated and do not need to be recalculated)

Batch insert sql example in mapper.xml:insert into ${table} (column1,column2..) values (xxx,xx),(xx,xx)... sharding rules: using the value of a column in the table

Related test screenshots:

image

Question: Is it possible to customize ShardingRouteEngine (similar to ShardingStandardRoutingEngine) and add a tableColumn cache before the route0() method call to solve the problem of repeated routing? image

honestAnt commented 1 year ago

Try to overwrite the source code and modify it. After adding the cache, the performance improvement for large-scale insertion is still very significant; I don’t know if there is any other reasonable way to modify it?

image

github-actions[bot] commented 1 year ago

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

terrymanu commented 3 months ago

shardingsphere-jdbc-core-spring-boot-starter is deprecated and removed in 5.3.0, please try new version and use ShardingSphere Driver.