strongduanmu commented on a change in pull request #6377:
URL: https://github.com/apache/shardingsphere/pull/6377#discussion_r456853167
##########
File path:
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingInsertStatementValidator.java
##########
@@ -35,9 +38,15 @@
@Override
public void validate(final ShardingRule shardingRule, final
InsertStatement sqlStatement, final List<Object> parameters) {
Optional<OnDuplicateKeyColumnsSegment> onDuplicateKeyColumnsSegment =
sqlStatement.getOnDuplicateKeyColumns();
- if (onDuplicateKeyColumnsSegment.isPresent() &&
isUpdateShardingKey(shardingRule, onDuplicateKeyColumnsSegment.get(),
sqlStatement.getTable().getTableName().getIdentifier().getValue())) {
+ String tableName =
sqlStatement.getTable().getTableName().getIdentifier().getValue();
+ if (onDuplicateKeyColumnsSegment.isPresent() &&
isUpdateShardingKey(shardingRule, onDuplicateKeyColumnsSegment.get(),
tableName)) {
throw new ShardingSphereException("INSERT INTO .... ON DUPLICATE
KEY UPDATE can not support update for sharding column.");
}
+ Optional<SubquerySegment> insertSelectSegment =
sqlStatement.getInsertSelect();
+ if (insertSelectSegment.isPresent() &&
isContainsKeyGenerateStrategy(shardingRule, tableName)
+ && !isContainsKeyGenerateColumn(shardingRule,
sqlStatement.getColumns(), tableName)) {
+ throw new ShardingSphereException("INSERT INTO .... SELECT can not
support key generate column.");
Review comment:
> Do you think it is better to add estimation of `the table inserted and
the table selected are the same or bind tables.`?
Adding this check is necessary to reduce the occurrence of abnormal
situations.
----------------------------------------------------------------
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]