Skip to content

Commit

Permalink
Merge pull request #7729 from planetscale/more-sys-fix
Browse files Browse the repository at this point in the history
show columns query on system schema
  • Loading branch information
harshit-gangal authored Mar 23, 2021
2 parents 24732d9 + 7313a96 commit 9b09bfa
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
46 changes: 30 additions & 16 deletions go/vt/vtgate/planbuilder/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,40 @@ func buildVariablePlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engin
func buildShowTblPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Primitive, error) {
if show.DbName != "" {
show.Tbl.Qualifier = sqlparser.NewTableIdent(show.DbName)
// Remove Database Name from the query.
show.DbName = ""
}
table, _, _, _, destination, err := vschema.FindTableOrVindex(show.Tbl)
if err != nil {
return nil, err
}
if table == nil {
return nil, vterrors.NewErrorf(vtrpcpb.Code_NOT_FOUND, vterrors.UnknownTable, "Table '%s' doesn't exist", show.Tbl.Name.String())
}
if destination == nil {
destination = key.DestinationAnyShard{}
}

// Remove Database Name from the query.
show.DbName = ""
show.Tbl.Qualifier = sqlparser.NewTableIdent("")
show.Tbl.Name = table.Name
dest := key.Destination(key.DestinationAnyShard{})
var ks *vindexes.Keyspace
var err error

if !show.Tbl.Qualifier.IsEmpty() && sqlparser.SystemSchema(show.Tbl.Qualifier.String()) {
ks, err = vschema.AnyKeyspace()
if err != nil {
return nil, err
}
} else {
table, _, _, _, destination, err := vschema.FindTableOrVindex(show.Tbl)
if err != nil {
return nil, err
}
if table == nil {
return nil, vterrors.NewErrorf(vtrpcpb.Code_NOT_FOUND, vterrors.UnknownTable, "Table '%s' doesn't exist", show.Tbl.Name.String())
}
// Update the table.
show.Tbl.Qualifier = sqlparser.NewTableIdent("")
show.Tbl.Name = table.Name

if destination != nil {
dest = destination
}
ks = table.Keyspace
}

return &engine.Send{
Keyspace: table.Keyspace,
TargetDestination: destination,
Keyspace: ks,
TargetDestination: dest,
Query: sqlparser.String(show),
IsDML: false,
SingleShardOnly: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,39 @@
]
}
}

# show full columns from system schema
"show full columns from sys.sys_config"
{
"QueryType": "SHOW",
"Original": "show full columns from sys.sys_config",
"Instructions": {
"OperatorType": "Send",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": "AnyShard()",
"IsDML": false,
"Query": "show full columns from sys.sys_config",
"SingleShardOnly": true
}
}

# show full columns from system schema replacing qualifier
"show full columns from x.sys_config from sys"
{
"QueryType": "SHOW",
"Original": "show full columns from x.sys_config from sys",
"Instructions": {
"OperatorType": "Send",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": "AnyShard()",
"IsDML": false,
"Query": "show full columns from sys.sys_config",
"SingleShardOnly": true
}
}

0 comments on commit 9b09bfa

Please sign in to comment.