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

[release-19.0] fix: handle info_schema routing (#15899) #15906

Merged
merged 1 commit into from
May 9, 2024
Merged
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
21 changes: 21 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/other_read_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
]
40 changes: 27 additions & 13 deletions go/vt/vtgate/planbuilder/vexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"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"
Expand All @@ -42,24 +44,37 @@
}

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

Check warning on line 54 in go/vt/vtgate/planbuilder/vexplain.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtgate/planbuilder/vexplain.go#L54

Added line #L54 was not covered by tests
}
} else {
var err error
var ks string
_, _, ks, _, destination, err = vschema.FindTableOrVindex(explain.Table)
if err != nil {
return nil, err

Check warning on line 61 in go/vt/vtgate/planbuilder/vexplain.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtgate/planbuilder/vexplain.go#L61

Added line #L61 was not covered by tests
}
explain.Table.Qualifier = sqlparser.NewIdentifierCS("")

keyspace, err = vschema.FindKeyspace(ks)
if err != nil {
return nil, err

Check warning on line 67 in go/vt/vtgate/planbuilder/vexplain.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtgate/planbuilder/vexplain.go#L67

Added line #L67 was not covered by tests
}
if keyspace == nil {
return nil, vterrors.VT14004(ks)

Check warning on line 70 in go/vt/vtgate/planbuilder/vexplain.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtgate/planbuilder/vexplain.go#L70

Added line #L70 was not covered by tests
}
}
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,
Expand Down Expand Up @@ -114,7 +129,6 @@
default:
return buildOtherReadAndAdmin(sqlparser.String(explain), vschema)
}

}

func explainPlan(explain *sqlparser.ExplainStmt, reservedVars *sqlparser.ReservedVars, vschema plancontext.VSchema) (*planResult, error) {
Expand Down
Loading