Skip to content

Support MySQL vector type #1004

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

Merged
merged 2 commits into from
Mar 6, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ const (
MYSQL_TYPE_TIME2
)

const MYSQL_TYPE_VECTOR = 0xf2

const (
MYSQL_TYPE_JSON byte = iota + 0xf5
MYSQL_TYPE_NEWDECIMAL
Expand Down
8 changes: 4 additions & 4 deletions mysql/rowdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ func (p RowData) ParseBinary(f []*Field, dst []FieldValue) ([]FieldValue, error)
pos += 8
continue

case MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR,
MYSQL_TYPE_BIT, MYSQL_TYPE_ENUM, MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB,
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_JSON:
case MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT,
MYSQL_TYPE_ENUM, MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_MEDIUM_BLOB,
MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB, MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_STRING,
MYSQL_TYPE_VECTOR, MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_JSON:
v, isNull, n, err = LengthEncodedString(p[pos:])
pos += n
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions notes/field_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Here is a list collected from `mysql-8.0/sql/field.h`:
| | | +--Field_varstring | MYSQL_TYPE_VARCHAR | MYSQL_TYPE_VARCHAR | |
| | | +--Field_blob | MYSQL_TYPE_BLOB | | |
| | | +--Field_geom | MYSQL_TYPE_GEOMETRY | | |
| | | +--Field_vector | MYSQL_TYPE_VECTOR | | |
| | | +--Field_json | MYSQL_TYPE_JSON | | |
| | | +--Field_typed_array | real_type_to_type(m_elt_type) | m_elt_type | MYSQL_TYPE_TYPED_ARRAY |
| | | | | | |
Expand Down
5 changes: 5 additions & 0 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func bitmapByteSize(columnCount int) int {
MYSQL_TYPE_DOUBLE
MYSQL_TYPE_BLOB
MYSQL_TYPE_GEOMETRY
MYSQL_TYPE_VECTOR

//maybe
MYSQL_TYPE_TIME2
Expand Down Expand Up @@ -226,6 +227,7 @@ func (e *TableMapEvent) decodeMeta(data []byte) error {
mysql.MYSQL_TYPE_DOUBLE,
mysql.MYSQL_TYPE_FLOAT,
mysql.MYSQL_TYPE_GEOMETRY,
mysql.MYSQL_TYPE_VECTOR,
mysql.MYSQL_TYPE_JSON:
e.ColumnMeta[i] = uint16(data[pos])
pos++
Expand Down Expand Up @@ -891,6 +893,7 @@ const RowsEventStmtEndFlag = 0x01
// - mysql.MYSQL_TYPE_STRING: string
// - mysql.MYSQL_TYPE_JSON: []byte / *replication.JsonDiff
// - mysql.MYSQL_TYPE_GEOMETRY: []byte
// - mysql.MYSQL_TYPE_VECTOR: []byte
type RowsEvent struct {
// 0, 1, 2
Version int
Expand Down Expand Up @@ -1407,6 +1410,8 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16, isPartial boo
// I also find some go libs to handle WKB if possible
// see https://github.com/twpayne/go-geom or https://github.com/paulmach/go.geo
v, n, err = decodeBlob(data, meta)
case mysql.MYSQL_TYPE_VECTOR:
v, n, err = decodeBlob(data, meta)
default:
err = fmt.Errorf("unsupport type %d in binlog and don't know how to handle", tp)
}
Expand Down
8 changes: 4 additions & 4 deletions server/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ func (c *Conn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte)
pos += 8
continue

case mysql.MYSQL_TYPE_DECIMAL, mysql.MYSQL_TYPE_NEWDECIMAL, mysql.MYSQL_TYPE_VARCHAR,
mysql.MYSQL_TYPE_BIT, mysql.MYSQL_TYPE_ENUM, mysql.MYSQL_TYPE_SET, mysql.MYSQL_TYPE_TINY_BLOB,
mysql.MYSQL_TYPE_MEDIUM_BLOB, mysql.MYSQL_TYPE_LONG_BLOB, mysql.MYSQL_TYPE_BLOB,
mysql.MYSQL_TYPE_VAR_STRING, mysql.MYSQL_TYPE_STRING, mysql.MYSQL_TYPE_GEOMETRY,
case mysql.MYSQL_TYPE_DECIMAL, mysql.MYSQL_TYPE_NEWDECIMAL, mysql.MYSQL_TYPE_VARCHAR, mysql.MYSQL_TYPE_BIT,
mysql.MYSQL_TYPE_ENUM, mysql.MYSQL_TYPE_SET, mysql.MYSQL_TYPE_TINY_BLOB, mysql.MYSQL_TYPE_MEDIUM_BLOB,
mysql.MYSQL_TYPE_LONG_BLOB, mysql.MYSQL_TYPE_BLOB, mysql.MYSQL_TYPE_VAR_STRING, mysql.MYSQL_TYPE_STRING,
mysql.MYSQL_TYPE_GEOMETRY, mysql.MYSQL_TYPE_VECTOR,
mysql.MYSQL_TYPE_DATE, mysql.MYSQL_TYPE_NEWDATE,
mysql.MYSQL_TYPE_TIMESTAMP, mysql.MYSQL_TYPE_DATETIME, mysql.MYSQL_TYPE_TIME:
if len(paramValues) < (pos + 1) {
Expand Down
Loading