util

package
v1.1.0-beta.0...-aa41092 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UseCurrentSessionOpt to make sure the sql is executed in current session.
	UseCurrentSessionOpt = []sqlexec.OptionFuncAlias{sqlexec.ExecOptionUseCurSession}

	// StatsCtx is used to mark the request as internal stats foreground priority.
	StatsCtx = kv.WithInternalSourceType(context.Background(), kv.InternalTxnStatsForegroundPriority)
)
View Source
var (
	// FlagWrapTxn indicates whether to wrap a transaction.
	FlagWrapTxn = 0
)
View Source
var GlobalAutoAnalyzeProcessList = newGlobalAutoAnalyzeProcessList()

GlobalAutoAnalyzeProcessList is used to track the auto analyze process.

Functions

func CallWithSCtx

func CallWithSCtx(pool syssession.Pool, f func(sctx sessionctx.Context) error, flags ...int) (err error)

CallWithSCtx allocates a sctx from the pool and call the f().

func DurationToTS

func DurationToTS(d time.Duration) uint64

DurationToTS converts duration to timestamp.

func Exec

func Exec(sctx sessionctx.Context, sql string, args ...any) (sqlexec.RecordSet, error)

Exec is a helper function to execute sql and return RecordSet.

func ExecRows

func ExecRows(sctx sessionctx.Context, sql string, args ...any) (rows []chunk.Row, fields []*resolve.ResultField, err error)

ExecRows is a helper function to execute sql and return rows and fields.

func ExecRowsWithCtx

func ExecRowsWithCtx(
	ctx context.Context,
	sctx sessionctx.Context,
	sql string,
	args ...any,
) (rows []chunk.Row, fields []*resolve.ResultField, err error)

ExecRowsWithCtx is a helper function to execute sql and return rows and fields.

func ExecWithCtx

func ExecWithCtx(
	ctx context.Context,
	sctx sessionctx.Context,
	sql string,
	args ...any,
) (sqlexec.RecordSet, error)

ExecWithCtx is a helper function to execute sql and return RecordSet.

func ExecWithOpts

func ExecWithOpts(sctx sessionctx.Context, opts []sqlexec.OptionFuncAlias, sql string, args ...any) (rows []chunk.Row, fields []*resolve.ResultField, err error)

ExecWithOpts is a helper function to execute sql and return rows and fields.

func ExecWithOptsWithCtx

func ExecWithOptsWithCtx(ctx context.Context, sctx sessionctx.Context, opts []sqlexec.OptionFuncAlias, sql string, args ...any) (rows []chunk.Row, fields []*resolve.ResultField, err error)

ExecWithOptsWithCtx is a helper function to execute sql with context and options and return rows and fields.

func GetCurrentPruneMode

func GetCurrentPruneMode(pool syssession.Pool) (mode string, err error)

GetCurrentPruneMode returns the current latest partitioning table prune mode.

func GetStartTS

func GetStartTS(sctx sessionctx.Context) (uint64, error)

GetStartTS gets the start ts from current transaction.

func IsSpecialGlobalIndex

func IsSpecialGlobalIndex(idx *model.IndexInfo, tblInfo *model.TableInfo) bool

IsSpecialGlobalIndex checks a index is a special global index or not. A special global index is one that is a global index and has virtual generated columns or prefix columns.

func UpdateSCtxVarsForStats

func UpdateSCtxVarsForStats(sctx sessionctx.Context) (func(), error)

UpdateSCtxVarsForStats updates all necessary variables that may affect the behavior of statistics. It restores the original settings on failure and returns a function to restore them after use on success.

func WrapTxn

func WrapTxn(sctx sessionctx.Context, f func(sctx sessionctx.Context) error) (err error)

WrapTxn uses a transaction here can let different SQLs in this operation have the same data visibility.

Types

type AutoAnalyzeProcIDGenerator

type AutoAnalyzeProcIDGenerator interface {
	// AutoAnalyzeProcID generates an analyze ID.
	AutoAnalyzeProcID() uint64
	ReleaseAutoAnalyzeProcID(uint64)
}

AutoAnalyzeProcIDGenerator is used to generate auto analyze proc ID.

func NewGenerator

func NewGenerator(autoAnalyzeProcIDGetter func() uint64, releaseAutoAnalyzeProcID func(uint64)) AutoAnalyzeProcIDGenerator

NewGenerator creates a new Generator.

type AutoAnalyzeTracker

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

AutoAnalyzeTracker is used to track the auto analyze process.

func NewAutoAnalyzeTracker

func NewAutoAnalyzeTracker(track func(id uint64, ctx sysproctrack.TrackProc) error, untrack func(id uint64)) *AutoAnalyzeTracker

NewAutoAnalyzeTracker creates a new AutoAnalyzeTracker.

func (*AutoAnalyzeTracker) Track

Track is used to track the auto analyze process.

func (*AutoAnalyzeTracker) UnTrack

func (t *AutoAnalyzeTracker) UnTrack(id uint64)

UnTrack is used to untrack the auto analyze process.

type LeaseGetter

type LeaseGetter interface {
	// Lease returns the stats lease.
	Lease() time.Duration
	// SetLease sets the stats lease. Only used for test.
	SetLease(lease time.Duration)
}

LeaseGetter is used to get the stats lease.

func NewLeaseGetter

func NewLeaseGetter(lease time.Duration) LeaseGetter

NewLeaseGetter creates a new LeaseGetter.

type Pool

type Pool interface {
	// GPool returns the goroutine pool.
	GPool() *gp.Pool

	// SPool returns the session pool.
	SPool() syssession.Pool

	// Close closes the goroutine pool.
	Close()
}

Pool is used to reuse goroutine and session.

func NewPool

func NewPool(p syssession.Pool) Pool

NewPool creates a new Pool.

type SnapshotTableInfoGetter

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

SnapshotTableInfoGetter gets the table of a physical ID in one InfoSchema snapshot. On InfoSchema V1, each partition lookup scans all tables, so it builds a partition map on the first call of ParentTableID. It is safe for concurrent use. Create one for each snapshot instead of sharing a cache, because callers on different schema versions would rebuild a shared map.

func NewSnapshotTableInfoGetter

func NewSnapshotTableInfoGetter(is infoschema.InfoSchema) *SnapshotTableInfoGetter

NewSnapshotTableInfoGetter creates a SnapshotTableInfoGetter for the InfoSchema snapshot.

func (*SnapshotTableInfoGetter) ParentTableID

func (g *SnapshotTableInfoGetter) ParentTableID(physicalID int64) (tableID int64, isPartition bool)

ParentTableID returns the parent table ID if the physicalID is a partition.

func (*SnapshotTableInfoGetter) TableInfoByID

func (g *SnapshotTableInfoGetter) TableInfoByID(physicalID int64) (table.Table, bool)

TableInfoByID returns the table of the physicalID. If the physicalID is a partition, it returns the parent table.

func (*SnapshotTableInfoGetter) TableItemByID

func (g *SnapshotTableInfoGetter) TableItemByID(physicalID int64) (infoschema.TableItem, bool)

TableItemByID returns the table item of the physicalID. If the physicalID is a partition, it returns the item of the parent table.

type TableInfoGetter

type TableInfoGetter interface {
	// TableInfoByID returns the table info specified by the physicalID.
	// If the physicalID is corresponding to a partition, return its parent table.
	TableInfoByID(is infoschema.InfoSchema, physicalID int64) (table.Table, bool)
}

TableInfoGetter is used to get table meta info.

func NewTableInfoGetter

func NewTableInfoGetter() TableInfoGetter

NewTableInfoGetter creates a TableInfoGetter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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