statistics

package
v0.0.0-...-1ca7fb8 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2017 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Ctx           context.Context  // Ctx is the context.
	TblInfo       *model.TableInfo // TblInfo is the table info of the table.
	StartTS       int64            // StartTS is the start timestamp of the statistics table builder.
	Count         int64            // Count is the total rows in the table.
	NumBuckets    int64            // NumBuckets is the number of buckets a column histogram has.
	ColumnSamples [][]types.Datum  // ColumnSamples is the sample of columns.
	ColIDs        []int64          // ColIDs is the id of columns in the table.
	ColNDVs       []int64          // ColNDVs is the NDV of columns.
	IdxRecords    []ast.RecordSet  // IdxRecords is the record set of index columns.
	IdxIDs        []int64          // IdxIDs is the id of indices in the table.
	PkRecords     ast.RecordSet    // PkRecords is the record set of primary key of integer type.
	PkID          int64            // PkID is the id of primary key with integer type in the table.
	// contains filtered or unexported fields
}

Builder describes information needed by NewTable

func (*Builder) NewTable

func (b *Builder) NewTable() (*Table, error)

NewTable creates a table statistics.

type Column

type Column struct {
	Histogram
}

Column represents a column histogram.

func (*Column) String

func (c *Column) String() string

type FMSketch

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

FMSketch is used to count the number of distinct elements in a set.

func NewFMSketch

func NewFMSketch(maxSize int) *FMSketch

NewFMSketch returns a new FM sketch.

func (*FMSketch) InsertValue

func (s *FMSketch) InsertValue(value types.Datum) error

InsertValue inserts a value into the FM sketch.

func (*FMSketch) NDV

func (s *FMSketch) NDV() int64

NDV returns the ndv of the sketch.

type Handle

type Handle struct {

	// LastVersion is the latest update version before last lease. Exported for test.
	LastVersion uint64
	// PrevLastVersion is the latest update version before two lease. Exported for test.
	// We need this because for two tables, the smaller version may write later than the one with larger version.
	// We can read the version with lastTwoVersion if the diff between commit time and version is less than one lease.
	// PrevLastVersion will be assigned by LastVersion every time Update is called.
	PrevLastVersion uint64
	// contains filtered or unexported fields
}

Handle can update stats info periodically.

func NewHandle

func NewHandle(ctx context.Context) *Handle

NewHandle creates a Handle for update stats.

func (*Handle) Clear

func (h *Handle) Clear()

Clear the statsCache, only for test.

func (*Handle) DDLEventCh

func (h *Handle) DDLEventCh() chan *ddl.Event

DDLEventCh returns ddl events channel in handle.

func (*Handle) DumpStatsDeltaToKV

func (h *Handle) DumpStatsDeltaToKV()

DumpStatsDeltaToKV sweeps the whole list and updates the global map. Then we dumps every table that held in map to KV.

func (*Handle) GetTableStats

func (h *Handle) GetTableStats(tblID int64) *Table

GetTableStats retrieves the statistics table from cache, and the cache will be updated by a goroutine.

func (*Handle) HandleDDLEvent

func (h *Handle) HandleDDLEvent(t *ddl.Event) error

HandleDDLEvent begins to process a ddl task.

func (*Handle) NewSessionStatsCollector

func (h *Handle) NewSessionStatsCollector() *SessionStatsCollector

NewSessionStatsCollector allocates a stats collector for a session.

func (*Handle) SaveToStorage

func (h *Handle) SaveToStorage(t *Table) error

SaveToStorage saves stats table to storage.

func (*Handle) Update

func (h *Handle) Update(is infoschema.InfoSchema) error

Update reads stats meta from store and updates the stats map.

type Histogram

type Histogram struct {
	ID  int64 // Column ID.
	NDV int64 // Number of distinct values.
	// LastUpdateVersion is the version that this histogram updated last time.
	LastUpdateVersion uint64

	Buckets []bucket
}

Histogram represents statistics for a column or index.

type Index

type Index struct {
	Histogram
	NumColumns int
}

Index represents an index histogram.

func (*Index) String

func (idx *Index) String() string

type SessionStatsCollector

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

SessionStatsCollector is a list item that holds the delta mapper. If you want to write or read mapper, you must lock it.

func (*SessionStatsCollector) Delete

func (s *SessionStatsCollector) Delete()

Delete only sets the deleted flag true, it will be deleted from list when DumpStatsDeltaToKV is called.

func (*SessionStatsCollector) Update

func (s *SessionStatsCollector) Update(id int64, delta int64, count int64)

Update will updates the delta and count for one table id.

type Table

type Table struct {
	Columns map[int64]*Column
	Indices map[int64]*Index
	Count   int64 // Total row count in a table.
	Pseudo  bool
	// contains filtered or unexported fields
}

Table represents statistics for a table.

func PseudoTable

func PseudoTable(tableID int64) *Table

PseudoTable creates a pseudo table statistics when statistic can not be found in KV store.

func (*Table) ColumnBetweenRowCount

func (t *Table) ColumnBetweenRowCount(sc *variable.StatementContext, a, b types.Datum, colInfo *model.ColumnInfo) (float64, error)

ColumnBetweenRowCount estimates the row count where column greater or equal to a and less than b.

func (*Table) ColumnEqualRowCount

func (t *Table) ColumnEqualRowCount(sc *variable.StatementContext, value types.Datum, colInfo *model.ColumnInfo) (float64, error)

ColumnEqualRowCount estimates the row count where the column equals to value.

func (*Table) ColumnGreaterRowCount

func (t *Table) ColumnGreaterRowCount(sc *variable.StatementContext, value types.Datum, colInfo *model.ColumnInfo) (float64, error)

ColumnGreaterRowCount estimates the row count where the column greater than value.

func (*Table) ColumnLessRowCount

func (t *Table) ColumnLessRowCount(sc *variable.StatementContext, value types.Datum, colInfo *model.ColumnInfo) (float64, error)

ColumnLessRowCount estimates the row count where the column less than value.

func (*Table) GetRowCountByIndexRanges

func (t *Table) GetRowCountByIndexRanges(sc *variable.StatementContext, idxID int64, indexRanges []*types.IndexRange, inAndEQCnt int) (float64, error)

GetRowCountByIndexRanges estimates the row count by a slice of IndexRange.

func (*Table) GetRowCountByIntColumnRanges

func (t *Table) GetRowCountByIntColumnRanges(sc *variable.StatementContext, colID int64, intRanges []types.IntColumnRange) (float64, error)

GetRowCountByIntColumnRanges estimates the row count by a slice of IntColumnRange.

func (*Table) String

func (t *Table) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

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