diff --git a/data/test/vtgate/dml_cases.txt b/data/test/vtgate/dml_cases.txt index fc06a5f3558..926b934edf2 100644 --- a/data/test/vtgate/dml_cases.txt +++ b/data/test/vtgate/dml_cases.txt @@ -1015,6 +1015,10 @@ } } +# insert into a vindex not allowed +"insert into user_index(id) values(1)" +"inserting into a vindex not allowed: user_index" + # simple replace unsharded "replace into unsharded values(1, 2)" { diff --git a/data/test/vtgate/unsupported_cases.txt b/data/test/vtgate/unsupported_cases.txt index 34c55f58baf..8d9687f8b96 100644 --- a/data/test/vtgate/unsupported_cases.txt +++ b/data/test/vtgate/unsupported_cases.txt @@ -253,7 +253,7 @@ # multi delete multi table "delete user from user join user_extra on user.id = user_extra.id where user.name = 'foo'" -"unsupported: multi-table delete statement in sharded keyspace" +"unsupported: multi-table/vindex delete statement in sharded keyspace" # scatter delete with owned lookup vindex "delete from user" @@ -289,11 +289,11 @@ # join in update tables "update user join user_extra on user.id = user_extra.id set user.name = 'foo'" -"unsupported: multi-table update statement in sharded keyspace" +"unsupported: multi-table/vindex update statement in sharded keyspace" # multiple tables in update "update user as u, user_extra as ue set u.name = 'foo' where u.id = ue.id" -"unsupported: multi-table update statement in sharded keyspace" +"unsupported: multi-table/vindex update statement in sharded keyspace" # unsharded insert with cross-shard join" "insert into unsharded select u.col from user u join user u1" diff --git a/go/vt/vtgate/planbuilder/delete.go b/go/vt/vtgate/planbuilder/delete.go index 4706a7718f2..0e969084476 100644 --- a/go/vt/vtgate/planbuilder/delete.go +++ b/go/vt/vtgate/planbuilder/delete.go @@ -39,7 +39,7 @@ func buildDeletePlan(del *sqlparser.Delete, vschema ContextVSchema) (*engine.Del } rb, ok := pb.bldr.(*route) if !ok { - return nil, errors.New("unsupported: multi-table delete statement in sharded keyspace") + return nil, errors.New("unsupported: multi-table/vindex delete statement in sharded keyspace") } edel.Keyspace = rb.ERoute.Keyspace if !edel.Keyspace.Sharded { diff --git a/go/vt/vtgate/planbuilder/insert.go b/go/vt/vtgate/planbuilder/insert.go index ad530e710cd..4ba900513b0 100644 --- a/go/vt/vtgate/planbuilder/insert.go +++ b/go/vt/vtgate/planbuilder/insert.go @@ -34,8 +34,11 @@ func buildInsertPlan(ins *sqlparser.Insert, vschema ContextVSchema) (*engine.Ins if err := pb.processAliasedTable(aliased); err != nil { return nil, err } - // route is guaranteed because of simple table expr. - rb := pb.bldr.(*route) + rb, ok := pb.bldr.(*route) + if !ok { + // This can happen only for vindexes right now. + return nil, fmt.Errorf("inserting into a vindex not allowed: %s", sqlparser.String(ins.Table)) + } if rb.ERoute.TargetDestination != nil { return nil, errors.New("unsupported: INSERT with a target destination") } diff --git a/go/vt/vtgate/planbuilder/update.go b/go/vt/vtgate/planbuilder/update.go index 33c4a366d4b..dc7f6eb94b8 100644 --- a/go/vt/vtgate/planbuilder/update.go +++ b/go/vt/vtgate/planbuilder/update.go @@ -40,7 +40,7 @@ func buildUpdatePlan(upd *sqlparser.Update, vschema ContextVSchema) (*engine.Upd } rb, ok := pb.bldr.(*route) if !ok { - return nil, errors.New("unsupported: multi-table update statement in sharded keyspace") + return nil, errors.New("unsupported: multi-table/vindex update statement in sharded keyspace") } if rb.ERoute.TargetDestination != nil { return nil, errors.New("unsupported: UPDATE with a target destination")