diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index 885499d87a2..4e5c4760477 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -18,14 +18,17 @@ package planbuilder import ( "bufio" - "bytes" "encoding/json" "fmt" "io" + "io/ioutil" "os" "strings" "testing" + "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" + "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/key" "vitess.io/vitess/go/vt/sqlparser" @@ -140,29 +143,30 @@ func init() { func TestPlan(t *testing.T) { vschema := loadSchema(t, "schema_test.json") - + testOutputTempDir, err := ioutil.TempDir("", "plan_test") + require.NoError(t, err) // You will notice that some tests expect user.Id instead of user.id. // This is because we now pre-create vindex columns in the symbol // table, which come from vschema. In the test vschema, // the column is named as Id. This is to make sure that // column names are case-preserved, but treated as // case-insensitive even if they come from the vschema. - testFile(t, "aggr_cases.txt", vschema) - testFile(t, "dml_cases.txt", vschema) - testFile(t, "from_cases.txt", vschema) - testFile(t, "filter_cases.txt", vschema) - testFile(t, "postprocess_cases.txt", vschema) - testFile(t, "select_cases.txt", vschema) - testFile(t, "symtab_cases.txt", vschema) - testFile(t, "unsupported_cases.txt", vschema) - testFile(t, "vindex_func_cases.txt", vschema) - testFile(t, "wireup_cases.txt", vschema) - testFile(t, "memory_sort_cases.txt", vschema) + testFile(t, "aggr_cases.txt", testOutputTempDir, vschema) + testFile(t, "dml_cases.txt", testOutputTempDir, vschema) + testFile(t, "from_cases.txt", testOutputTempDir, vschema) + testFile(t, "filter_cases.txt", testOutputTempDir, vschema) + testFile(t, "postprocess_cases.txt", testOutputTempDir, vschema) + testFile(t, "select_cases.txt", testOutputTempDir, vschema) + testFile(t, "symtab_cases.txt", testOutputTempDir, vschema) + testFile(t, "unsupported_cases.txt", testOutputTempDir, vschema) + testFile(t, "vindex_func_cases.txt", testOutputTempDir, vschema) + testFile(t, "wireup_cases.txt", testOutputTempDir, vschema) + testFile(t, "memory_sort_cases.txt", testOutputTempDir, vschema) } func TestOne(t *testing.T) { vschema := loadSchema(t, "schema_test.json") - testFile(t, "onecase.txt", vschema) + testFile(t, "onecase.txt", "", vschema) } func loadSchema(t *testing.T, filename string) *vindexes.VSchema { @@ -225,35 +229,48 @@ type testPlan struct { Instructions engine.Primitive `json:",omitempty"` } -func testFile(t *testing.T, filename string, vschema *vindexes.VSchema) { - for tcase := range iterateExecFile(filename) { - t.Run(tcase.comments, func(t *testing.T) { - plan, err := Build(tcase.input, &vschemaWrapper{ - v: vschema, - }) - var out string - if err != nil { - out = err.Error() - } else { - bout, _ := json.Marshal(testPlan{ - Original: plan.Original, - Instructions: plan.Instructions, +func testFile(t *testing.T, filename, tempDir string, vschema *vindexes.VSchema) { + t.Run(filename, func(t *testing.T) { + expected := &strings.Builder{} + fail := false + for tcase := range iterateExecFile(filename) { + t.Run(tcase.comments, func(t *testing.T) { + plan, err := Build(tcase.input, &vschemaWrapper{ + v: vschema, }) - out = string(bout) - } - if out != tcase.output { - t.Errorf("File: %s, Line:%v\n got:\n%s, \nwant:\n%s", filename, tcase.lineno, out, tcase.output) - // Uncomment these lines to re-generate input files + + out := getPlanOrErrorOutput(err, plan) + + if out != tcase.output { + fail = true + t.Errorf("File: %s, Line: %v\n %s", filename, tcase.lineno, cmp.Diff(out, tcase.output)) + } + if err != nil { - out = fmt.Sprintf("\"%s\"", out) - } else { - bout, _ := json.MarshalIndent(plan, "", " ") - out = string(bout) + out = `"` + out + `"` } - fmt.Printf("%s\"%s\"\n%s\n\n", tcase.comments, tcase.input, out) - } - }) + + expected.WriteString(fmt.Sprintf("%s\"%s\"\n%s\n\n", tcase.comments, tcase.input, out)) + + }) + } + if fail && tempDir != "" { + gotFile := fmt.Sprintf("%s/%s", tempDir, filename) + ioutil.WriteFile(gotFile, []byte(strings.TrimSpace(expected.String())+"\n"), 0644) + fmt.Println(fmt.Sprintf("Errors found in plantests. If the output is correct, run `cp %s/* testdata/` to update test expectations", tempDir)) + } + }) +} + +func getPlanOrErrorOutput(err error, plan *engine.Plan) string { + if err != nil { + return err.Error() } + bout, _ := json.MarshalIndent(testPlan{ + Original: plan.Original, + Instructions: plan.Instructions, + }, "", " ") + return string(bout) } type testCase struct { @@ -281,8 +298,7 @@ func iterateExecFile(name string) (testCaseIterator chan testCase) { binput, err := r.ReadBytes('\n') if err != nil { if err != io.EOF { - fmt.Printf("Line: %d\n", lineno) - panic(fmt.Errorf("error reading file %s: %s", name, err.Error())) + panic(fmt.Errorf("error reading file %s: line %d: %s", name, lineno, err.Error())) } break } @@ -297,8 +313,7 @@ func iterateExecFile(name string) (testCaseIterator chan testCase) { } err = json.Unmarshal(binput, &input) if err != nil { - fmt.Printf("Line: %d, input: %s\n", lineno, binput) - panic(err) + panic(fmt.Sprintf("Line: %d, input: %s, error: %v\n", lineno, binput, err)) } input = strings.Trim(input, "\"") var output []byte @@ -306,19 +321,11 @@ func iterateExecFile(name string) (testCaseIterator chan testCase) { l, err := r.ReadBytes('\n') lineno++ if err != nil { - fmt.Printf("Line: %d\n", lineno) - panic(fmt.Errorf("error reading file %s: %s", name, err.Error())) + panic(fmt.Sprintf("error reading file %s line# %d: %s", name, lineno, err.Error())) } output = append(output, l...) if l[0] == '}' { output = output[:len(output)-1] - b := bytes.NewBuffer(make([]byte, 0, 64)) - err := json.Compact(b, output) - if err == nil { - output = b.Bytes() - } else { - panic("Invalid JSON " + string(output) + err.Error()) - } break } if l[0] == '"' { diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt index 05a8e4254e9..2ca7229980e 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt @@ -1,5 +1,5 @@ # Test cases in this file follow the code in ordered_aggregate.go. - +# # Aggregate on unsharded "select count(*), col from unsharded" { @@ -29,7 +29,9 @@ "Query": "select count(*), col from user where id = 1", "FieldQuery": "select count(*), col from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -532,7 +534,9 @@ "Query": "select id, count(*) as c from user group by id having id = 1 and c = 10", "FieldQuery": "select id, count(*) as c from user where 1 != 1 group by id", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -1037,7 +1041,6 @@ } } - # scatter aggregate group by invalid column number "select col from user group by 2" "column number out of range: 2" @@ -1341,19 +1344,21 @@ # Group by with collate operator "select user.col1 as a from user where user.id = 5 group by a collate utf8_general_ci" { - "Original":"select user.col1 as a from user where user.id = 5 group by a collate utf8_general_ci", - "Instructions":{ - "Opcode":"SelectEqualUnique", - "Keyspace":{ - "Name":"user", - "Sharded":true - }, - "Query":"select user.col1 as a from user where user.id = 5 group by a collate utf8_general_ci", - "FieldQuery":"select user.col1 as a from user where 1 != 1 group by a collate utf8_general_ci", - "Vindex":"user_index", - "Values":[5], - "Table": "user" - } + "Original": "select user.col1 as a from user where user.id = 5 group by a collate utf8_general_ci", + "Instructions": { + "Opcode": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "select user.col1 as a from user where user.id = 5 group by a collate utf8_general_ci", + "FieldQuery": "select user.col1 as a from user where 1 != 1 group by a collate utf8_general_ci", + "Vindex": "user_index", + "Values": [ + 5 + ], + "Table": "user" + } } # routing rules for aggregates where sharded and unsharded match. Unsharded always wins. diff --git a/go/vt/vtgate/planbuilder/testdata/dml_cases.txt b/go/vt/vtgate/planbuilder/testdata/dml_cases.txt index d59e99cdbf5..83bc66ec874 100644 --- a/go/vt/vtgate/planbuilder/testdata/dml_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/dml_cases.txt @@ -149,12 +149,13 @@ }, "Query": "update user set val = 1 where id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } - # update by primary keyspace id with alias "update user as user_alias set val = 1 where user_alias.id = 1" { @@ -167,7 +168,9 @@ }, "Query": "update user as user_alias set val = 1 where user_alias.id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -203,7 +206,9 @@ }, "Query": "update user set val = 1 where (name = 'foo' and id = 1)", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -220,9 +225,13 @@ }, "Query": "update user_metadata set email = 'juan@vitess.io' where user_id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "ChangedVindexValues": { - "email_user_map": ["juan@vitess.io"] + "email_user_map": [ + "juan@vitess.io" + ] }, "Table": "user_metadata", "OwnedVindexQuery": "select email, address from user_metadata where user_id = 1 for update" @@ -245,10 +254,16 @@ }, "Query": "update user_metadata set email = 'juan@vitess.io', address = '155 5th street' where user_id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "ChangedVindexValues": { - "address_user_map": ["155 5th street"], - "email_user_map": ["juan@vitess.io"] + "address_user_map": [ + "155 5th street" + ], + "email_user_map": [ + "juan@vitess.io" + ] }, "Table": "user_metadata", "OwnedVindexQuery": "select email, address from user_metadata where user_id = 1 for update" @@ -271,7 +286,9 @@ 1 ], "ChangedVindexValues": { - "email_user_map": ["juan@vitess.io"] + "email_user_map": [ + "juan@vitess.io" + ] }, "Table": "user_metadata", "OwnedVindexQuery": "select email, address from user_metadata where user_id = 1 order by user_id asc limit 10 for update" @@ -290,7 +307,9 @@ }, "Query": "update user set val = 1 where id = id2 and id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -307,7 +326,9 @@ }, "Query": "update user set val = 1 where id = 18446744073709551616 and id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -324,7 +345,9 @@ }, "Query": "delete from user where id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user", "OwnedVindexQuery": "select Name, Costly from user where id = 1 for update" } @@ -418,7 +441,9 @@ }, "Query": "update music set val = 1 where id = 1", "Vindex": "music_user_map", - "Values": [1], + "Values": [ + 1 + ], "Table": "music" } } @@ -430,9 +455,9 @@ "Instructions": { "Opcode": "UpdateUnsharded", "Keyspace": { - "Name": "main", - "Sharded": false - }, + "Name": "main", + "Sharded": false + }, "Query": "update unsharded_a as a join unsharded_b as b on a.id = b.id set a.val = 'foo' where b.val = 1" } } @@ -463,7 +488,9 @@ }, "Query": "delete from music where id = 1", "Vindex": "music_user_map", - "Values": [1], + "Values": [ + 1 + ], "Table": "music", "OwnedVindexQuery": "select id from music where id = 1 for update" } @@ -481,7 +508,9 @@ }, "Query": "delete from music_extra where user_id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "music_extra" } } @@ -758,7 +787,6 @@ } } - # unsharded insert subquery in insert value "insert into unsharded values((select 1 from dual), 1)" { @@ -865,7 +893,23 @@ "Sharded": true }, "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -873,10 +917,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1] + "Values": [ + 1 + ] }, "Prefix": "insert into user(id, Name, Costly) values ", - "Mid":["(:_Id0, :_Name0, :_Costly0)"] + "Mid": [ + "(:_Id0, :_Name0, :_Costly0)" + ] } } @@ -891,7 +939,23 @@ "Sharded": true }, "Query": "insert ignore into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -899,10 +963,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1] + "Values": [ + 1 + ] }, "Prefix": "insert ignore into user(id, Name, Costly) values ", - "Mid":["(:_Id0, :_Name0, :_Costly0)"] + "Mid": [ + "(:_Id0, :_Name0, :_Costly0)" + ] } } @@ -917,7 +985,23 @@ "Sharded": true }, "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0) on duplicate key update col = 2", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -948,7 +1032,23 @@ "Sharded": true }, "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -978,7 +1078,23 @@ "Sharded": true }, "Query": "insert into user(nonid, id, Name, Costly) values (2, :_Id0, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -986,10 +1102,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [null] + "Values": [ + null + ] }, "Prefix": "insert into user(nonid, id, Name, Costly) values ", - "Mid": ["(2, :_Id0, :_Name0, :_Costly0)"] + "Mid": [ + "(2, :_Id0, :_Name0, :_Costly0)" + ] } } @@ -1004,7 +1124,23 @@ "Sharded": true }, "Query": "insert into user(id, nonid, Name, Costly) values (:_Id0, 2, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1012,10 +1148,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [null] + "Values": [ + null + ] }, "Prefix": "insert into user(id, nonid, Name, Costly) values ", - "Mid": ["(:_Id0, 2, :_Name0, :_Costly0)"] + "Mid": [ + "(:_Id0, 2, :_Name0, :_Costly0)" + ] } } @@ -1030,7 +1170,23 @@ "Sharded": true }, "Query": "insert into user(nonid, id, Name, Costly) values (true, :_Id0, :_Name0, :_Costly0)", - "Values": [[[":__seq0"]],[[null]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + null + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1038,10 +1194,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [null] + "Values": [ + null + ] }, "Prefix": "insert into user(nonid, id, Name, Costly) values ", - "Mid": ["(true, :_Id0, :_Name0, :_Costly0)"] + "Mid": [ + "(true, :_Id0, :_Name0, :_Costly0)" + ] } } @@ -1056,7 +1216,23 @@ "Sharded": true }, "Query": "insert into user(nonid, name, id, Costly) values (2, :_Name0, :_Id0, :_Costly0)", - "Values": [[[":__seq0"]],[["foo"]],[[null]]], + "Values": [ + [ + [ + ":__seq0" + ] + ], + [ + [ + "foo" + ] + ], + [ + [ + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1064,10 +1240,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1] + "Values": [ + 1 + ] }, "Prefix": "insert into user(nonid, name, id, Costly) values ", - "Mid": ["(2, :_Name0, :_Id0, :_Costly0)"] + "Mid": [ + "(2, :_Name0, :_Id0, :_Costly0)" + ] } } @@ -1082,7 +1262,13 @@ "Sharded": true }, "Query": "insert into user_extra(nonid, extra_id, user_id) values (2, :__seq0, :_user_id0)", - "Values": [[[null]]], + "Values": [ + [ + [ + null + ] + ] + ], "Table": "user_extra", "Generate": { "Keyspace": { @@ -1090,10 +1276,14 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [null] + "Values": [ + null + ] }, "Prefix": "insert into user_extra(nonid, extra_id, user_id) values ", - "Mid": ["(2, :__seq0, :_user_id0)"] + "Mid": [ + "(2, :__seq0, :_user_id0)" + ] } } @@ -1108,7 +1298,13 @@ "Sharded": true }, "Query": "insert into `weird``name`(`a``b*c`, `b*c`) values (:_a_b_c0, 2)", - "Values": [[[1]]], + "Values": [ + [ + [ + 1 + ] + ] + ], "Table": "weird`name", "Prefix": "insert into `weird``name`(`a``b*c`, `b*c`) values ", "Mid": [ @@ -1159,7 +1355,26 @@ "Sharded": true }, "Query": "insert into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", - "Values": [[[":__seq0",":__seq1"]],[[null,null]],[[null,null]]], + "Values": [ + [ + [ + ":__seq0", + ":__seq1" + ] + ], + [ + [ + null, + null + ] + ], + [ + [ + null, + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1167,10 +1382,16 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1,2] + "Values": [ + 1, + 2 + ] }, "Prefix": "insert into user(id, Name, Costly) values ", - "Mid": ["(:_Id0, :_Name0, :_Costly0)","(:_Id1, :_Name1, :_Costly1)"] + "Mid": [ + "(:_Id0, :_Name0, :_Costly0)", + "(:_Id1, :_Name1, :_Costly1)" + ] } } @@ -1185,7 +1406,26 @@ "Sharded": true }, "Query": "insert /*vt+ QUERY_TIMEOUT_MS=1 */ into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", - "Values": [[[":__seq0",":__seq1"]],[[null,null]],[[null,null]]], + "Values": [ + [ + [ + ":__seq0", + ":__seq1" + ] + ], + [ + [ + null, + null + ] + ], + [ + [ + null, + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1193,10 +1433,16 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1,2] + "Values": [ + 1, + 2 + ] }, "Prefix": "insert /*vt+ QUERY_TIMEOUT_MS=1 */ into user(id, Name, Costly) values ", - "Mid": ["(:_Id0, :_Name0, :_Costly0)","(:_Id1, :_Name1, :_Costly1)"], + "Mid": [ + "(:_Id0, :_Name0, :_Costly0)", + "(:_Id1, :_Name1, :_Costly1)" + ], "QueryTimeout": 1 } } @@ -1212,7 +1458,26 @@ "Sharded": true }, "Query": "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user(id, Name, Costly) values (:_Id0, :_Name0, :_Costly0), (:_Id1, :_Name1, :_Costly1)", - "Values": [[[":__seq0",":__seq1"]],[[null,null]],[[null,null]]], + "Values": [ + [ + [ + ":__seq0", + ":__seq1" + ] + ], + [ + [ + null, + null + ] + ], + [ + [ + null, + null + ] + ] + ], "Table": "user", "Generate": { "Keyspace": { @@ -1220,10 +1485,16 @@ "Sharded": false }, "Query": "select next :n values from seq", - "Values": [1,2] + "Values": [ + 1, + 2 + ] }, "Prefix": "insert /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ into user(id, Name, Costly) values ", - "Mid": ["(:_Id0, :_Name0, :_Costly0)","(:_Id1, :_Name1, :_Costly1)"], + "Mid": [ + "(:_Id0, :_Name0, :_Costly0)", + "(:_Id1, :_Name1, :_Costly1)" + ], "MultiShardAutocommit": true } } @@ -1419,7 +1690,6 @@ } } - # insert multiple rows in a multi column vindex table "insert multicolvin (column_a, column_b, column_c, kid) VALUES (1,2,3,4), (5,6,7,8)" { @@ -1581,7 +1851,7 @@ }, "Query": "update /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ user_extra set val = 1", "Table": "user_extra", - "MultiShardAutocommit": true + "MultiShardAutocommit": true } } @@ -1631,7 +1901,6 @@ } } - # update with non-unique key "update user_extra set val = 1 where name = 'foo'" { @@ -1791,8 +2060,8 @@ "Instructions": { "Opcode": "UpdateUnsharded", "Keyspace": { - "Name":"main", - "Sharded":false + "Name": "main", + "Sharded": false }, "Query": "update unsharded set col = (select id from unsharded_a where id = unsharded.col) where col = (select id from unsharded_b)" } @@ -1824,9 +2093,13 @@ }, "Query": "update user set name = null where id = 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "ChangedVindexValues": { - "name_user_map": [null] + "name_user_map": [ + null + ] }, "Table": "user", "OwnedVindexQuery": "select Name, Costly from user where id = 1 for update" diff --git a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt index 53fae69ba05..6e059a0a7ac 100644 --- a/go/vt/vtgate/planbuilder/testdata/filter_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/filter_cases.txt @@ -27,7 +27,9 @@ "Query": "select id from user where user.id = 5", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -61,7 +63,9 @@ "Query": "select id from music where id = 5 and user_id = 4", "FieldQuery": "select id from music where 1 != 1", "Vindex": "user_index", - "Values": [4], + "Values": [ + 4 + ], "Table": "music" } } @@ -79,7 +83,9 @@ "Query": "select id from user where costly = 'aa' and name = 'bb'", "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", - "Values": ["bb"], + "Values": [ + "bb" + ], "Table": "user" } } @@ -98,7 +104,10 @@ "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", "Values": [ - ["aa", "bb"] + [ + "aa", + "bb" + ] ], "Table": "user" } @@ -133,7 +142,9 @@ "Query": "select id from user where name = :a", "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", - "Values": [":a"], + "Values": [ + ":a" + ], "Table": "user" } } @@ -151,7 +162,9 @@ "Query": "select id from user where name = 18446744073709551615", "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", - "Values": [18446744073709551615], + "Values": [ + 18446744073709551615 + ], "Table": "user" } } @@ -169,7 +182,9 @@ "Query": "select id from user where name in ::__vals", "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", - "Values": ["::list"], + "Values": [ + "::list" + ], "Table": "user" } } @@ -187,7 +202,9 @@ "Query": "select user_extra.id from user join user_extra on user.id = user_extra.user_id where user.id = 5", "FieldQuery": "select user_extra.id from user join user_extra on user.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -205,7 +222,9 @@ "Query": "select user_extra.id from user join user_extra on user.id = user_extra.user_id where user_extra.user_id = 5", "FieldQuery": "select user_extra.id from user join user_extra on user.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -223,7 +242,9 @@ "Query": "select user_extra.id from user left join user_extra on user.id = user_extra.user_id where user.id = 5", "FieldQuery": "select user_extra.id from user left join user_extra on user.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -263,7 +284,9 @@ "Query": "select user.col from user where user.id = 5", "FieldQuery": "select user.col from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Right": { @@ -300,7 +323,9 @@ "Query": "select user.col from user where user.id = 5", "FieldQuery": "select user.col from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Right": { @@ -312,7 +337,9 @@ "Query": "select user_extra.id from user_extra where user_extra.col = :user_col and user_extra.user_id = 5", "FieldQuery": "select user_extra.id from user_extra where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user_extra" }, "Cols": [ @@ -349,7 +376,9 @@ "Query": "select user_extra.id from user_extra where user_extra.col = :user_col and user_extra.user_id = :user_col", "FieldQuery": "select user_extra.id from user_extra where 1 != 1", "Vindex": "user_index", - "Values": [":user_col"], + "Values": [ + ":user_col" + ], "Table": "user_extra" }, "Cols": [ @@ -410,7 +439,10 @@ "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", "Values": [ - [1, 2] + [ + 1, + 2 + ] ], "Table": "user" } @@ -430,7 +462,10 @@ "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", "Values": [ - [1, 2] + [ + 1, + 2 + ] ], "Table": "user" } @@ -449,7 +484,9 @@ "Query": "select (id or col) as val from user where user.col = 5 and user.id in (1, 2) and user.name = 'aa'", "FieldQuery": "select (id or col) as val from user where 1 != 1", "Vindex": "name_user_map", - "Values": ["aa"], + "Values": [ + "aa" + ], "Table": "user" } } @@ -467,7 +504,9 @@ "Query": "select id from user where user.col = false and user.id in (1, 2) and user.name = 'aa'", "FieldQuery": "select id from user where 1 != 1", "Vindex": "name_user_map", - "Values": ["aa"], + "Values": [ + "aa" + ], "Table": "user" } } @@ -485,7 +524,9 @@ "Query": "select id from user where user.col = 5 and user.id in (1, 2) and user.name = 'aa' and user.id = 1", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -503,7 +544,9 @@ "Query": "select id from user where user.id = 1 and user.name = 'aa' and user.id in (1, 2) and user.col = 5", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -640,7 +683,10 @@ "FieldQuery": "select u.m from user as u where 1 != 1", "Vindex": "user_index", "Values": [ - [":user_extra_col", 1] + [ + ":user_extra_col", + 1 + ] ], "Table": "user" }, @@ -678,7 +724,9 @@ "Query": "select u.m from user as u where u.id = 5 and u.id in (select m2 from user where user.id = 5)", "FieldQuery": "select u.m from user as u where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Cols": [ @@ -713,7 +761,10 @@ "FieldQuery": "select u.m from user as u where 1 != 1", "Vindex": "user_index", "Values": [ - [":user_extra_col", 1] + [ + ":user_extra_col", + 1 + ] ], "Table": "user" }, @@ -755,7 +806,9 @@ "Query": "select id from user where id = 5 and user.col in (select user_extra.col from user_extra where user_extra.user_id = 5)", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -773,7 +826,9 @@ "Query": "select id from user where id = 'aa' and user.col in (select user_extra.col from user_extra where user_extra.user_id = 'aa')", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": ["aa"], + "Values": [ + "aa" + ], "Table": "user" } } @@ -791,7 +846,9 @@ "Query": "select id from user where id = :a and user.col in (select user_extra.col from user_extra where user_extra.user_id = :a)", "FieldQuery": "select id from user where 1 != 1", "Vindex": "user_index", - "Values": [":a"], + "Values": [ + ":a" + ], "Table": "user" } } @@ -1063,7 +1120,9 @@ "Query": "select user_extra.Id from user join user_extra on user.iD = user_extra.User_Id where user.Id = 5", "FieldQuery": "select user_extra.Id from user join user_extra on user.iD = user_extra.User_Id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.txt b/go/vt/vtgate/planbuilder/testdata/from_cases.txt index d8b6ed9ee6e..928ff6d0c22 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.txt @@ -715,7 +715,9 @@ "Query": "select user.col from user join user_extra on user.id = 5 and user.id = user_extra.user_id", "FieldQuery": "select user.col from user join user_extra on user.id = 5 and user.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -770,7 +772,9 @@ "Query": "select user.col from user where user.id = 5", "FieldQuery": "select user.col from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Right": { @@ -804,7 +808,9 @@ "Query": "select user.col from user where user.id = 5", "FieldQuery": "select user.col from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Right": { @@ -883,7 +889,9 @@ "Query": "select user.col from user where user.name = :user_extra_user_id", "FieldQuery": "select user.col from user where 1 != 1", "Vindex": "name_user_map", - "Values": [":user_extra_user_id"], + "Values": [ + ":user_extra_user_id" + ], "Table": "user" }, "Cols": [ @@ -1004,7 +1012,9 @@ "Query": "select id from (select id, col from user where id = 5) as t", "FieldQuery": "select id from (select id, col from user where 1 != 1) as t where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1022,7 +1032,9 @@ "Query": "select t.id from (select id from user where id = 5) as t join user_extra on t.id = user_extra.user_id", "FieldQuery": "select t.id from (select id from user where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1040,7 +1052,9 @@ "Query": "select t.id from (select user.id from user where user.id = 5) as t join user_extra on t.id = user_extra.user_id", "FieldQuery": "select t.id from (select user.id from user where 1 != 1) as t join user_extra on t.id = user_extra.user_id where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1080,7 +1094,9 @@ "Query": "select t.id from (select id from user where id = 5) as t", "FieldQuery": "select t.id from (select id from user where 1 != 1) as t where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" }, "Right": { @@ -1115,7 +1131,9 @@ "Query": "select id from (select id, col from user as route1 where id = 5) as t", "FieldQuery": "select id from (select id, col from user as route1 where 1 != 1) as t where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1173,7 +1191,9 @@ "Query": "select u.col, e.col from (select col from user where id = 5) as u join (select col from user_extra where user_id = 5) as e", "FieldQuery": "select u.col, e.col from (select col from user where 1 != 1) as u join (select col from user_extra where 1 != 1) as e where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1370,7 +1390,6 @@ } } - # Join with cross-shard subquery on rhs "select t.col1 from unsharded_a ua join (select user.id, user.col1 from user join user_extra) as t" { @@ -1747,7 +1766,7 @@ # subquery with join primitive (FROM) "select id, t.id from (select user.id from user join user_extra) as t" -{ +{ "Original": "select id, t.id from (select user.id from user join user_extra) as t", "Instructions": { "Cols": [ diff --git a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt index cdc6a6909b3..8947e10666d 100644 --- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt @@ -1,5 +1,4 @@ # Test cases in this file follow the code in memory_sort.go. - # scatter aggregate order by references ungrouped column "select a, b, count(*) from user group by a order by b" { @@ -533,7 +532,6 @@ "Query": "select un.col2 from unsharded as un", "FieldQuery": "select un.col2 from unsharded as un where 1 != 1", "Table": "unsharded" - }, "Right": { "Opcode": "SelectScatter", diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt index 3332bde4b7c..508e9ebee77 100644 --- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.txt @@ -133,7 +133,9 @@ "Query": "select col from user where id = 5 order by aa asc", "FieldQuery": "select col from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -151,7 +153,9 @@ "Query": "select col from user where id = 1 order by 1 asc", "FieldQuery": "select col from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -406,7 +410,9 @@ "Query": "select music.col3 from music where music.id = :user_id order by null", "FieldQuery": "select music.col3 from music where 1 != 1", "Vindex": "music_user_map", - "Values": [":user_id"], + "Values": [ + ":user_id" + ], "Table": "music" }, "Cols": [ @@ -646,7 +652,9 @@ "Query": "select * from user where id = 5 order by col asc", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -664,7 +672,9 @@ "Query": "select user.* from user where id = 5 order by user.col asc", "FieldQuery": "select user.* from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -682,7 +692,9 @@ "Query": "select * from user where id = 5 order by user.col asc", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -752,7 +764,9 @@ "Query": "select * from user where id = 5 order by user.col collate utf8_general_ci asc", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -760,73 +774,81 @@ #Order by with math functions "select * from user where id = 5 order by -col1" { - "Original":"select * from user where id = 5 order by -col1", - "Instructions":{ - "Opcode":"SelectEqualUnique", - "Keyspace":{ - "Name":"user", - "Sharded":true - }, - "Query":"select * from user where id = 5 order by -col1 asc", - "FieldQuery":"select * from user where 1 != 1", - "Vindex":"user_index", - "Values":[5], - "Table": "user" - } + "Original": "select * from user where id = 5 order by -col1", + "Instructions": { + "Opcode": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "select * from user where id = 5 order by -col1 asc", + "FieldQuery": "select * from user where 1 != 1", + "Vindex": "user_index", + "Values": [ + 5 + ], + "Table": "user" + } } #Order by with string operations "select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc" { - "Original":"select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc", - "Instructions":{ - "Opcode":"SelectEqualUnique", - "Keyspace":{ - "Name":"user", - "Sharded":true - }, - "Query":"select * from user where id = 5 order by concat(col, col1) collate utf8_general_ci desc", - "FieldQuery":"select * from user where 1 != 1", - "Vindex":"user_index", - "Values":[5], - "Table": "user" - } + "Original": "select * from user where id = 5 order by concat(col,col1) collate utf8_general_ci desc", + "Instructions": { + "Opcode": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "select * from user where id = 5 order by concat(col, col1) collate utf8_general_ci desc", + "FieldQuery": "select * from user where 1 != 1", + "Vindex": "user_index", + "Values": [ + 5 + ], + "Table": "user" + } } #Order by with math operations "select * from user where id = 5 order by id+col collate utf8_general_ci desc" { - "Original":"select * from user where id = 5 order by id+col collate utf8_general_ci desc", - "Instructions":{ - "Opcode":"SelectEqualUnique", - "Keyspace":{ - "Name":"user", - "Sharded":true - }, - "Query":"select * from user where id = 5 order by id + col collate utf8_general_ci desc", - "FieldQuery":"select * from user where 1 != 1", - "Vindex":"user_index", - "Values":[5], - "Table": "user" - } + "Original": "select * from user where id = 5 order by id+col collate utf8_general_ci desc", + "Instructions": { + "Opcode": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "select * from user where id = 5 order by id + col collate utf8_general_ci desc", + "FieldQuery": "select * from user where 1 != 1", + "Vindex": "user_index", + "Values": [ + 5 + ], + "Table": "user" + } } #Order by subquery column "select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id" { - "Original":"select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id", - "Instructions":{ - "Opcode":"SelectEqualUnique", - "Keyspace":{ - "Name":"user", - "Sharded":true - }, - "Query":"select * from user as u join (select user_id from user_extra where user_id = 5) as eu on u.id = eu.user_id where u.id = 5 order by eu.user_id asc", - "FieldQuery":"select * from user as u join (select user_id from user_extra where 1 != 1) as eu on u.id = eu.user_id where 1 != 1", - "Vindex":"user_index", - "Values":[5], - "Table": "user" - } + "Original": "select * from user u join (select user_id from user_extra where user_id = 5) eu on u.id = eu.user_id where u.id = 5 order by eu.user_id", + "Instructions": { + "Opcode": "SelectEqualUnique", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "Query": "select * from user as u join (select user_id from user_extra where user_id = 5) as eu on u.id = eu.user_id where u.id = 5 order by eu.user_id asc", + "FieldQuery": "select * from user as u join (select user_id from user_extra where 1 != 1) as eu on u.id = eu.user_id where 1 != 1", + "Vindex": "user_index", + "Values": [ + 5 + ], + "Table": "user" + } } # routing rules: order by test pushed to all options. table 1 is chosen. @@ -882,7 +904,9 @@ "Query": "select col1 from user where id = 1 limit 1", "FieldQuery": "select col1 from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt index 4d9f7891f82..c655e2f6d0e 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt @@ -443,7 +443,6 @@ } } - # select from dual on sharded keyspace "select @@session.auto_increment_increment from user.dual" { @@ -785,7 +784,9 @@ "Query": "select * from user where name = 'abc' and (id = 4) limit 5", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [4], + "Values": [ + 4 + ], "Table": "user" } } @@ -803,7 +804,9 @@ "Query": "select * from user where (id = 4) and (name = 'abc') limit 5", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [4], + "Values": [ + 4 + ], "Table": "user" } } @@ -841,7 +844,9 @@ "Query": "select user0_.col as col0_ from user as user0_ where id = 1 order by user0_.col desc limit 2", "FieldQuery": "select user0_.col as col0_ from user as user0_ where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -859,7 +864,9 @@ "Query": "select user0_.col as col0_ from user as user0_ where id = 1 order by col0_ desc limit 3", "FieldQuery": "select user0_.col as col0_ from user as user0_ where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -877,7 +884,9 @@ "Query": "select * from user where (id = 1) and name = true limit 5", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -895,7 +904,9 @@ "Query": "select * from user where (id = 1) and name limit 5", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "user" } } @@ -913,7 +924,9 @@ "Query": "select * from user where (id = 5) and name = true limit 5", "FieldQuery": "select * from user where 1 != 1", "Vindex": "user_index", - "Values": [5], + "Values": [ + 5 + ], "Table": "user" } } @@ -1055,7 +1068,9 @@ "Query": "select * from music where user_id = 1 union select * from user where id = 1", "FieldQuery": "select * from music where 1 != 1 union select * from user where 1 != 1", "Vindex": "user_index", - "Values": [1], + "Values": [ + 1 + ], "Table": "music" } } diff --git a/go/vt/vtgate/planbuilder/testdata/symtab_cases.txt b/go/vt/vtgate/planbuilder/testdata/symtab_cases.txt index e9d4d3a78b4..e094a6054ab 100644 --- a/go/vt/vtgate/planbuilder/testdata/symtab_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/symtab_cases.txt @@ -1,5 +1,5 @@ # Tests in this file are for testing symtab functionality - +# # Column names need not be qualified if they are predefined in vschema and unambiguous. "select predef2, predef3 from user join unsharded on predef2 = predef3" { diff --git a/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt b/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt index 5f91fd70352..6b3b182d2b7 100644 --- a/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt @@ -88,7 +88,11 @@ "type": 10262 } ], - "Cols": [0, 1, 0], + "Cols": [ + 0, + 1, + 0 + ], "Vindex": "user_index", "Value": ":id" } @@ -128,7 +132,6 @@ } } - # You can even join with a vindexFunc primitive "select user_index.keyspace_id, unsharded.id from user_index join unsharded where user_index.id = :id" { @@ -143,7 +146,9 @@ "type": 10262 } ], - "Cols": [1], + "Cols": [ + 1 + ], "Vindex": "user_index", "Value": ":id" }, @@ -157,7 +162,10 @@ "FieldQuery": "select unsharded.id from unsharded where 1 != 1", "Table": "unsharded" }, - "Cols": [-1, 1] + "Cols": [ + -1, + 1 + ] } }