Skip to content

Commit b2e8633

Browse files
committed
Add VisibilityBitmap to TableMapEvent for MySQL 8.0.23+ Invisible Columns
Changes: - `TableMapEvent.VisibilityBitmap` `VisibilityBitmap` is a bitmap where each bit represents the visibility of a corresponding column in a table. If a bit is set, it indicates that the corresponding column is NOT an invinsible column. Invisible column was introduced in MySQL version 8.0.23. - `TableMapEvent.VisibilityMap` `VisibilityMap` lists boolean values of which is true if column of the same index is NOT an invisible column.
1 parent dc97dfa commit b2e8633

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

replication/const.go

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ const (
240240
TABLE_MAP_OPT_META_PRIMARY_KEY_WITH_PREFIX
241241
TABLE_MAP_OPT_META_ENUM_AND_SET_DEFAULT_CHARSET
242242
TABLE_MAP_OPT_META_ENUM_AND_SET_COLUMN_CHARSET
243+
TABLE_MAP_OPT_META_COLUMN_VISIBILITY
243244
)
244245

245246
type IntVarEventType byte

replication/row_event.go

+26
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ type TableMapEvent struct {
8181
// EnumSetDefaultCharset/EnumSetColumnCharset is similar to DefaultCharset/ColumnCharset but for enum/set columns.
8282
EnumSetDefaultCharset []uint64
8383
EnumSetColumnCharset []uint64
84+
85+
// VisibilityBitmap stores bits that are set if corresponding column is not invisible (MySQL 8.0.23+)
86+
VisibilityBitmap []byte
8487
}
8588

8689
func (e *TableMapEvent) Decode(data []byte) error {
@@ -312,6 +315,9 @@ func (e *TableMapEvent) decodeOptionalMeta(data []byte) (err error) {
312315
return err
313316
}
314317

318+
case TABLE_MAP_OPT_META_COLUMN_VISIBILITY:
319+
e.VisibilityBitmap = v
320+
315321
default:
316322
// Ignore for future extension
317323
}
@@ -421,6 +427,7 @@ func (e *TableMapEvent) Dump(w io.Writer) {
421427
fmt.Fprintf(w, "Primary key prefix: %v\n", e.PrimaryKeyPrefix)
422428
fmt.Fprintf(w, "Enum/set default charset: %v\n", e.EnumSetDefaultCharset)
423429
fmt.Fprintf(w, "Enum/set column charset: %v\n", e.EnumSetColumnCharset)
430+
fmt.Fprintf(w, "Invisible Column bitmap: \n%s", hex.Dump(e.VisibilityBitmap))
424431

425432
unsignedMap := e.UnsignedMap()
426433
fmt.Fprintf(w, "UnsignedMap: %#v\n", unsignedMap)
@@ -440,6 +447,9 @@ func (e *TableMapEvent) Dump(w io.Writer) {
440447
geometryTypeMap := e.GeometryTypeMap()
441448
fmt.Fprintf(w, "GeometryTypeMap: %#v\n", geometryTypeMap)
442449

450+
visibilityMap := e.VisibilityMap()
451+
fmt.Fprintf(w, "VisibilityMap: %#v\n", visibilityMap)
452+
443453
nameMaxLen := 0
444454
for _, name := range e.ColumnName {
445455
if len(name) > nameMaxLen {
@@ -730,6 +740,22 @@ func (e *TableMapEvent) GeometryTypeMap() map[int]uint64 {
730740
return ret
731741
}
732742

743+
// VisibilityMap returns a map: column index -> visiblity.
744+
// Invisible column was introduced in MySQL 8.0.23
745+
// nil is returned if not available.
746+
func (e *TableMapEvent) VisibilityMap() map[int]bool {
747+
if len(e.VisibilityBitmap) == 0 {
748+
return nil
749+
}
750+
p := 0
751+
ret := make(map[int]bool)
752+
for i := 0; i < int(e.ColumnCount); i++ {
753+
ret[i] = e.VisibilityBitmap[p/8]&(1<<uint(7-p%8)) != 0
754+
p++
755+
}
756+
return ret
757+
}
758+
733759
// Below realType and IsXXXColumn are base from:
734760
// table_def::type in sql/rpl_utility.h
735761
// Table_map_log_event::print_columns in mysql-8.0/sql/log_event.cc and mariadb-10.5/sql/log_event_client.cc

0 commit comments

Comments
 (0)