indexusage

package
v0.0.0-...-6e93ed8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Collector represents a data structure to record the index usage for the whole node

func NewCollector

func NewCollector() *Collector

NewCollector create an index usage collector

func (*Collector) Close

func (c *Collector) Close()

Close closes the background worker inside

func (*Collector) GCIndexUsage

func (c *Collector) GCIndexUsage(tableMetaLookup func(id int64) (*model.TableInfo, bool))

GCIndexUsage will delete the usage information of non-existent indexes. `tableMetaLookup` argument is represented as a function (but not `sessionctx.Context` or `infoschema.InfoSchema`) to avoid depending on `sessionctx.Context`.

func (*Collector) GetIndexUsage

func (c *Collector) GetIndexUsage(tableID int64, indexID int64) Sample

GetIndexUsage returns the index usage information

func (*Collector) SpawnSessionCollector

func (c *Collector) SpawnSessionCollector() *SessionIndexUsageCollector

SpawnSessionCollector creates a new session collector attached to this global collector

func (*Collector) StartWorker

func (c *Collector) StartWorker()

StartWorker starts the background worker inside

type GlobalIndexID

type GlobalIndexID struct {
	TableID int64
	IndexID int64
}

GlobalIndexID is the key type for indexUsageMap.

type Sample

type Sample struct {
	// LastUsedAt records the last time the index is used.
	LastUsedAt time.Time
	// QueryTotal records the total counts of queries which used this index.
	QueryTotal uint64
	// KvReqTotal records the count of KV requests which are sent to read this index.
	KvReqTotal uint64
	// RowAccessTotal sums the number of the rows scanned using this index.
	RowAccessTotal uint64
	// PercentageAccess is a histogram where each bucket represents the number of accesses to the index where the
	// percentage of scanned rows to the total number of rows in the table falls within the ranges of
	// 0, 0-1, 1-10, 10-20, 20-50, 50-100, and 100.
	PercentageAccess [7]uint64
}

Sample is the data structure to store index usage information.

func NewSample

func NewSample(queryTotal uint64, kvReqTotal uint64, rowAccess uint64, tableTotalRows uint64) Sample

NewSample creates a new data point for index usage.

type SessionIndexUsageCollector

type SessionIndexUsageCollector struct {
	// contains filtered or unexported fields
}

SessionIndexUsageCollector collects index usage per-session

func (*SessionIndexUsageCollector) Flush

func (s *SessionIndexUsageCollector) Flush()

Flush reports the indexUsage in `SessionIndexUsageCollector` to the global collector. It'll block until the data is received

func (*SessionIndexUsageCollector) Report

func (s *SessionIndexUsageCollector) Report()

Report reports the indexUsage in `SessionIndexUsageCollector` to the global collector

func (*SessionIndexUsageCollector) Update

func (s *SessionIndexUsageCollector) Update(tableID int64, indexID int64, sample Sample)

Update updates the indexUsage in SessionIndexUsageCollector

type StmtIndexUsageCollector

type StmtIndexUsageCollector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StmtIndexUsageCollector removes the duplicates index for recording `QueryTotal` in session collector

func NewStmtIndexUsageCollector

func NewStmtIndexUsageCollector(sessionCollector *SessionIndexUsageCollector) *StmtIndexUsageCollector

NewStmtIndexUsageCollector creates a new StmtIndexUsageCollector.

func (*StmtIndexUsageCollector) Reset

func (s *StmtIndexUsageCollector) Reset()

Reset resets the recorded index in the collector to avoid re-allocating for each statement.

func (*StmtIndexUsageCollector) Update

func (s *StmtIndexUsageCollector) Update(tableID int64, indexID int64, sample Sample)

Update updates the index usage in the internal session collector. The `sample.QueryTotal` will be modified according to whether this index has been recorded in this statement usage collector.

Jump to

Keyboard shortcuts

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