handle

package
v1.1.0-beta.0...-83d3794 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatsOwnerKey is the stats owner path that is saved to etcd.
	StatsOwnerKey = "/tidb/stats/owner"
	// StatsPrompt is the prompt for stats owner manager.
	StatsPrompt = "stats"
)

Variables

View Source
var AttachStatsCollector = func(s sqlexec.SQLExecutor) sqlexec.SQLExecutor {
	return s
}

AttachStatsCollector attaches the stats collector for the session. this function is registered in BootstrapSession in pkg/session/session.go

View Source
var DetachStatsCollector = func(s sqlexec.SQLExecutor) sqlexec.SQLExecutor {
	return s
}

DetachStatsCollector removes the stats collector for the session this function is registered in BootstrapSession in pkg/session/session.go

View Source
var IsFullCacheFunc func(cache statstypes.StatsCache, total uint64) bool = isFullCache

IsFullCacheFunc is whether the cache is full or not. but we can only change it when to test

Functions

This section is empty.

Types

type Handle

type Handle struct {
	// Pool is used to get a session or a goroutine to execute stats updating.
	util.Pool

	// AutoAnalyzeProcIDGenerator is used to generate auto analyze proc ID.
	util.AutoAnalyzeProcIDGenerator

	// LeaseGetter is used to get stats lease.
	util.LeaseGetter

	// TableInfoGetter is used to fetch table meta info.
	util.TableInfoGetter

	// StatsGC is used to GC stats.
	types.StatsGC

	// StatsUsage is used to track the usage of column / index statistics.
	types.StatsUsage

	// StatsHistory is used to manage historical stats.
	types.StatsHistory

	// StatsAnalyze is used to handle auto-analyze and manage analyze jobs.
	types.StatsAnalyze

	// StatsSyncLoad is used to load stats syncly.
	types.StatsSyncLoad

	// StatsReadWriter is used to read/write stats from/to storage.
	types.StatsReadWriter

	// StatsLock is used to manage locked stats.
	types.StatsLock

	// StatsGlobal is used to manage global stats.
	types.StatsGlobal

	// DDL is used to handle ddl events.
	types.DDL

	// StatsCache ...
	types.StatsCache

	InitStatsDone chan struct{}
	// contains filtered or unexported fields
}

Handle can update stats info periodically.

func NewHandle

func NewHandle(
	ctx context.Context,
	lease time.Duration,
	pool syssession.Pool,
	tracker sysproctrack.Tracker,
	ddlNotifier *notifier.DDLNotifier,
	autoAnalyzeProcIDGetter func() uint64,
	releaseAutoAnalyzeProcID func(uint64),
) (*Handle, error)

NewHandle creates a Handle for update stats.

func (*Handle) Clear

func (h *Handle) Clear()

Clear the statsCache, only for test.

func (*Handle) Close

func (h *Handle) Close()

Close stops the background

func (*Handle) FlushStats

func (h *Handle) FlushStats()

FlushStats flushes the cached stats update into store.

func (*Handle) GetNonPseudoPhysicalTableStats

func (h *Handle) GetNonPseudoPhysicalTableStats(physicalTableID int64) (*statistics.Table, bool)

GetNonPseudoPhysicalTableStats retrieves the statistics for a physical table from cache, but it will not return pseudo. physicalTableID can be a table ID or partition ID. Note: this function may return nil if the table is not found in the cache.

func (*Handle) GetPhysicalTableStats

func (h *Handle) GetPhysicalTableStats(physicalTableID int64, tblInfo *model.TableInfo) *statistics.Table

GetPhysicalTableStats retrieves the statistics for a physical table from cache or creates a pseudo statistics table. physicalTableID can be a table ID or partition ID.

func (*Handle) GetSystemDBIDCacheLenForTest

func (h *Handle) GetSystemDBIDCacheLenForTest() int

GetSystemDBIDCacheLenForTest gets the length of systemDBIDCache, only for test.

func (*Handle) InitStats

func (h *Handle) InitStats(ctx context.Context, is infoschema.InfoSchema, tableIDs ...int64) error

InitStats initiates the stats cache. 1. Basic stats meta data is loaded.(count, modify count, etc.) 2. Index stats are fully loaded. (histogram, topn, buckets) 2. Column stats are marked as existing or not by initializing the table.ColAndIdxExistenceMap, based on data from mysql.stats_histograms) To work with auto-analyze's needs, we need to read all stats meta info into memory. The sync/async load of the stats or other process haven't done a full initialization of the table.ColAndIdxExistenceMap. So we need to it here. If tableIDs is provided, we only load the stats for the specified tables.

func (*Handle) InitStatsLite

func (h *Handle) InitStatsLite(ctx context.Context, tableIDs ...int64) error

InitStatsLite initiates the stats cache. The function is liter and faster than InitStats. 1. Basic stats meta data is loaded.(count, modify count, etc.) 2. Column/index stats are marked as existing or not by initializing the table.ColAndIdxExistenceMap, based on data from mysql.stats_histograms) 3. TopN, Bucket, FMSketch are not loaded. And to work with auto analyze's needs, we need to read all the tables' stats meta into memory. The sync/async load of the stats or other process haven't done a full initialization of the table.ColAndIdxExistenceMap. So we need to it here.

func (*Handle) StartWorker

func (h *Handle) StartWorker()

StartWorker starts the background collector worker inside

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL