diff --git a/go/vt/vtgate/engine/memory_sort_test.go b/go/vt/vtgate/engine/memory_sort_test.go index 0af0564dc7c..3b53ef11250 100644 --- a/go/vt/vtgate/engine/memory_sort_test.go +++ b/go/vt/vtgate/engine/memory_sort_test.go @@ -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() { diff --git a/go/vt/vtgate/engine/ordered_aggregate_test.go b/go/vt/vtgate/engine/ordered_aggregate_test.go index 539e81b4c59..9f6b8afddd7 100644 --- a/go/vt/vtgate/engine/ordered_aggregate_test.go +++ b/go/vt/vtgate/engine/ordered_aggregate_test.go @@ -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" diff --git a/go/vt/vtgate/engine/route_test.go b/go/vt/vtgate/engine/route_test.go index 7d5b1d1bbea..13fb0be656b 100644 --- a/go/vt/vtgate/engine/route_test.go +++ b/go/vt/vtgate/engine/route_test.go @@ -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" ) diff --git a/go/vt/vtgate/planbuilder/plan_test.go b/go/vt/vtgate/planbuilder/plan_test.go index 755a5fbf916..328c8ac7421 100644 --- a/go/vt/vtgate/planbuilder/plan_test.go +++ b/go/vt/vtgate/planbuilder/plan_test.go @@ -102,8 +102,11 @@ func TestPlan(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) @@ -193,8 +196,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) diff --git a/go/vt/vtgate/semantics/info_schema.go b/go/vt/vtgate/semantics/info_schema.go index b27e197c16f..af050d5ff1b 100644 --- a/go/vt/vtgate/semantics/info_schema.go +++ b/go/vt/vtgate/semantics/info_schema.go @@ -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