Skip to content

Commit

Permalink
br: fix br work with global index (#57493)
Browse files Browse the repository at this point in the history
close #57469
  • Loading branch information
Defined2014 authored Nov 19, 2024
1 parent d0150c0 commit 4e47aad
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
18 changes: 14 additions & 4 deletions br/tests/br_table_partition/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ run_sql "CREATE TABLE IF NOT EXISTS $DB.${TABLE}_List ($TABLE_COLUMNS) PARTITION

wait

insertRecords $DB.${TABLE}_Hash 1 $ROW_COUNT &
insertRecords $DB.${TABLE}_List 1 $ROW_COUNT &

for i in $(seq $TABLE_COUNT); do
for j in $(seq $CONCURRENCY); do
insertRecords $DB.$TABLE${i} $(expr $ROW_COUNT / $CONCURRENCY \* $(expr $j - 1) + 1) $(expr $ROW_COUNT / $CONCURRENCY \* $j) &
done
insertRecords $DB.${TABLE}_Hash 1 $ROW_COUNT &
insertRecords $DB.${TABLE}_List 1 $ROW_COUNT &
if ! ((i % 4)); then
if [ $((i % 4)) -eq 0 ]; then
run_sql "ALTER TABLE $DB.$TABLE${i} REMOVE PARTITIONING"
fi
if ! ((i % 2)); then
if [ $((i % 2)) -eq 0 ]; then
run_sql "ALTER TABLE $DB.$TABLE${i} \
PARTITION BY RANGE(c1) ( \
PARTITION p0 VALUES LESS THAN (0), \
Expand All @@ -77,3 +78,12 @@ for i in $(seq $TABLE_COUNT); do
fi
done
wait

run_sql "ALTER TABLE $DB.${TABLE}_Hash ADD UNIQUE INDEX idx(c1) GLOBAL" &
run_sql "ALTER TABLE $DB.${TABLE}_List ADD UNIQUE INDEX idx(c1) GLOBAL" &

for i in $(seq $TABLE_COUNT); do
run_sql "ALTER TABLE $DB.$TABLE${i} ADD UNIQUE INDEX idx(c1) GLOBAL" &
done
wait

14 changes: 13 additions & 1 deletion pkg/distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,18 @@ func BuildTableRanges(tbl *model.TableInfo) ([]kv.KeyRange, error) {
}

ranges := make([]kv.KeyRange, 0, len(pis.Definitions)*(len(tbl.Indices)+1)+1)
// Handle global index ranges
for _, idx := range tbl.Indices {
if idx.State != model.StatePublic || !idx.Global {
continue
}
idxRanges, err := IndexRangesToKVRanges(nil, tbl.ID, idx.ID, ranger.FullRange())
if err != nil {
return nil, err
}
ranges = idxRanges.AppendSelfTo(ranges)
}

for _, def := range pis.Definitions {
rgs, err := appendRanges(tbl, def.ID)
if err != nil {
Expand All @@ -854,7 +866,7 @@ func appendRanges(tbl *model.TableInfo, tblID int64) ([]kv.KeyRange, error) {
retRanges = kvRanges.AppendSelfTo(retRanges)

for _, index := range tbl.Indices {
if index.State != model.StatePublic {
if index.State != model.StatePublic || index.Global {
continue
}
ranges = ranger.FullRange()
Expand Down

0 comments on commit 4e47aad

Please sign in to comment.