Skip to content

Commit

Permalink
cache info schema table info
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed Aug 5, 2023
1 parent 4d9d94c commit 01195ce
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions go/vt/vtgate/semantics/info_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,16 +1671,25 @@ type infoSchemaWithColumns struct {
infoSchemaData map[string][]vindexes.Column
}

// We cache this information. If the registered mysql version is changed, we flush the cache
var cacheSchemaInfo map[string][]vindexes.Column
var cachedVersion string

// newSchemaInfo returns a SchemaInformation that has the column information for all info_schema tables
func newSchemaInfo(inner SchemaInformation) SchemaInformation {
version := servenv.MySQLServerVersion()
var infoSchema map[string][]vindexes.Column
if strings.HasPrefix(version, "5.7") {
infoSchema = getInfoSchema57()
} else {
infoSchema = getInfoSchema80()

if version != cachedVersion || cacheSchemaInfo == nil {
// we don't have a valid cached info_schema map with column information
if strings.HasPrefix(version, "5.7") {
cacheSchemaInfo = getInfoSchema57()
} else {
cacheSchemaInfo = getInfoSchema80()
}
cachedVersion = version
}
return &infoSchemaWithColumns{inner: inner, infoSchemaData: infoSchema}

return &infoSchemaWithColumns{inner: inner, infoSchemaData: cacheSchemaInfo}
}

// FindTableOrVindex implements the SchemaInformation interface
Expand Down

0 comments on commit 01195ce

Please sign in to comment.