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

Fix treament of dual as sharded by reverting #5268 #5519

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}
Expand Down
18 changes: 10 additions & 8 deletions go/vt/vtgate/planbuilder/testdata/select_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
{
"Original": "select database() from dual",
"Instructions": {
"Opcode": "SelectReference",
"Opcode": "SelectUnsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
Expand All @@ -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"
}
}

Expand All @@ -412,7 +412,7 @@
{
"Original": "select @@session.auto_increment_increment from dual",
"Instructions": {
"Opcode": "SelectReference",
"Opcode": "SelectUnsharded",
"Keyspace": {
"Name": "main",
"Sharded": false
Expand Down Expand Up @@ -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"
}
}
Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 8 additions & 17 deletions go/vt/vtgate/vindexes/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down