Skip to content

Commit

Permalink
error when keyspace not selected on vindex function
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Aug 5, 2024
1 parent 33030b7 commit 173b68c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/vt/vtgate/engine/vindex_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (vf *VindexFunc) mapVindex(ctx context.Context, vcursor VCursor, bindVars m
case key.DestinationKeyspaceID:
if len(d) > 0 {
if vcursor != nil {
if vcursor.GetKeyspace() == "" {
return nil, vterrors.VT09005()
}
resolvedShards, _, err := vcursor.ResolveDestinations(ctx, vcursor.GetKeyspace(), nil, []key.Destination{d})
if err != nil {
return nil, err
Expand Down
13 changes: 13 additions & 0 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,19 @@ func TestSetSystemVariablesWithReservedConnection(t *testing.T) {
sbc1.Queries = nil
}

func TestSelectVindexFunc(t *testing.T) {
executor, _, _, _, _ := createExecutorEnv(t)

query := "select * from hash_index where id = 1"
session := NewAutocommitSession(&vtgatepb.Session{})
_, err := executor.Execute(context.Background(), nil, "TestSelectVindexFunc", session, query, nil)
require.ErrorContains(t, err, "VT09005: no database selected")

session.TargetString = KsTestSharded
_, err = executor.Execute(context.Background(), nil, "TestSelectVindexFunc", session, query, nil)
require.NoError(t, err)
}

func TestCreateTableValidTimestamp(t *testing.T) {
executor, sbc1, _, _, _ := createExecutorEnv(t)
executor.normalize = true
Expand Down

0 comments on commit 173b68c

Please sign in to comment.