diff --git a/go/vt/vtgate/planbuilder/testdata/other_read_cases.json b/go/vt/vtgate/planbuilder/testdata/other_read_cases.json index 8b67623186a..2258bcd768c 100644 --- a/go/vt/vtgate/planbuilder/testdata/other_read_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/other_read_cases.json @@ -146,5 +146,26 @@ "user.music" ] } + }, + { + "comment": "describe info_schema table", + "query": "describe information_schema.administrable_role_authorizations", + "plan": { + "QueryType": "EXPLAIN", + "Original": "describe information_schema.administrable_role_authorizations", + "Instructions": { + "OperatorType": "Send", + "Keyspace": { + "Name": "main", + "Sharded": false + }, + "TargetDestination": "AnyShard()", + "Query": "explain information_schema.administrable_role_authorizations", + "SingleShardOnly": true + }, + "TablesUsed": [ + "main.administrable_role_authorizations" + ] + } } ] diff --git a/go/vt/vtgate/planbuilder/vexplain.go b/go/vt/vtgate/planbuilder/vexplain.go index db62da75122..b9226678867 100644 --- a/go/vt/vtgate/planbuilder/vexplain.go +++ b/go/vt/vtgate/planbuilder/vexplain.go @@ -20,6 +20,8 @@ import ( "context" "encoding/json" + "vitess.io/vitess/go/vt/vtgate/vindexes" + "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/key" querypb "vitess.io/vitess/go/vt/proto/query" @@ -42,24 +44,37 @@ func buildVExplainPlan(ctx context.Context, vexplainStmt *sqlparser.VExplainStmt } func explainTabPlan(explain *sqlparser.ExplainTab, vschema plancontext.VSchema) (*planResult, error) { - _, _, ks, _, destination, err := vschema.FindTableOrVindex(explain.Table) - if err != nil { - return nil, err + var keyspace *vindexes.Keyspace + var destination key.Destination + + if sqlparser.SystemSchema(explain.Table.Qualifier.String()) { + var err error + keyspace, err = vschema.AnyKeyspace() + if err != nil { + return nil, err + } + } else { + var err error + var ks string + _, _, ks, _, destination, err = vschema.FindTableOrVindex(explain.Table) + if err != nil { + return nil, err + } + explain.Table.Qualifier = sqlparser.NewIdentifierCS("") + + keyspace, err := vschema.FindKeyspace(ks) + if err != nil { + return nil, err + } + if keyspace == nil { + return nil, vterrors.VT14004(ks) + } } - explain.Table.Qualifier = sqlparser.NewIdentifierCS("") if destination == nil { destination = key.DestinationAnyShard{} } - keyspace, err := vschema.FindKeyspace(ks) - if err != nil { - return nil, err - } - if keyspace == nil { - return nil, vterrors.VT14004(ks) - } - return newPlanResult(&engine.Send{ Keyspace: keyspace, TargetDestination: destination, @@ -114,7 +129,6 @@ func buildExplainStmtPlan(stmt sqlparser.Statement, reservedVars *sqlparser.Rese default: return buildOtherReadAndAdmin(sqlparser.String(explain), vschema) } - } func explainPlan(explain *sqlparser.ExplainStmt, reservedVars *sqlparser.ReservedVars, vschema plancontext.VSchema) (*planResult, error) {