Skip to content
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
7 changes: 7 additions & 0 deletions go/test/endtoend/vtgate/setstatement/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func TestCharsetIntro(t *testing.T) {
require.NoError(t, err)
_, err = exec(t, conn, "insert into test (id,val1) values (666, _binary'abc')")
require.NoError(t, err)
_, err = exec(t, conn, "update test set val1 = _latin1'xyz' where id = 666")
require.NoError(t, err)
_, err = exec(t, conn, "delete from test where val1 = _utf8'xyz'")
require.NoError(t, err)
qr, err := exec(t, conn, "select id from test where val1 = _utf8mb4'xyz'")
require.NoError(t, err)
require.EqualValues(t, 0, qr.RowsAffected)
}

func TestSetSysVar(t *testing.T) {
Expand Down
49 changes: 49 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/dml_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2101,3 +2101,52 @@
"Vindex": "kid_index"
}
}

# update with binary value
"update user set name = _binary 'abc' where id = 1"
{
"QueryType": "UPDATE",
"Original": "update user set name = _binary 'abc' where id = 1",
"Instructions": {
"OperatorType": "Update",
"Variant": "Equal",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "MASTER",
"ChangedVindexValues": [
"name_user_map"
],
"KsidVindex": "user_index",
"MultiShardAutocommit": false,
"OwnedVindexQuery": "select Id, Name, Costly from user where id = 1 for update",
"Query": "update user set name = _binary 'abc' where id = 1",
"Table": "user",
"Values": [
1
],
"Vindex": "user_index"
}
}

# delete with binary value
"delete from user where name = _binary 'abc'"
{
"QueryType": "DELETE",
"Original": "delete from user where name = _binary 'abc'",
"Instructions": {
"OperatorType": "Delete",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"TargetTabletType": "MASTER",
"KsidVindex": "user_index",
"MultiShardAutocommit": false,
"OwnedVindexQuery": "select Id, Name, Costly from user where name = _binary 'abc' for update",
"Query": "delete from user where name = _binary 'abc'",
"Table": "user"
}
}
7 changes: 4 additions & 3 deletions go/vt/vtgate/planbuilder/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ func buildChangedVindexesValues(update *sqlparser.Update, colVindexes []*vindexe
// extractValueFromUpdate given an UpdateExpr attempts to extracts the Value
// it's holding. At the moment it only supports: StrVal, HexVal, IntVal, ValArg.
// If a complex expression is provided (e.g set name = name + 1), the update will be rejected.
func extractValueFromUpdate(upd *sqlparser.UpdateExpr) (pv sqltypes.PlanValue, err error) {
if !sqlparser.IsValue(upd.Expr) && !sqlparser.IsNull(upd.Expr) {
func extractValueFromUpdate(upd *sqlparser.UpdateExpr) (sqltypes.PlanValue, error) {
pv, err := sqlparser.NewPlanValue(upd.Expr)
if err != nil || sqlparser.IsSimpleTuple(upd.Expr) {
err := vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: Only values are supported. Invalid update on column: %v", upd.Name.Name)
return sqltypes.PlanValue{}, err
}
return sqlparser.NewPlanValue(upd.Expr)
return pv, nil
}