diff --git a/src/vitess-tester/query.go b/src/vitess-tester/query.go index 123b61d..0d8fe52 100644 --- a/src/vitess-tester/query.go +++ b/src/vitess-tester/query.go @@ -127,6 +127,7 @@ const ( Q_COMMENT_WITH_COMMAND Q_EMPTY_LINE Q_SKIP_IF_BELOW_VERSION + Q_VEXPLAIN ) // ParseQueries parses an array of string into an array of query object. diff --git a/src/vitess-tester/tester.go b/src/vitess-tester/tester.go index cdf4fc7..284e88f 100644 --- a/src/vitess-tester/tester.go +++ b/src/vitess-tester/tester.go @@ -41,6 +41,7 @@ type tester struct { skipBinary string skipVersion int skipNext bool + vexplain string // check expected error, use --error before the statement // we only care if an error is returned, not the exact error message. @@ -131,6 +132,14 @@ func (t *tester) Run() error { } case Q_ERROR: t.expectedErrs = true + case Q_VEXPLAIN: + strs := strings.Split(q.Query, " ") + if len(strs) != 2 { + t.reporter.AddFailure(fmt.Errorf("incorrect syntax for Q_VEXPLAIN in: %v", q.Query)) + continue + } + + t.vexplain = strs[1] case Q_QUERY: if t.skipNext { t.skipNext = false @@ -143,6 +152,16 @@ func (t *tester) Run() error { continue } } + if t.vexplain != "" { + result, err := t.curr.VtConn.ExecuteFetch("vexplain "+t.vexplain+" "+q.Query, -1, false) + t.vexplain = "" + if err != nil { + t.reporter.AddFailure(err) + continue + } + + t.reporter.AddFailure(fmt.Errorf("VExplain Output:\n %s\n", result.Rows[0][0].ToString())) + } t.reporter.AddTestCase(q.Query, q.Line) if err = t.execute(q); err != nil && !t.expectedErrs { t.reporter.AddFailure(err) diff --git a/src/vitess-tester/type.go b/src/vitess-tester/type.go index f64016c..83c80fb 100644 --- a/src/vitess-tester/type.go +++ b/src/vitess-tester/type.go @@ -115,6 +115,7 @@ var commandMap = map[string]CmdType{ "begin_concurrent": Q_BEGIN_CONCURRENT, "end_concurrent": Q_END_CONCURRENT, "skip_if_below_version": Q_SKIP_IF_BELOW_VERSION, + "vexplain": Q_VEXPLAIN, } func findType(cmdName string) CmdType { diff --git a/t/subqueries.test b/t/subqueries.test index a0182a4..c6ab255 100644 --- a/t/subqueries.test +++ b/t/subqueries.test @@ -455,4 +455,18 @@ FROM GROUP BY id, name ORDER BY - (SELECT SUM(LENGTH(extra_info)) FROM user_extra WHERE user_extra.user_id = user.id); \ No newline at end of file + (SELECT SUM(LENGTH(extra_info)) FROM user_extra WHERE user_extra.user_id = user.id); + +select max((select min(user_id) from user_extra)) +from user +where id = 1; + +select + max((select group_concat(id, name) from user where id = 1)); + +--skip this is buggy at the moment +select max((select max(name) from user u1 where u1.id = u2.id)) +from user u2; + +select count(distinct name, id) +from user; \ No newline at end of file