Documentation ¶
Overview ¶
Package table contains some common utilities for working with tables such as a 'Chunker' feature.
Index ¶
- Constants
- Variables
- func LazyFindP90(a []time.Duration) time.Duration
- func QuoteColumns(cols []string) string
- type Boundary
- type Chunk
- type Chunker
- type Datum
- type JSONBoundary
- type JSONChunk
- type Operator
- type TableInfo
- func (t *TableInfo) AutoUpdateStatistics(ctx context.Context, interval time.Duration, logger loggers.Advanced)
- func (t *TableInfo) Close() error
- func (t *TableInfo) DescIndex(keyName string) ([]string, error)
- func (t *TableInfo) MaxValue() Datum
- func (t *TableInfo) PrimaryKeyIsMemoryComparable() error
- func (t *TableInfo) PrimaryKeyValues(row interface{}) ([]interface{}, error)
- func (t *TableInfo) SetInfo(ctx context.Context) error
- func (t *TableInfo) WrapCastType(col string) string
Constants ¶
const ( // StartingChunkSize is the initial chunkSize StartingChunkSize = 1000 // MaxDynamicStepFactor is the maximum amount each recalculation of the dynamic chunkSize can // increase by. For example, if the newTarget is 5000 but the current target is 1000, the newTarget // will be capped back down to 1500. Over time the number 5000 will be reached, but not straight away. MaxDynamicStepFactor = 1.5 // MinDynamicRowSize is the minimum chunkSize that can be used when dynamic chunkSize is enabled. // This helps prevent a scenario where the chunk size is too small (it can never be less than 1). MinDynamicRowSize = 10 // MaxDynamicRowSize is the max allowed chunkSize that can be used when dynamic chunkSize is enabled. // This seems like a safe upper bound for now MaxDynamicRowSize = 100000 // DynamicPanicFactor is the factor by which the feedback process takes immediate action when // the chunkSize appears to be too large. For example, if the PanicFactor is 5, and the target *time* // is 50ms, an actual time 250ms+ will cause the dynamic chunk size to immediately be reduced. DynamicPanicFactor = 5 // ChunkerDefaultTarget is the default chunker target ChunkerDefaultTarget = 100 * time.Millisecond )
Variables ¶
Functions ¶
func LazyFindP90 ¶
LazyFindP90 finds the second to last value in a slice. This is the same as a p90 if there are 10 values, but if there were 100 values it would technically be a p99 etc.
func QuoteColumns ¶
Types ¶
type Chunk ¶
type Chunk struct { Key []string ChunkSize uint64 LowerBound *Boundary UpperBound *Boundary AdditionalConditions string }
Chunk is returned by chunk.Next() Applications can use it to iterate over the rows.
type Chunker ¶
type Chunker interface { Open() error OpenAtWatermark(watermark string, datum Datum) error IsRead() bool Close() error Next() (*Chunk, error) Feedback(chunk *Chunk, duration time.Duration) GetLowWatermark() (string, error) KeyAboveHighWatermark(key interface{}) bool }
func NewChunker ¶
type Datum ¶
type Datum struct { Val interface{} Tp datumTp // signed, unsigned, binary }
Datum could be a binary string, uint64 or int64.
func NewNilDatum ¶
func NewNilDatum(tp datumTp) Datum
func (Datum) GreaterThanOrEqual ¶
type JSONBoundary ¶
type JSONChunk ¶
type JSONChunk struct { Key []string ChunkSize uint64 LowerBound JSONBoundary UpperBound JSONBoundary }
type TableInfo ¶
type TableInfo struct { sync.Mutex EstimatedRows uint64 SchemaName string TableName string QuotedName string Columns []string // all the column names NonGeneratedColumns []string // all the non-generated column names Indexes []string // all the index names KeyColumns []string // the column names of the primaryKey KeyIsAutoInc bool // if pk[0] is an auto_increment column DisableAutoUpdateStatistics atomic.Bool // contains filtered or unexported fields }
func (*TableInfo) AutoUpdateStatistics ¶
func (t *TableInfo) AutoUpdateStatistics(ctx context.Context, interval time.Duration, logger loggers.Advanced)
AutoUpdateStatistics runs a loop that updates the table statistics every interval. This will continue until Close() is called on the tableInfo, or t.DisableAutoUpdateStatistics is set to true.
func (*TableInfo) PrimaryKeyIsMemoryComparable ¶
PrimaryKeyIsMemoryComparable checks that the PRIMARY KEY type is compatible. We no longer need this check for the chunker, since it can handle any type of key in the composite chunker. But the migration still needs to verify this, because of the delta map feature, which requires binary comparable keys.
func (*TableInfo) PrimaryKeyValues ¶
PrimaryKeyValues helps extract the PRIMARY KEY from a row image. It uses our knowledge of the ordinal position of columns to find the position of primary key columns (there might be more than one). For minimal row image, you need to send the before image to extract the PK. This is because in the after image, the PK might be nil.
func (*TableInfo) SetInfo ¶
SetInfo reads from MySQL metadata (usually infoschema) and sets the values in TableInfo.