executor

package
v0.0.0-debug-20260702 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultResolveVariable func(
	varName string, isSystemVar, isGlobalVar bool,
) (any, error)

DefaultResolveVariable is a process-wide fallback system-variable resolver, installed once at startup by pkg/frontend's init() from gSysVarsDefs. It is consulted whenever code needs to resolve a system variable from a *process.Process that has no session-bound resolver attached — typically background flows (idxcron ALTER REINDEX, ProcessInitSQL, bootstrap, cron tasks).

Lives here in pkg/util/executor because:

  • pkg/iscp, pkg/sql/compile, and pkg/frontend already import this package, so it's the lowest common ancestor.
  • Conceptually paired with Options.WithResolveVariableFunc and proc.Base.IsFrontend — all three turn on the same axis ("does this proc have a session?").

Nil-safe by design: tests that don't blank-import pkg/frontend see this as nil; callers must nil-check before invocation. See pkg/iscp/iteration.go::ProcessInitSQL and pkg/sql/compile/util.go::resolveVariableOrDefault for the canonical nil-checked consumers.

Defaults-only — SET GLOBAL overrides are NOT honoured. Per-index admin-tuned values are expected to ride along in the captured-vars sqlexec.Metadata that the idxcron task carries.

Functions

func AppendBytesRows

func AppendBytesRows(m *MemResult, col int, values [][]byte) error

func AppendFixedRows

func AppendFixedRows[T any](m *MemResult, col int, values []T) error

func AppendStringRows

func AppendStringRows(m *MemResult, col int, values []string) error

func GetBytesRows

func GetBytesRows(vec *vector.Vector) [][]byte

GetBytesRows get bytes rows, varchar, varbinary, text, json, etc.

func GetFixedRows

func GetFixedRows[T any](vec *vector.Vector) []T

GetFixedRows get fixed rows, int, float, etc.

func GetStringRows

func GetStringRows(vec *vector.Vector) []string

GetStringRows get bytes rows, varchar, varbinary, text, json, etc.

Types

type MemResult

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

MemResult used to test. Construct a Result from memory.

func NewMemResult

func NewMemResult(
	types []types.Type,
	mp *mpool.MPool) *MemResult

func (*MemResult) GetResult

func (m *MemResult) GetResult() Result

func (*MemResult) NewBatch

func (m *MemResult) NewBatch()

func (*MemResult) NewBatchWithRowCount

func (m *MemResult) NewBatchWithRowCount(rowcount int)

type Options

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

Options execute options.

func (Options) AccountID

func (opts Options) AccountID() uint32

AccountID returns account id

func (Options) AdjustTableExtraFunc

func (opts Options) AdjustTableExtraFunc() func(*api.SchemaExtra) error

func (Options) Database

func (opts Options) Database() string

Database returns default database

func (Options) DisableIncrStatement added in v1.0.0

func (opts Options) DisableIncrStatement() bool

DisableIncrStatement returns the txn operator need incr a new input statement

func (Options) EnableTrace added in v1.2.0

func (opts Options) EnableTrace() bool

func (Options) ExistsTxn

func (opts Options) ExistsTxn() bool

ExistsTxn return true if the txn is a exists txn which is not create by executor

func (Options) ExtraTxnOptions added in v1.2.0

func (opts Options) ExtraTxnOptions() []client.TxnOption

func (Options) ForceRebuildPlan

func (opts Options) ForceRebuildPlan() bool

func (Options) GetTimeZone added in v1.0.0

func (opts Options) GetTimeZone() *time.Location

GetTimeZone return the time zone of original session

func (Options) HasAccountID

func (opts Options) HasAccountID() bool

HasAccountID returns true if account is set

func (Options) HasExistsTxn

func (opts Options) HasExistsTxn() bool

HasExistsTxn return true if a exists txn is set

func (Options) IsFrontend

func (opts Options) IsFrontend() bool

func (Options) KeepTxnAlive

func (opts Options) KeepTxnAlive() bool

func (Options) LowerCaseTableNames added in v1.2.2

func (opts Options) LowerCaseTableNames() int64

func (Options) MinCommittedTS

func (opts Options) MinCommittedTS() timestamp.Timestamp

MinCommittedTS returns min committed ts

func (Options) ResolveVariableFunc

func (opts Options) ResolveVariableFunc() func(varName string, isSystemVar, isGlobalVar bool) (interface{}, error)

func (Options) SQL

func (opts Options) SQL() string

func (Options) SetupNewTxn

func (opts Options) SetupNewTxn(txnOp client.TxnOperator) Options

SetupNewTxn setup new txn

func (Options) StatementOption added in v1.2.0

func (opts Options) StatementOption() StatementOption

StatementOption returns statement options

func (Options) Streaming

func (opts Options) Streaming() (chan Result, chan error, bool)

func (Options) Txn

func (opts Options) Txn() client.TxnOperator

