apache / apache/shardingsphere

Index0utOfBoundsException occurs when execute merge statement without sharding generated key

Open
#32,934 0 comments 0 reactions 1 assignee Claimed by @strongduanmu View on GitHub
in: metadata type: bug
Dominant language
Java
Stars
20.8k
Forks
6.9k
Avg merge
11h 35m
Merged PRs (30d)
326

Description

## Bug Report

### Which version of ShardingSphere did you use?

[b7294f7](https://github.com/apache/shardingsphere/commit/b7294f7d352dc25e63cf29a2ea5ebde8090a1218)

### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

### Expected behavior

Execute merge statement successfully when I not config sharding generated key.

### Actual behavior

image

### Reason analyze (If you can)

The generated in ShardingSphereColumn should indicate whether to use the distributed key, rather than the id generated in the underlying db. This logic is correct in earlier versions (such as 5.0.0).

https://github.com/apache/shardingsphere/blob/d3409a2e36b4233372cfd048038634b7a518dc5d/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/metadata/ShardingTableMetaDataBuilder.java#L122

The logic of the latest version is wrong. It will first determine whether it is a distributed ID. If not, it will use the ID generated in the db.

image

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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.