diff --git a/go/vt/vtgate/planbuilder/from.go b/go/vt/vtgate/planbuilder/from.go index 7f919ca21c0..8f47e0822ee 100644 --- a/go/vt/vtgate/planbuilder/from.go +++ b/go/vt/vtgate/planbuilder/from.go @@ -242,7 +242,7 @@ func (pb *primitiveBuilder) buildTablePrimitive(tableExpr *sqlparser.AliasedTabl default: // Pinned tables have their keyspace ids already assigned. // Use the Binary vindex, which is the identity function - // for keyspace id. + // for keyspace id. Currently only dual tables are pinned. eroute = engine.NewSimpleRoute(engine.SelectEqualUnique, vst.Keyspace) eroute.Vindex, _ = vindexes.NewBinary("binary", nil) eroute.Values = []sqltypes.PlanValue{{Value: sqltypes.MakeTrusted(sqltypes.VarBinary, vst.Pinned)}} diff --git a/go/vt/vtgate/planbuilder/testdata/select_cases.txt b/go/vt/vtgate/planbuilder/testdata/select_cases.txt index bf0ce701b1c..e8885a33a28 100644 --- a/go/vt/vtgate/planbuilder/testdata/select_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/select_cases.txt @@ -376,7 +376,7 @@ { "Original": "select database() from dual", "Instructions": { - "Opcode": "SelectReference", + "Opcode": "SelectUnsharded", "Keyspace": { "Name": "main", "Sharded": false @@ -392,18 +392,18 @@ "NEXT used on a non-sequence table" # last_insert_id for unsharded route -"select last_insert_id() from main.unsharded" +"select last_insert_id() from main.dual" { - "Original": "select last_insert_id() from main.unsharded", + "Original": "select last_insert_id() from main.dual", "Instructions": { "Opcode": "SelectUnsharded", "Keyspace": { "Name": "main", "Sharded": false }, - "Query": "select last_insert_id() from unsharded", - "FieldQuery": "select last_insert_id() from unsharded where 1 != 1", - "Table": "unsharded" + "Query": "select last_insert_id() from dual", + "FieldQuery": "select last_insert_id() from dual where 1 != 1", + "Table": "dual" } } @@ -412,7 +412,7 @@ { "Original": "select @@session.auto_increment_increment from dual", "Instructions": { - "Opcode": "SelectReference", + "Opcode": "SelectUnsharded", "Keyspace": { "Name": "main", "Sharded": false @@ -449,13 +449,15 @@ { "Original": "select @@session.auto_increment_increment from user.dual", "Instructions": { - "Opcode": "SelectReference", + "Opcode": "SelectEqualUnique", "Keyspace": { "Name": "user", "Sharded": true }, "Query": "select @@session.auto_increment_increment from dual", "FieldQuery": "select @@session.auto_increment_increment from dual where 1 != 1", + "Vindex": "binary", + "Values": ["\u0000"], "Table": "dual" } } diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt index 77cee7da742..c10604dfa72 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt @@ -71,10 +71,6 @@ "select last_insert_id() from user" "unsupported: LAST_INSERT_ID is only allowed for unsharded keyspaces" -# last_insert_id for dual -"select last_insert_id()" -"unsupported: LAST_INSERT_ID is only allowed for unsharded keyspaces" - # natural join "select * from user natural join user_extra" "unsupported: natural join" diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index 8f519fb7093..5242081ab09 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -367,7 +367,9 @@ func addDual(vschema *VSchema) { t := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks.Keyspace, - Type: TypeReference, + } + if ks.Keyspace.Sharded { + t.Pinned = []byte{0} } ks.Tables["dual"] = t if first == "" || first > ksname { diff --git a/go/vt/vtgate/vindexes/vschema_test.go b/go/vt/vtgate/vindexes/vschema_test.go index 200636c2388..b831a03e571 100644 --- a/go/vt/vtgate/vindexes/vschema_test.go +++ b/go/vt/vtgate/vindexes/vschema_test.go @@ -172,7 +172,6 @@ func TestUnshardedVSchema(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -236,7 +235,6 @@ func TestVSchemaColumns(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -303,7 +301,6 @@ func TestVSchemaColumnListAuthoritative(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -384,7 +381,7 @@ func TestVSchemaPinned(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -488,7 +485,7 @@ func TestShardedVSchemaOwned(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -705,12 +702,11 @@ func TestVSchemaRoutingRules(t *testing.T) { dual1 := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks1, - Type: TypeReference, + Pinned: []byte{0}, } dual2 := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks2, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{ @@ -948,7 +944,7 @@ func TestShardedVSchemaMultiColumnVindex(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -1048,7 +1044,7 @@ func TestShardedVSchemaNotOwned(t *testing.T) { dual := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ks, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -1175,12 +1171,10 @@ func TestBuildVSchemaDupSeq(t *testing.T) { duala := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksa, - Type: TypeReference, } dualb := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksb, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -1248,12 +1242,10 @@ func TestBuildVSchemaDupTable(t *testing.T) { duala := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksa, - Type: TypeReference, } dualb := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksb, - Type: TypeReference, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -1384,12 +1376,12 @@ func TestBuildVSchemaDupVindex(t *testing.T) { duala := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksa, - Type: TypeReference, + Pinned: []byte{0}, } dualb := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksb, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{}, @@ -1671,12 +1663,11 @@ func TestSequence(t *testing.T) { duala := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: ksu, - Type: TypeReference, } dualb := &Table{ Name: sqlparser.NewTableIdent("dual"), Keyspace: kss, - Type: TypeReference, + Pinned: []byte{0}, } want := &VSchema{ RoutingRules: map[string]*RoutingRule{},