Txn returns the txn operator

func (Options) WaitCommittedLogApplied

func (opts Options) WaitCommittedLogApplied() bool

WaitCommittedLogApplied return true means need wait committed log applied in current cn.

func (Options) WithAccountID

func (opts Options) WithAccountID(accountID uint32) Options

WithAccountID execute sql in account

func (Options) WithAdjustTableExtraFunc

func (opts Options) WithAdjustTableExtraFunc(
	fn func(*api.SchemaExtra) error,
) Options

func (Options) WithDatabase

func (opts Options) WithDatabase(database string) Options

WithDatabase exec sql in database

func (Options) WithDisableIncrStatement added in v1.0.0

func (opts Options) WithDisableIncrStatement() Options

WithDisableIncrStatement disable incr statement

func (Options) WithDisableTrace added in v1.2.0

func (opts Options) WithDisableTrace() Options

func (Options) WithDisableWaitPaused

func (opts Options) WithDisableWaitPaused() Options

func (Options) WithEnableTrace added in v1.2.0

func (opts Options) WithEnableTrace() Options

func (Options) WithForceRebuildPlan

func (opts Options) WithForceRebuildPlan() Options

func (Options) WithFrontend

func (opts Options) WithFrontend(b bool) Options

WithFrontend marks the SQL execution as a frontend session-bound invocation (b=true) versus a background / internal one (b=false). Consumed by pkg/sql/compile/sql_executor.go's NewTopProcess which sets proc.Base.IsFrontend = opts.IsFrontend().

The default — `executor.Options{}` with no setter — is background (IsFrontend()=false). Frontend code that uses the internal SQL executor for session-bound queries opts in by calling WithFrontend(true). Background callers (idxcron, ProcessInitSQL, bootstrap, cron tasks, task service, …) don't need to call this — they inherit the default.

Takes a bool (rather than a no-arg setter) so callers that wrap an existing proc and re-invoke the executor can carry the flag forward via opts.WithFrontend(proc.Base.IsFrontend) — same shape as WithResolveVariableFunc(proc.GetResolveVariableFunc()).

func (Options) WithKeepTxnAlive

func (opts Options) WithKeepTxnAlive() Options

func (Options) WithLowerCaseTableNames added in v1.2.2

func (opts Options) WithLowerCaseTableNames(lower *int64) Options

func (Options) WithMinCommittedTS

func (opts Options) WithMinCommittedTS(ts timestamp.Timestamp) Options

WithMinCommittedTS use minCommittedTS to exec sql. It will set txn's snapshot to minCommittedTS+1, so the txn can see the data which committed at minCommittedTS. It's not work if txn operator is set.

func (Options) WithResolveVariableFunc

func (opts Options) WithResolveVariableFunc(fn func(varName string, isSystemVar, isGlobalVar bool) (interface{}, error)) Options

func (Options) WithSQL

func (opts Options) WithSQL(sql string) Options

func (Options) WithStatementOption added in v1.2.0

func (opts Options) WithStatementOption(statementOption StatementOption) Options

WithStatementOption set statement option

func (Options) WithStreaming

func (opts Options) WithStreaming(stream_chan chan Result, error_chan chan error) Options

func (Options) WithTimeZone added in v1.0.0

func (opts Options) WithTimeZone(timeZone *time.Location) Options

func (Options) WithTxn

func (opts Options) WithTxn(txnOp client.TxnOperator) Options

WithTxn exec sql in a exists txn

func (Options) WithUserTxn

func (opts Options) WithUserTxn() Options

func (Options) WithWaitCommittedLogApplied

func (opts Options) WithWaitCommittedLogApplied() Options

WithWaitCommittedLogApplied if set, the executor will wait all committed log applied for the txn.

type Result

type Result struct {
	LastInsertID uint64
	AffectedRows uint64
	Batches      []*batch.Batch
	Mp           *mpool.MPool
	LogicalPlan  *plan.Query
}

Result exec sql result

func NewResult

func NewResult(mp *mpool.MPool) Result

NewResult create result

func (Result) Close

func (res Result) Close()

func (Result) ReadRows

func (res Result) ReadRows(apply func(rows int, cols []*vector.Vector) bool)

ReadRows read all rows, apply is used to read cols data in a row. If apply return false, stop reading. If the query has a lot of data, apply will be called multiple times, giving a batch of rows for each call.

type SQLExecutor

type SQLExecutor interface {
	// Exec exec a sql in a exists txn.
	Exec(ctx context.Context, sql string, opts Options) (Result, error)
	// ExecTxn executor sql in a txn. execFunc can use TxnExecutor to exec multiple sql
	// in a transaction.
	ExecTxn(ctx context.Context, execFunc func(txn TxnExecutor) error, opts Options) error
}

SQLExecutor is used to execute internal sql. All internal requirements for writing data should be done using the internal sql executor, otherwise pessimistic transactions may not work.

