diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index adffdfc..34f4add 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -965,3 +965,33 @@ func benchmarkPlanner(b *testing.B, version plancontext.PlannerVersion, testCase } } } + +func TestMySchema(t *testing.T) { + vschemaWrapper := &vschemaWrapper{ + v: loadSchema(t, "vschemas/my_schema.json", true), + sysVarEnabled: true, + } + testOutputTempDir := makeTestOutput(t) + + testFile(t, "my.json", testOutputTempDir, vschemaWrapper, false) +} + +func BenchmarkMine(b *testing.B) { + vschema := &vschemaWrapper{ + v: loadSchema(b, "vschemas/my_schema.json", true), + sysVarEnabled: true, + version: Gen4, + } + testCases := readJSONTests("my.json") + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + for _, tcase := range testCases { + plan, _ := TestBuilder(tcase.Query, vschema, vschema.currentDb()) + if plan == nil { + panic("") + } + } + } +} diff --git a/go/vt/vtgate/planbuilder/testdata/my.json b/go/vt/vtgate/planbuilder/testdata/my.json new file mode 100644 index 0000000..e9793af --- /dev/null +++ b/go/vt/vtgate/planbuilder/testdata/my.json @@ -0,0 +1,9 @@ +[ + { + "comment": "MyTest", + "query": "select col04, col03, col01, col02 from my_table where id in ((select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '2XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'9FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'VXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'AFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '6XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'6FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'ZXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'5FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'GXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'DFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'JXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'DFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '8XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'DFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'FXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'0FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'FXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'EFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'JXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'5FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'YXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'2FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'AFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'YXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'9FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '1XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'CFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'XXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'CFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'WXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'AFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '2XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'BFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'4FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'HXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'QXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'0FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'ZXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'EFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'NXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'BFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'XXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'BFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'WXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'AFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'PXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'3FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'BXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'4FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'XXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'5FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'TXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'4FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '4XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'DFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'KXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'4FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '3XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'FFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '0XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'AFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '1XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'JXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'3FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'SXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '5XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'2FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'KXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'5FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'XXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'CFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'7FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'XXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'FFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'HXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'2FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = '5XxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'BFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'CXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'DFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'NXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'EFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'TXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'CFFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'DXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'9FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'GXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'4FFF' order by col02 desc limit 0, 10000) union all (select id from my_table force index (MY_INDEX) where col02 <= 1234567890000 and col10 = 1234567890000000000 and col06 = 0 and col02 >= 1000000000000 and col01 = 'RXxXxXxXxXxXxXxXxXxXxXx' and sdKey = X'BFFF' order by col02 desc limit 0, 10000)) order by col01 desc, sdKey desc, col02 desc limit 0, 500000;", + "plan": { + + } + } +] diff --git a/go/vt/vtgate/planbuilder/testdata/vschemas/my_schema.json b/go/vt/vtgate/planbuilder/testdata/vschemas/my_schema.json new file mode 100644 index 0000000..abfcee6 --- /dev/null +++ b/go/vt/vtgate/planbuilder/testdata/vschemas/my_schema.json @@ -0,0 +1,110 @@ +{ + "keyspaces": { + "unsharded_ns": { + "sharded": false, + "tables": { + "my_table_seq": { + "type": "sequence", + "columns": [ + { + "name": "next_id", + "type": "UINT64" + }, + { + "name": "cache", + "type": "UINT32" + }, + { + "name": "id", + "type": "UINT64" + } + ], + "column_list_authoritative": true + } + } + }, + "main": { + "sharded": true, + "vindexes": { + "binary_vdx": { + "type": "binary" + } + }, + "tables": { + "my_table": { + "column_vindexes": [ + { + "columns": [ + "sdKey" + ], + "name": "binary_vdx" + } + ], + "auto_increment": { + "column": "id", + "sequence": "my_table_seq" + }, + "columns": [ + { + "name": "col01", + "type": "VARCHAR" + }, + { + "name": "col02", + "type": "INT64" + }, + { + "name": "col03", + "type": "BLOB" + }, + { + "name": "col04", + "type": "VARCHAR" + }, + { + "name": "col05", + "type": "VARBINARY" + }, + { + "name": "col06", + "type": "INT8" + }, + { + "name": "col07", + "type": "INT64" + }, + { + "name": "col08", + "type": "VARBINARY" + }, + { + "name": "sdKey", + "type": "VARBINARY" + }, + { + "name": "col09", + "type": "INT64" + }, + { + "name": "col10", + "type": "INT64" + }, + { + "name": "col11", + "type": "INT64" + }, + { + "name": "col12", + "type": "INT64" + }, + { + "name": "id", + "type": "UINT64" + } + ], + "column_list_authoritative": true + } + } + } + } +}