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

Add support for showing global vgtid executed #7797

Merged
merged 13 commits into from
Apr 13, 2021
6 changes: 1 addition & 5 deletions go/sqltypes/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,5 @@ func PrintResults(results []*Result) string {
}

func split(str string) []string {
splits := strings.Split(str, "|")
for i, v := range splits {
splits[i] = strings.TrimSpace(v)
}
return splits
return strings.Split(str, "|")
}
25 changes: 21 additions & 4 deletions go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ import (
"fmt"
"testing"

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

"github.com/google/go-cmp/cmp"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"

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

func TestSelectNull(t *testing.T) {
Expand Down Expand Up @@ -595,6 +592,26 @@ func TestSubQueryOnTopOfSubQuery(t *testing.T) {
assertMatches(t, conn, "select id1 from t1 where id1 not in (select id3 from t2) and id2 in (select id4 from t2) order by id1", `[[INT64(3)] [INT64(4)]]`)
}

func TestShowVGtid(t *testing.T) {
conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()

query := "show global vgtid_executed from ks"
qr := exec(t, conn, query)
require.Equal(t, 1, len(qr.Rows))
require.Equal(t, 2, len(qr.Rows[0]))

defer exec(t, conn, `delete from t1`)
exec(t, conn, `insert into t1(id1, id2) values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)`)
qr2 := exec(t, conn, query)
require.Equal(t, 1, len(qr2.Rows))
require.Equal(t, 2, len(qr2.Rows[0]))

require.Equal(t, qr.Rows[0][0], qr2.Rows[0][0], "keyspace should be same")
require.NotEqual(t, qr.Rows[0][1].ToString(), qr2.Rows[0][1].ToString(), "vgtid should have changed")
}

func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) {
t.Helper()
qr := exec(t, conn, query)
Expand Down
2 changes: 2 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,8 @@ func (ty ShowCommandType) ToString() string {
return VariableGlobalStr
case VariableSession:
return VariableSessionStr
case VGtidExecGlobal:
return VGtidExecGlobalStr
case VitessMigrations:
return VitessMigrationsStr
case Keyspace:
Expand Down
3 changes: 3 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const (
TriggerStr = " triggers"
VariableGlobalStr = " global variables"
VariableSessionStr = " variables"
VGtidExecGlobalStr = " global vgtid_executed"
KeyspaceStr = " keyspaces"
VitessMigrationsStr = " vitess_migrations"

Expand Down Expand Up @@ -493,6 +494,7 @@ const (
Trigger
VariableGlobal
VariableSession
VGtidExecGlobal
VitessMigrations
Keyspace
)
Expand All @@ -512,6 +514,7 @@ const (
ExclusiveType
)

// AlterMigrationType constants
const (
RetryMigrationType AlterMigrationType = iota
CompleteMigrationType
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ var keywords = []keyword{
{"varchar", VARCHAR},
{"varcharacter", UNUSED},
{"varying", UNUSED},
{"vgtid_executed", VGTID_EXECUTED},
{"virtual", UNUSED},
{"vindex", VINDEX},
{"vindexes", VINDEXES},
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,10 @@ var (
}, {
input: "show session variables",
output: "show variables",
}, {
input: "show global vgtid_executed",
}, {
input: "show global vgtid_executed from ks",
}, {
input: "show vitess_keyspaces",
output: "show keyspaces",
Expand Down
Loading