Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema: fix TIDB_ROW_ID_SHARDING_INFO for composite primary key #52331

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions pkg/infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,18 +1713,16 @@ func GetShardingInfo(dbInfo model.CIStr, tableInfo *model.TableInfo) any {
return nil
}
shardingInfo := "NOT_SHARDED"
if tableInfo.PKIsHandle {
if tableInfo.ContainsAutoRandomBits() {
shardingInfo = "PK_AUTO_RANDOM_BITS=" + strconv.Itoa(int(tableInfo.AutoRandomBits))
rangeBits := tableInfo.AutoRandomRangeBits
if rangeBits != 0 && rangeBits != autoid.AutoRandomRangeBitsDefault {
shardingInfo = fmt.Sprintf("%s, RANGE BITS=%d", shardingInfo, rangeBits)
}
} else {
shardingInfo = "NOT_SHARDED(PK_IS_HANDLE)"
if tableInfo.ContainsAutoRandomBits() {
shardingInfo = "PK_AUTO_RANDOM_BITS=" + strconv.Itoa(int(tableInfo.AutoRandomBits))
rangeBits := tableInfo.AutoRandomRangeBits
if rangeBits != 0 && rangeBits != autoid.AutoRandomRangeBitsDefault {
shardingInfo = fmt.Sprintf("%s, RANGE BITS=%d", shardingInfo, rangeBits)
}
} else if tableInfo.ShardRowIDBits > 0 {
shardingInfo = "SHARD_BITS=" + strconv.Itoa(int(tableInfo.ShardRowIDBits))
} else if tableInfo.PKIsHandle {
shardingInfo = "NOT_SHARDED(PK_IS_HANDLE)"
}
return shardingInfo
}
Expand Down
5 changes: 5 additions & 0 deletions tests/integrationtest/r/ddl/db_integration.result
Original file line number Diff line number Diff line change
Expand Up @@ -1298,3 +1298,8 @@ create table t(a int);
alter table t add column b int as ((grouping(a))) stored;
Error 1111 (HY000): Invalid use of group function
drop table t;
drop table if exists t;
create table t (a bigint auto_random, b int, c char(255), primary key(a, b) clustered);
select TIDB_ROW_ID_SHARDING_INFO from information_schema.tables where TABLE_SCHEMA = 'ddl__db_integration' and TABLE_NAME = 't';
TIDB_ROW_ID_SHARDING_INFO
PK_AUTO_RANDOM_BITS=5
5 changes: 5 additions & 0 deletions tests/integrationtest/t/ddl/db_integration.test
Original file line number Diff line number Diff line change
Expand Up @@ -1117,3 +1117,8 @@ create table t(a int);
--error 1111
alter table t add column b int as ((grouping(a))) stored;
drop table t;

# Test composite primary key should have correct TIDB_ROW_ID_SHARDING_INFO.
drop table if exists t;
create table t (a bigint auto_random, b int, c char(255), primary key(a, b) clustered);
select TIDB_ROW_ID_SHARDING_INFO from information_schema.tables where TABLE_SCHEMA = 'ddl__db_integration' and TABLE_NAME = 't';