Skip to content

Commit

Permalink
Refactor bitmap iteration to align with MySQL source code
Browse files Browse the repository at this point in the history
Changes:
- Refactpred `UnsignedMap`
- Refactored `VisibilityMap`

Suggested by: #813 (comment)
  • Loading branch information
dongwook-chan committed Aug 15, 2023
1 parent ccabd26 commit 20bf956
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (e *TableMapEvent) Dump(w io.Writer) {
fmt.Fprintf(w, "Primary key prefix: %v\n", e.PrimaryKeyPrefix)
fmt.Fprintf(w, "Enum/set default charset: %v\n", e.EnumSetDefaultCharset)
fmt.Fprintf(w, "Enum/set column charset: %v\n", e.EnumSetColumnCharset)
fmt.Fprintf(w, "Invisible Column bitmap: \n%s", hex.Dump(e.VisibilityBitmap))
fmt.Fprintf(w, "Visible Column bitmap: \n%s", hex.Dump(e.VisibilityBitmap))

unsignedMap := e.UnsignedMap()
fmt.Fprintf(w, "UnsignedMap: %#v\n", unsignedMap)
Expand Down Expand Up @@ -618,16 +618,21 @@ func (e *TableMapEvent) UnsignedMap() map[int]bool {
if len(e.SignednessBitmap) == 0 {
return nil
}
p := 0
ret := make(map[int]bool)
for i := 0; i < int(e.ColumnCount); i++ {
if !e.IsNumericColumn(i) {
continue
i := 0
for _, field := range e.SignednessBitmap {
for c := 0x80; c != 0; c >>= 1 {
if !e.IsNumericColumn(i) {
continue
}
ret[i] = field&byte(c) != 0
i++
if uint64(i) >= e.ColumnCount {
return ret
}
}
ret[i] = e.SignednessBitmap[p/8]&(1<<uint(7-p%8)) != 0
p++
}
return ret
return nil
}

// CollationMap returns a map: column index -> collation id.
Expand Down Expand Up @@ -747,13 +752,18 @@ func (e *TableMapEvent) VisibilityMap() map[int]bool {
if len(e.VisibilityBitmap) == 0 {
return nil
}
p := 0
ret := make(map[int]bool)
for i := 0; i < int(e.ColumnCount); i++ {
ret[i] = e.VisibilityBitmap[p/8]&(1<<uint(7-p%8)) != 0
p++
i := 0
for _, field := range e.VisibilityBitmap {
for c := 0x80; c != 0; c >>= 1 {
ret[i] = field&byte(c) != 0
i++
if uint64(i) >= e.ColumnCount {
return ret
}
}
}
return ret
return nil
}

// Below realType and IsXXXColumn are base from:
Expand Down

0 comments on commit 20bf956

Please # to comment.