Skip to content

Commit

Permalink
simplify the code
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 8, 2023
1 parent 6710c49 commit 0276e6e
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 33 deletions.
1 change: 0 additions & 1 deletion go/vt/servenv/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func MySQLServerVersion() string {
// flag. It is intended for use in tests that require a specific MySQL server
// version (for example, collations) that cannot specify that via the command
// line.
// Please note that semantics.ClearCachedInfoSchemaInfo() should be called any time this method is called
func SetMySQLServerVersionForTest(version string) {
mySQLServerVersion = version
}
Expand Down
2 changes: 0 additions & 2 deletions go/vt/vtgate/engine/memory_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import (
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtgate/evalengine"
"vitess.io/vitess/go/vt/vtgate/semantics"
)

func init() {
// We require MySQL 8.0 collations for the comparisons in the tests
mySQLVersion := "8.0.0"
servenv.SetMySQLServerVersionForTest(mySQLVersion)
semantics.ClearCachedInfoSchemaInfo()
collationEnv = collations.NewEnvironment(mySQLVersion)
}

Expand Down
2 changes: 0 additions & 2 deletions go/vt/vtgate/engine/ordered_aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
querypb "vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/servenv"
. "vitess.io/vitess/go/vt/vtgate/engine/opcode"
"vitess.io/vitess/go/vt/vtgate/semantics"
)

var collationEnv *collations.Environment
Expand All @@ -41,7 +40,6 @@ func init() {
// We require MySQL 8.0 collations for the comparisons in the tests
mySQLVersion := "8.0.0"
servenv.SetMySQLServerVersionForTest(mySQLVersion)
semantics.ClearCachedInfoSchemaInfo()
collationEnv = collations.NewEnvironment(mySQLVersion)
}

Expand Down
2 changes: 0 additions & 2 deletions go/vt/vtgate/engine/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vterrors"
"vitess.io/vitess/go/vt/vtgate/evalengine"
"vitess.io/vitess/go/vt/vtgate/semantics"
"vitess.io/vitess/go/vt/vtgate/vindexes"
)

Expand All @@ -51,7 +50,6 @@ func init() {
// We require MySQL 8.0 collations for the comparisons in the tests
mySQLVersion := "8.0.0"
servenv.SetMySQLServerVersionForTest(mySQLVersion)
semantics.ClearCachedInfoSchemaInfo()
collationEnv = collations.NewEnvironment(mySQLVersion)
}

Expand Down
3 changes: 0 additions & 3 deletions go/vt/vtgate/evalengine/api_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/vtgate/semantics"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/collations"
Expand Down Expand Up @@ -58,7 +56,6 @@ func init() {
// We require MySQL 8.0 collations for the comparisons in the tests
mySQLVersion := "8.0.0"
servenv.SetMySQLServerVersionForTest(mySQLVersion)
semantics.ClearCachedInfoSchemaInfo()
collationEnv = collations.NewEnvironment(mySQLVersion)
}

Expand Down
3 changes: 0 additions & 3 deletions go/vt/vtgate/evalengine/integration/comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/vtgate/semantics"

"github.com/spf13/pflag"

"vitess.io/vitess/go/mysql/format"
Expand Down Expand Up @@ -258,7 +256,6 @@ func TestMySQL(t *testing.T) {
// We require MySQL 8.0 collations for the comparisons in the tests

servenv.SetMySQLServerVersionForTest(conn.ServerVersion)
semantics.ClearCachedInfoSchemaInfo()
collationEnv = collations.NewEnvironment(conn.ServerVersion)
servenv.OnParse(registerFlags)
initTimezoneData(t, conn)
Expand Down
4 changes: 0 additions & 4 deletions go/vt/vtgate/planbuilder/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ func TestSystemTables57(t *testing.T) {
// first we move everything to use 5.7 logic
oldVer := servenv.MySQLServerVersion()
servenv.SetMySQLServerVersionForTest("5.7")
semantics.ClearCachedInfoSchemaInfo()
defer func() {
servenv.SetMySQLServerVersionForTest(oldVer)
semantics.ClearCachedInfoSchemaInfo()
}()
vschemaWrapper := &vschemaWrapper{v: loadSchema(t, "vschemas/schema.json", true)}
testOutputTempDir := makeTestOutput(t)
Expand Down Expand Up @@ -200,10 +198,8 @@ func TestOneWith57Version(t *testing.T) {
// first we move everything to use 5.7 logic
oldVer := servenv.MySQLServerVersion()
servenv.SetMySQLServerVersionForTest("5.7")
semantics.ClearCachedInfoSchemaInfo()
defer func() {
servenv.SetMySQLServerVersionForTest(oldVer)
semantics.ClearCachedInfoSchemaInfo()
}()
vschema := &vschemaWrapper{v: loadSchema(t, "vschemas/schema.json", true)}

Expand Down
24 changes: 8 additions & 16 deletions go/vt/vtgate/semantics/info_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1671,30 +1671,22 @@ type infoSchemaWithColumns struct {
infoSchemaData map[string][]vindexes.Column
}

// We cache this information. If the version is changed in a test, this field also needs to be cleared
var cacheSchemaInfo 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 {
if cacheSchemaInfo == nil {
// yes, this is slightly racy, but the worst that can happen is that we build it more times
// than needed. It's not going to lead to any actual issues
loadSchemaInfo()
}
return &infoSchemaWithColumns{inner: inner, infoSchemaData: cacheSchemaInfo}
}

func ClearCachedInfoSchemaInfo() {
cacheSchemaInfo = nil
return &infoSchemaWithColumns{inner: inner, infoSchemaData: loadSchemaInfo()}
}

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

return infoSchema80
}

// FindTableOrVindex implements the SchemaInformation interface
Expand Down

0 comments on commit 0276e6e

Please sign in to comment.