Skip to content

Commit

Permalink
vindex function: error when keyspace not selected (vitessio#16534)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal authored Aug 6, 2024
1 parent 4a89749 commit 623e820
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/fake_vcursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (t *noopVCursor) ExceedsMaxMemoryRows(numRows int) bool {
}

func (t *noopVCursor) GetKeyspace() string {
return ""
return "test_ks"
}

func (t *noopVCursor) RecordWarning(warning *querypb.QueryWarning) {
Expand Down
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 623e820

Please sign in to comment.