Skip to content
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

v3: Fix issue when no routes are found from a lookup #10422

Merged
merged 1 commit into from
Jun 4, 2022
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
113 changes: 113 additions & 0 deletions go/test/endtoend/vtgate/sec_vind/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2022 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vtgate

import (
"context"
_ "embed"
"flag"
"os"
"testing"

"vitess.io/vitess/go/test/endtoend/utils"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/test/endtoend/cluster"
)

var (
clusterInstance *cluster.LocalProcessCluster
vtParams mysql.ConnParams
KeyspaceName = "ks"
Cell = "test"
//go:embed schema.sql
SchemaSQL string

//go:embed vschema.json
VSchema string
)

func TestMain(m *testing.M) {
defer cluster.PanicHandler(nil)
flag.Parse()

exitCode := func() int {
clusterInstance = cluster.NewCluster(Cell, "localhost")
defer clusterInstance.Teardown()

// Start topo server
err := clusterInstance.StartTopo()
if err != nil {
return 1
}

// Start keyspace
keyspace := &cluster.Keyspace{
Name: KeyspaceName,
SchemaSQL: SchemaSQL,
VSchema: VSchema,
}
err = clusterInstance.StartKeyspace(*keyspace, []string{"-80", "80-"}, 1, true)
if err != nil {
return 1
}

// Start vtgate
err = clusterInstance.StartVtgate()
if err != nil {
return 1
}
vtParams = mysql.ConnParams{
Host: clusterInstance.Hostname,
Port: clusterInstance.VtgateMySQLPort,
}
return m.Run()
}()
os.Exit(exitCode)
}

func start(t *testing.T) (*mysql.Conn, func()) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.Nil(t, err)

deleteAll := func() {
_, _ = utils.ExecAllowError(t, conn, "set workload = oltp")

tables := []string{"t1", "lookup_t1"}
for _, table := range tables {
_, _ = utils.ExecAllowError(t, conn, "delete from "+table)
}
}

deleteAll()

return conn, func() {
deleteAll()
conn.Close()
cluster.PanicHandler(t)
}
}

func TestInAgainstSecondaryVindex(t *testing.T) {
conn, closer := start(t)
defer closer()

utils.AssertMatches(t, conn, `select 1 from t1 where c2 in ("abc")`, "[]")
}
11 changes: 11 additions & 0 deletions go/test/endtoend/vtgate/sec_vind/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE t1 (
c1 bigint unsigned NOT NULL,
c2 varchar(16) NOT NULL,
PRIMARY KEY (c1)
) ENGINE InnoDB;

CREATE TABLE lookup_t1 (
c2 varchar(16) NOT NULL,
keyspace_id varbinary(16) NOT NULL,
PRIMARY KEY (c2)
) ENGINE InnoDB;
39 changes: 39 additions & 0 deletions go/test/endtoend/vtgate/sec_vind/vschema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"sharded": true,
"vindexes": {
"lookup_idx": {
"type": "lookup",
"params": {
"from": "c2",
"to": "keyspace_id",
"table": "lookup_t1"
},
"owner": "t1"
},
"xxhash": {
"type": "xxhash"
}
},
"tables": {
"t1": {
"columnVindexes": [
{
"column": "c1",
"name": "xxhash"
},
{
"column": "c2",
"name": "lookup_idx"
}
]
},
"lookup_t1": {
"columnVindexes": [
{
"column": "c2",
"name": "xxhash"
}
]
}
}
}
4 changes: 2 additions & 2 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ func TestSelectBindvars(t *testing.T) {
})
require.NoError(t, err)
wantQueries = []*querypb.BoundQuery{{
Sql: "select id from `user` where `name` in ::__vals",
Sql: "select id from `user` where 1 != 1",
BindVariables: map[string]*querypb.BindVariable{
"name1": sqltypes.BytesBindVariable([]byte("foo1")),
"name2": sqltypes.BytesBindVariable([]byte("foo2")),
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func TestSelectBindvars(t *testing.T) {

// When there are no matching rows in the vindex, vtgate still needs the field info
wantQueries = []*querypb.BoundQuery{{
Sql: "select id from `user` where `name` = :name",
Sql: "select id from `user` where 1 != 1",
BindVariables: map[string]*querypb.BindVariable{
"name": sqltypes.StringBindVariable("nonexistent"),
},
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func buildSelectPlan(query string) stmtPlanner {
// if it doesn't find a shard to send the query to.
// All other engine primitives can handle this, so we only need it when
// Route is the last (and only) instruction before the user sees a result
rb.NoRoutesSpecialHandling = true
if isOnlyDual(sel) || (len(sel.GroupBy) == 0 && sel.SelectExprs.AllAggregation()) {
rb.NoRoutesSpecialHandling = true
}
}

return primitive, nil
Expand Down
9 changes: 9 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,15 @@
"RetryMax": 2,
"Tags": []
},
"vindex_secondary": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/vtgate/sec_vind"],
"Command": [],
"Manual": false,
"Shard": "vtgate_vindex_heavy",
"RetryMax": 2,
"Tags": []
},
"web_test": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/vtctldweb"],
Expand Down