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

planner: move more methods from StatsHandle to its sub-packages #47696

Merged
merged 5 commits into from
Oct 17, 2023
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
2 changes: 1 addition & 1 deletion br/pkg/backup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ go_library(
"//pkg/meta",
"//pkg/parser/model",
"//pkg/statistics/handle",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/util",
"//pkg/util/codec",
"//pkg/util/ranger",
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/backup/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/statistics/handle"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
kvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
Expand All @@ -39,7 +39,7 @@ type schemaInfo struct {
crc64xor uint64
totalKvs uint64
totalBytes uint64
stats *storage.JSONTable
stats *util.JSONTable
}

type iterFuncTp func(kv.Storage, func(*model.DBInfo, *model.TableInfo)) error
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/metautil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go_library(
"//br/pkg/storage",
"//br/pkg/summary",
"//pkg/parser/model",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/tablecodec",
"//pkg/util/encrypt",
"@com_github_docker_go_units//:go-units",
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/metautil/metafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/summary"
"github.com/pingcap/tidb/pkg/parser/model"
handle "github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/pingcap/tidb/pkg/util/encrypt"
"go.uber.org/zap"
Expand Down Expand Up @@ -153,7 +153,7 @@ type Table struct {
TotalBytes uint64
Files []*backuppb.File
TiFlashReplicas int
Stats *handle.JSONTable
Stats *util.JSONTable
}

// NoChecksum checks whether the table has a calculated checksum.
Expand Down Expand Up @@ -344,9 +344,9 @@ func (reader *MetaReader) ReadSchemasFiles(ctx context.Context, output chan<- *T
return errors.Trace(err)
}
}
var stats *handle.JSONTable
var stats *util.JSONTable
if s.Stats != nil {
stats = &handle.JSONTable{}
stats = &util.JSONTable{}
if err := json.Unmarshal(s.Stats, stats); err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/task/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ go_test(
"//br/pkg/utils",
"//pkg/config",
"//pkg/parser/model",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/tablecodec",
"@com_github_golang_protobuf//proto",
"@com_github_pingcap_errors//:errors",
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/task/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/utils"
"github.com/pingcap/tidb/pkg/parser/model"
handle "github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/stretchr/testify/require"
pd "github.com/tikv/pd/client"
Expand Down Expand Up @@ -187,7 +187,7 @@ func mockReadSchemasFromBackupMeta(t *testing.T, db2Tables map[string][]string)
}
mockTblList = append(mockTblList, mockTbl)

mockStats := handle.JSONTable{
mockStats := util.JSONTable{
DatabaseName: dbName.String(),
TableName: tblName.String(),
}
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ go_test(
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/types",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/tablecodec",
"//pkg/testkit/testsetup",
"//pkg/types",
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/utils/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/pingcap/tidb/br/pkg/metautil"
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/pkg/parser/model"
handle "github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/stretchr/testify/require"
)
Expand All @@ -38,7 +38,7 @@ func TestLoadBackupMeta(t *testing.T) {
ID: tblID,
Name: tblName,
}
mockStats := handle.JSONTable{
mockStats := util.JSONTable{
DatabaseName: dbName.String(),
TableName: tblName.String(),
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestLoadBackupMetaPartionTable(t *testing.T) {
},
},
}
mockStats := handle.JSONTable{
mockStats := util.JSONTable{
DatabaseName: dbName.String(),
TableName: tblName.String(),
}
Expand Down
1 change: 1 addition & 0 deletions cmd/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
"//pkg/planner/core",
"//pkg/statistics",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/types",
"//pkg/util/mathutil",
"//pkg/util/mock",
Expand Down
3 changes: 2 additions & 1 deletion cmd/importer/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
stats "github.com/pingcap/tidb/pkg/statistics"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/types"
"go.uber.org/zap"
)
Expand All @@ -34,7 +35,7 @@ func loadStats(tblInfo *model.TableInfo, path string) (*stats.Table, error) {
if err != nil {
return nil, errors.Trace(err)
}
jsTable := &storage.JSONTable{}
jsTable := &util.JSONTable{}
err = json.Unmarshal(data, jsTable)
if err != nil {
return nil, errors.Trace(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ go_library(
"//pkg/sessionctx/sessionstates",
"//pkg/sessionctx/variable",
"//pkg/statistics/handle",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/store/helper",
"//pkg/telemetry",
"//pkg/ttl/cache",
Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/plan_replayer_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/printer"
Expand Down Expand Up @@ -773,7 +773,7 @@ func extractTableNames(ctx context.Context, sctx sessionctx.Context,
return tableExtractor.getTablesAndViews(), nil
}

func getStatsForTable(do *Domain, pair tableNamePair, historyStatsTS uint64) (*storage.JSONTable, []string, error) {
func getStatsForTable(do *Domain, pair tableNamePair, historyStatsTS uint64) (*util.JSONTable, []string, error) {
is := do.InfoSchema()
h := do.StatsHandle()
tbl, err := is.TableByName(model.NewCIStr(pair.DBName), model.NewCIStr(pair.TableName))
Expand Down
3 changes: 1 addition & 2 deletions pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ go_library(
"//pkg/statistics",
"//pkg/statistics/handle",
"//pkg/statistics/handle/cache",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/store/driver/backoff",
"//pkg/store/driver/txn",
Expand Down Expand Up @@ -409,8 +408,8 @@ go_test(
"//pkg/sessiontxn",
"//pkg/sessiontxn/staleread",
"//pkg/statistics",
"//pkg/statistics/handle/globalstats",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/store/copr",
"//pkg/store/driver/error",
"//pkg/store/helper",
Expand Down
6 changes: 3 additions & 3 deletions pkg/executor/historical_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/statistics/handle/globalstats"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/oracle"
Expand Down Expand Up @@ -344,7 +344,7 @@ PARTITION p0 VALUES LESS THAN (6)
require.NotNil(t, jsTable)
// only has p0 stats
require.NotNil(t, jsTable.Partitions["p0"])
require.Nil(t, jsTable.Partitions[globalstats.TiDBGlobalStats])
require.Nil(t, jsTable.Partitions[util.TiDBGlobalStats])

// change static to dynamic then assert
tk.MustExec("set @@tidb_partition_prune_mode='dynamic'")
Expand All @@ -366,7 +366,7 @@ PARTITION p0 VALUES LESS THAN (6)
require.NotNil(t, jsTable)
// has both global and p0 stats
require.NotNil(t, jsTable.Partitions["p0"])
require.NotNil(t, jsTable.Partitions[globalstats.TiDBGlobalStats])
require.NotNil(t, jsTable.Partitions[util.TiDBGlobalStats])
}

func TestDumpHistoricalStatsFallback(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/load_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/pingcap/tidb/pkg/executor/internal/exec"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/util/chunk"
)

Expand Down Expand Up @@ -79,7 +79,7 @@ func (*LoadStatsExec) Open(context.Context) error {

// Update updates the stats of the corresponding table according to the data.
func (e *LoadStatsInfo) Update(data []byte) error {
jsonTbl := &storage.JSONTable{}
jsonTbl := &util.JSONTable{}
if err := json.Unmarshal(data, jsonTbl); err != nil {
return errors.Trace(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/sessiontxn"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/replayer"
Expand Down Expand Up @@ -443,7 +443,7 @@ func createSchemaAndItems(ctx sessionctx.Context, f *zip.File) error {
}

func loadStats(ctx sessionctx.Context, f *zip.File) error {
jsonTbl := &storage.JSONTable{}
jsonTbl := &util.JSONTable{}
r, err := f.Open()
if err != nil {
return errors.AddStack(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/cbotest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go_test(
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/statistics",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/testkit",
"//pkg/testkit/testdata",
"//pkg/testkit/testmain",
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/casetest/cbotest/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/statistics"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
"github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/pkg/testkit/testdata"
"github.com/stretchr/testify/require"
Expand All @@ -42,7 +42,7 @@ func loadTableStats(fileName string, dom *domain.Domain) error {
if err != nil {
return err
}
statsTbl := &storage.JSONTable{}
statsTbl := &util.JSONTable{}
err = json.Unmarshal(bytes, statsTbl)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions pkg/server/handler/optimizor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ go_library(
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/statistics/handle",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/table",
"//pkg/types",
"//pkg/util",
Expand Down Expand Up @@ -56,8 +56,7 @@ go_test(
"//pkg/server/internal/testutil",
"//pkg/server/internal/util",
"//pkg/session",
"//pkg/statistics/handle/globalstats",
"//pkg/statistics/handle/storage",
"//pkg/statistics/handle/util",
"//pkg/store/mockstore/unistore",
"//pkg/testkit",
"//pkg/testkit/testsetup",
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/handler/optimizor/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/server/handler"
"github.com/pingcap/tidb/pkg/statistics/handle"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
util2 "github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/replayer"
Expand Down Expand Up @@ -369,7 +369,7 @@ func dumpJSONStatsIntoZip(tbls map[int64]*tblInfo, content []byte, path string)

type tblInfo struct {
info *model.TableInfo
jsonStats *storage.JSONTable
jsonStats *util2.JSONTable
dbName string
tblName string
}
6 changes: 3 additions & 3 deletions pkg/server/handler/optimizor/plan_replayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
"github.com/pingcap/tidb/pkg/server/internal/testutil"
"github.com/pingcap/tidb/pkg/server/internal/util"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
util2 "github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
"github.com/tikv/client-go/v2/oracle"
Expand Down Expand Up @@ -273,13 +273,13 @@ func getInfoFromPlanReplayerZip(
t *testing.T,
z *zip.Reader,
) (
jsonTbls []*storage.JSONTable,
jsonTbls []*util2.JSONTable,
metas []map[string]string,
errMsgs []string,
) {
for _, zipFile := range z.File {
if strings.HasPrefix(zipFile.Name, "stats/") {
jsonTbl := &storage.JSONTable{}
jsonTbl := &util2.JSONTable{}
r, err := zipFile.Open()
require.NoError(t, err)
//nolint: all_revive
Expand Down
7 changes: 3 additions & 4 deletions pkg/server/handler/optimizor/statistics_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
"github.com/pingcap/tidb/pkg/server/internal/testutil"
"github.com/pingcap/tidb/pkg/server/internal/util"
"github.com/pingcap/tidb/pkg/session"
"github.com/pingcap/tidb/pkg/statistics/handle/globalstats"
"github.com/pingcap/tidb/pkg/statistics/handle/storage"
util2 "github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -178,10 +177,10 @@ func testDumpPartitionTableStats(t *testing.T, client *testserverclient.TestServ
}()
b, err := io.ReadAll(resp0.Body)
require.NoError(t, err)
jsonTable := &storage.JSONTable{}
jsonTable := &util2.JSONTable{}
err = json.Unmarshal(b, jsonTable)
require.NoError(t, err)
require.NotNil(t, jsonTable.Partitions[globalstats.TiDBGlobalStats])
require.NotNil(t, jsonTable.Partitions[util2.TiDBGlobalStats])
require.Len(t, jsonTable.Partitions, expectedLen)
}
check(false)
Expand Down
Loading
Loading