Skip to content

Commit

Permalink
Cache info schema table info (#13724)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay authored Aug 8, 2023
1 parent 682868c commit 2973fb4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
10 changes: 4 additions & 6 deletions go/vt/vtgate/engine/memory_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import (
"context"
"testing"

"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtgate/evalengine"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/test/utils"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtgate/evalengine"
)

func init() {
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/ordered_aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/servenv"
Expand Down
15 changes: 5 additions & 10 deletions go/vt/vtgate/engine/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"vitess.io/vitess/go/mysql/sqlerror"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vterrors"

"vitess.io/vitess/go/vt/sqlparser"

"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/evalengine"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/vtgate/vindexes"
)

Expand Down
10 changes: 8 additions & 2 deletions go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ func TestForeignKeyPlanning(t *testing.T) {

func TestSystemTables57(t *testing.T) {
// first we move everything to use 5.7 logic
oldVer := servenv.MySQLServerVersion()
servenv.SetMySQLServerVersionForTest("5.7")
defer servenv.SetMySQLServerVersionForTest("")
defer func() {
servenv.SetMySQLServerVersionForTest(oldVer)
}()
vschemaWrapper := &vschemaWrapper{v: loadSchema(t, "vschemas/schema.json", true)}
testOutputTempDir := makeTestOutput(t)
testFile(t, "info_schema57_cases.json", testOutputTempDir, vschemaWrapper, false)
Expand Down Expand Up @@ -208,8 +211,11 @@ func TestOneWithTPCHVSchema(t *testing.T) {

func TestOneWith57Version(t *testing.T) {
// first we move everything to use 5.7 logic
oldVer := servenv.MySQLServerVersion()
servenv.SetMySQLServerVersionForTest("5.7")
defer servenv.SetMySQLServerVersionForTest("")
defer func() {
servenv.SetMySQLServerVersionForTest(oldVer)
}()
vschema := &vschemaWrapper{v: loadSchema(t, "vschemas/schema.json", true)}

testFile(t, "onecase.json", "", vschema, false)
Expand Down
16 changes: 11 additions & 5 deletions go/vt/vtgate/semantics/info_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,16 +1671,22 @@ type infoSchemaWithColumns struct {
infoSchemaData map[string][]vindexes.Column
}

// We cache this information, since these are maps that are not changed
var infoSchema57 = getInfoSchema57()
var infoSchema80 = getInfoSchema80()

// newSchemaInfo returns a SchemaInformation that has the column information for all info_schema tables
func newSchemaInfo(inner SchemaInformation) SchemaInformation {
return &infoSchemaWithColumns{inner: inner, infoSchemaData: loadSchemaInfo()}
}

func loadSchemaInfo() map[string][]vindexes.Column {
version := servenv.MySQLServerVersion()
var infoSchema map[string][]vindexes.Column
if strings.HasPrefix(version, "5.7") {
infoSchema = getInfoSchema57()
} else {
infoSchema = getInfoSchema80()
return infoSchema57
}
return &infoSchemaWithColumns{inner: inner, infoSchemaData: infoSchema}

return infoSchema80
}

// FindTableOrVindex implements the SchemaInformation interface
Expand Down

0 comments on commit 2973fb4

Please sign in to comment.