Skip to content

Commit

Permalink
Merge pull request #8771 from planetscale/fix-merge-SysTableTableName
Browse files Browse the repository at this point in the history
Proper merge of the SysTableTableName fields when joining two routes
  • Loading branch information
systay authored Sep 7, 2021
2 parents 369edc0 + 3a6b97a commit 130652a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/vt/vtgate/planbuilder/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ func (pb *primitiveBuilder) join(rpb *primitiveBuilder, ajoin *sqlparser.JoinTab
lRoute.eroute.TableName = strings.Join([]string{lRoute.eroute.TableName, rRoute.eroute.TableName}, ", ")
}

// join sysTableNames
for tableName, expr := range rRoute.eroute.SysTableTableName {
_, ok := lRoute.eroute.SysTableTableName[tableName]
if !ok {
lRoute.eroute.SysTableTableName[tableName] = expr
}
}

// Since the routes have merged, set st.singleRoute to point at
// the merged route.
pb.st.singleRoute = lRoute
Expand Down
19 changes: 19 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/from_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3954,3 +3954,22 @@ Gen4 plan same as above
]
}
}

# join two routes with SysTableTableName entries in LHS and RHS
"select a.table_name from (select * from information_schema.key_column_usage a where a.table_name = 'users') a join (select * from information_schema.referential_constraints where table_name = 'users') b"
{
"QueryType": "SELECT",
"Original": "select a.table_name from (select * from information_schema.key_column_usage a where a.table_name = 'users') a join (select * from information_schema.referential_constraints where table_name = 'users') b",
"Instructions": {
"OperatorType": "Route",
"Variant": "SelectDBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select a.table_name from (select * from information_schema.key_column_usage as a where 1 != 1) as a join (select * from information_schema.referential_constraints where 1 != 1) as b where 1 != 1",
"Query": "select a.table_name from (select * from information_schema.key_column_usage as a where a.table_name = :a_table_name) as a join (select * from information_schema.referential_constraints where table_name = :table_name) as b",
"SysTableTableName": "[a_table_name:VARBINARY(\"users\"), table_name:VARBINARY(\"users\")]",
"Table": "information_schema.key_column_usage, information_schema.referential_constraints"
}
}

0 comments on commit 130652a

Please sign in to comment.