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 2020/08/19 02:18:40 UTC

[GitHub] [shardingsphere] 291277058 edited a comment on issue #6918: Discussion:Will shardingsphere support update sql with table select function

291277058 edited a comment on issue #6918:
URL: https://github.com/apache/shardingsphere/issues/6918#issuecomment-675811968


   When I update a entity ,the logic sql look like this
   `update order_item set app_id=?, create_date=?, order_info=?, orderno=?, original_price=?, pay_date=?, pay_source=?, price=?, product_list=?, source_orderno=?, status=?, user_id=? where id=?`
   It canbe understand that sql will execute in all table shard, I set other field as the key to sharding table,not the id.
   But update sql is special,it can be shard by the updated field,sharding field value is expectd not be change.Of course if not set the shard field the sharding function not work.(which I called table select function).
   
   Now, when I execute update, I got the following result.
   ![image](https://user-images.githubusercontent.com/33279488/90583752-91f8c380-e203-11ea-9a9c-a9fee2f885da.png)
   Update sql almost like insert sql , but insert can work within expewctations, why not the update.
   
   `if (sqlStatement instanceof InsertStatement) {
               return new InsertOptimizeEngine(shardingRule, (InsertStatement)sqlStatement, parameters, generatedKey);
           } else {
               return !(sqlStatement instanceof SelectStatement) && !(sqlStatement instanceof DMLStatement) ? new QueryOptimizeEngine(sqlStatement.getRouteConditions().getOrCondition(), parameters) : new QueryOptimizeEngine(sqlStatement.getRouteConditions().getOrCondition(), parameters);
           }`
   
   In my standpoint, I think it canbe optimized by execute only one sql.
   Add UpdateOptimizeEngine maybe can slove this problem.


----------------------------------------------------------------
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:
users@infra.apache.org