func NewMemExecutor

func NewMemExecutor(mocker func(sql string) (Result, error)) SQLExecutor

NewMemExecutor used to testing

func NewMemExecutor2

func NewMemExecutor2(mocker func(sql string) (Result, error), txnOp client.TxnOperator) SQLExecutor

type StatementOption added in v1.2.0

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

StatementOption statement execute option.

func (StatementOption) AccountID added in v1.2.0

func (opts StatementOption) AccountID() uint32

func (StatementOption) AlterCopyDedupOpt

func (opts StatementOption) AlterCopyDedupOpt() *plan.AlterCopyOpt

func (StatementOption) DisableDropIncrStatement

func (opts StatementOption) DisableDropIncrStatement() bool

func (StatementOption) DisableLock

func (opts StatementOption) DisableLock() bool

func (StatementOption) DisableLog

func (opts StatementOption) DisableLog() bool

func (StatementOption) HasAccountID added in v1.2.0

func (opts StatementOption) HasAccountID() bool

func (StatementOption) HasParams

func (opts StatementOption) HasParams() bool

func (StatementOption) HasRoleID

func (opts StatementOption) HasRoleID() bool

func (StatementOption) HasUserID

func (opts StatementOption) HasUserID() bool

func (StatementOption) IgnoreCheckExperimental

func (opts StatementOption) IgnoreCheckExperimental() bool

func (StatementOption) IgnoreForeignKey

func (opts StatementOption) IgnoreForeignKey() bool

func (StatementOption) IgnorePublish

func (opts StatementOption) IgnorePublish() bool

func (StatementOption) KeepAutoIncrement

func (opts StatementOption) KeepAutoIncrement() uint64

func (StatementOption) KeepLogicalId

func (opts StatementOption) KeepLogicalId() uint64

func (StatementOption) Params

func (opts StatementOption) Params(
	mp *mpool.MPool,
) *vector.Vector

func (StatementOption) RoleID

func (opts StatementOption) RoleID() uint32

func (StatementOption) UserID

func (opts StatementOption) UserID() uint32

func (StatementOption) WaitPolicy added in v1.2.0

func (opts StatementOption) WaitPolicy() lock.WaitPolicy

WaitPolicy returns the wait policy for current statement

func (StatementOption) WithAccountID added in v1.2.0

func (opts StatementOption) WithAccountID(accountID uint32) StatementOption

WithAccountID execute sql in account

func (StatementOption) WithAlterCopyOpt

func (opts StatementOption) WithAlterCopyOpt(opt *plan.AlterCopyOpt) StatementOption

func (StatementOption) WithDisableDropIncrStatement

func (opts StatementOption) WithDisableDropIncrStatement() StatementOption

func (StatementOption) WithDisableLock

func (opts StatementOption) WithDisableLock() StatementOption

func (StatementOption) WithDisableLog

func (opts StatementOption) WithDisableLog() StatementOption

func (StatementOption) WithIgnoreCheckExperimental

func (opts StatementOption) WithIgnoreCheckExperimental() StatementOption

func (StatementOption) WithIgnoreForeignKey

func (opts StatementOption) WithIgnoreForeignKey() StatementOption

WithDisableIncrStatement disable incr statement

func (StatementOption) WithIgnorePublish

func (opts StatementOption) WithIgnorePublish() StatementOption

func (StatementOption) WithKeepAutoIncrement

func (opts StatementOption) WithKeepAutoIncrement(keep uint64) StatementOption

func (StatementOption) WithKeepLogicalId

func (opts StatementOption) WithKeepLogicalId(keep uint64) StatementOption

func (StatementOption) WithParams

func (opts StatementOption) WithParams(
	values []string,
) StatementOption

func (StatementOption) WithRoleID

func (opts StatementOption) WithRoleID(roleID uint32) StatementOption

func (StatementOption) WithUserID

func (opts StatementOption) WithUserID(userID uint32) StatementOption

func (StatementOption) WithWaitPolicy added in v1.2.0

func (opts StatementOption) WithWaitPolicy(waitPolicy lock.WaitPolicy) StatementOption

WithWaitPolicy set wait policy for current statement

type TxnExecutor

type TxnExecutor interface {
	Use(db string)
	LockTable(table string) error
	// NOTE: If you specify `AccoundId` in `StatementOption`, sql will be executed under that tenant.
	// If not specified, it will be executed under the system tenant by default.
	Exec(sql string, options StatementOption) (Result, error)
	Txn() client.TxnOperator
}

TxnExecutor exec all sql in a transaction.

func NewMemTxnExecutor

func NewMemTxnExecutor(mocker func(sql string) (Result, error), txnOperator client.TxnOperator) TxnExecutor

NewMemTxnExecutor used to testing

Directories

Path Synopsis
Package mock_executor is a generated GoMock package.
Package mock_executor is a generated GoMock package.

Jump to

Keyboard shortcuts

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