distsql

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

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTableRanges

func BuildTableRanges(tbl *model.TableInfo) ([]kv.KeyRange, error)

BuildTableRanges returns the key ranges encompassing the entire table, and its partitions if exists.

func CommonHandleRangesToKVRanges

func CommonHandleRangesToKVRanges(dctx *distsqlctx.DistSQLContext, tids []int64, ranges []*ranger.Range) (*kv.KeyRanges, error)

CommonHandleRangesToKVRanges converts common handle ranges to "KeyRange".

func EncodeIndexKey

func EncodeIndexKey(dctx *distsqlctx.DistSQLContext, ran *ranger.Range) ([]byte, []byte, error)

EncodeIndexKey gets encoded keys containing low and high

func FillDummySummariesForTiFlashTasks

func FillDummySummariesForTiFlashTasks(runtimeStatsColl *execdetails.RuntimeStatsColl, callee string, storeTypeName string, allPlanIDs []int, recordedPlanIDs map[int]int)

FillDummySummariesForTiFlashTasks fills dummy execution summaries for mpp tasks which lack summaries

func GetSystemEndian

func GetSystemEndian() tipb.Endian

GetSystemEndian gets the system endian.

func IndexRangesToKVRanges

func IndexRangesToKVRanges(dctx *distsqlctx.DistSQLContext, tid, idxID int64, ranges []*ranger.Range) (*kv.KeyRanges, error)

IndexRangesToKVRanges converts index ranges to "KeyRange".

func IndexRangesToKVRangesForTables

func IndexRangesToKVRangesForTables(dctx *distsqlctx.DistSQLContext, tids []int64, idxID int64, ranges []*ranger.Range) (*kv.KeyRanges, error)

IndexRangesToKVRangesForTables converts indexes ranges to "KeyRange".

func IndexRangesToKVRangesWithInterruptSignal

func IndexRangesToKVRangesWithInterruptSignal(dctx *distsqlctx.DistSQLContext, tid, idxID int64, ranges []*ranger.Range, memTracker *memory.Tracker, interruptSignal *atomic.Value) (*kv.KeyRanges, error)

IndexRangesToKVRangesWithInterruptSignal converts index ranges to "KeyRange". The process can be interrupted by set `interruptSignal` to true.

func PartitionHandlesToKVRanges

func PartitionHandlesToKVRanges(handles []kv.Handle) ([]kv.KeyRange, []int)

PartitionHandlesToKVRanges convert ParitionHandles to kv ranges. Handle in slices must be kv.PartitionHandle

func SetEncodeType

func SetEncodeType(ctx *distsqlctx.DistSQLContext, dagReq *tipb.DAGRequest)

SetEncodeType sets the encoding method for the DAGRequest. The supported encoding methods are: 1. TypeChunk: the result is encoded using the Chunk format, refer util/chunk/chunk.go 2. TypeDefault: the result is encoded row by row

func SetTiFlashConfVarsInContext

func SetTiFlashConfVarsInContext(ctx context.Context, dctx *distsqlctx.DistSQLContext) context.Context

SetTiFlashConfVarsInContext set some TiFlash config variables in context.

func SplitRangesAcrossInt64Boundary

func SplitRangesAcrossInt64Boundary(ranges []*ranger.Range, keepOrder bool, desc bool, isCommonHandle bool) ([]*ranger.Range, []*ranger.Range)

SplitRangesAcrossInt64Boundary split the ranges into two groups: 1. signedRanges is less or equal than MaxInt64 2. unsignedRanges is greater than MaxInt64

We do this because every key of tikv is encoded as an int64. As a result, MaxUInt64 is smaller than zero when interpreted as an int64 variable.

This function does the following:

  1. split ranges into two groups as described above.
  2. if there's a range that straddles the int64 boundary, split it into two ranges, which results in one smaller and one greater than MaxInt64.

if `KeepOrder` is false, we merge the two groups of ranges into one group, to save a rpc call later if `desc` is false, return signed ranges first, vice versa.

func TableHandleRangesToKVRanges

func TableHandleRangesToKVRanges(dctx *distsqlctx.DistSQLContext, tid []int64, isCommonHandle bool, ranges []*ranger.Range) (*kv.KeyRanges, error)

TableHandleRangesToKVRanges convert table handle ranges to "KeyRanges" for multiple tables.

func TableHandlesToKVRanges

func TableHandlesToKVRanges(tid int64, handles []kv.Handle) ([]kv.KeyRange, []int)

TableHandlesToKVRanges converts sorted handle to kv ranges. For continuous handles, we should merge them to a single key range.

func TableRangesToKVRanges

func TableRangesToKVRanges(tid int64, ranges []*ranger.Range) []kv.KeyRange

TableRangesToKVRanges converts table ranges to "KeyRange". Note this function should not be exported, but currently br refers to it, so have to keep it.

func VerifyTxnScope

func VerifyTxnScope(txnScope string, physicalTableID int64, is infoschema.MetaOnlyInfoSchema) bool

VerifyTxnScope verify whether the txnScope and visited physical table break the leader rule's dcLocation.

func WithSQLKvExecCounterInterceptor

func WithSQLKvExecCounterInterceptor(ctx context.Context, counter *stmtstats.KvExecCounter) context.Context

WithSQLKvExecCounterInterceptor binds an interceptor for client-go to count the number of SQL executions of each TiKV (if any).

Types

type CopRuntimeStats

type CopRuntimeStats interface {
	// GetCopRuntimeStats gets the cop runtime stats information.
	GetCopRuntimeStats() *copr.CopRuntimeStats
}

CopRuntimeStats is an interface uses to check whether the result has cop runtime stats.

type RequestBuilder

type RequestBuilder struct {
	kv.Request
	// contains filtered or unexported fields
}

RequestBuilder is used to build a "kv.Request". It is called before we issue a kv request by "Select".

func (*RequestBuilder) Build

func (builder *RequestBuilder) Build() (*kv.Request, error)

Build builds a "kv.Request".

func (*RequestBuilder) SetAllowBatchCop

func (builder *RequestBuilder) SetAllowBatchCop(batchCop bool) *RequestBuilder

SetAllowBatchCop sets `BatchCop` property.

func (*RequestBuilder) SetAnalyzeRequest

func (builder *RequestBuilder) SetAnalyzeRequest(ana *tipb.AnalyzeReq, isoLevel kv.IsoLevel) *RequestBuilder

SetAnalyzeRequest sets the request type to "ReqTypeAnalyze" and construct request data.

func (*RequestBuilder) SetChecksumRequest

func (builder *RequestBuilder) SetChecksumRequest(checksum *tipb.ChecksumRequest) *RequestBuilder

SetChecksumRequest sets the request type to "ReqTypeChecksum" and construct request data.

func (*RequestBuilder) SetClosestReplicaReadAdjuster

func (builder *RequestBuilder) SetClosestReplicaReadAdjuster(chkFn kv.CoprRequestAdjuster) *RequestBuilder

SetClosestReplicaReadAdjuster sets request CoprRequestAdjuster

func (*RequestBuilder) SetConcurrency

func (builder *RequestBuilder) SetConcurrency(concurrency int) *RequestBuilder

SetConcurrency sets "Concurrency" for "kv.Request".

func (*RequestBuilder) SetConnIDAndConnAlias

func (builder *RequestBuilder) SetConnIDAndConnAlias(connID uint64, connAlias string) *RequestBuilder

SetConnIDAndConnAlias sets connection id for the builder.

func (*RequestBuilder) SetDAGRequest

func (builder *RequestBuilder) SetDAGRequest(dag *tipb.DAGRequest) *RequestBuilder

SetDAGRequest sets the request type to "ReqTypeDAG" and construct request data.

func (*RequestBuilder) SetDesc

func (builder *RequestBuilder) SetDesc(desc bool) *RequestBuilder

SetDesc sets "Desc" for "kv.Request".

func (*RequestBuilder) SetExplicitRequestSourceType

func (builder *RequestBuilder) SetExplicitRequestSourceType(sourceType string) *RequestBuilder

SetExplicitRequestSourceType sets the explicit request source type.

func (*RequestBuilder) SetFromInfoSchema

func (builder *RequestBuilder) SetFromInfoSchema(is infoschema.MetaOnlyInfoSchema) *RequestBuilder

SetFromInfoSchema sets the following fields from infoSchema: "bundles"

func (*RequestBuilder) SetFromSessionVars

func (builder *RequestBuilder) SetFromSessionVars(dctx *distsqlctx.DistSQLContext) *RequestBuilder

SetFromSessionVars sets the following fields for "kv.Request" from session variables: "Concurrency", "IsolationLevel", "NotFillCache", "TaskID", "Priority", "ReplicaRead", "ResourceGroupTagger", "ResourceGroupName"

func (*RequestBuilder) SetHandleRanges

func (builder *RequestBuilder) SetHandleRanges(dctx *distsqlctx.DistSQLContext, tid int64, isCommonHandle bool, ranges []*ranger.Range) *RequestBuilder

SetHandleRanges sets "KeyRanges" for "kv.Request" by converting table handle range "ranges" to "KeyRanges" firstly.

func (*RequestBuilder) SetHandleRangesForTables

func (builder *RequestBuilder) SetHandleRangesForTables(dctx *distsqlctx.DistSQLContext, tid []int64, isCommonHandle bool, ranges []*ranger.Range) *RequestBuilder

SetHandleRangesForTables sets "KeyRanges" for "kv.Request" by converting table handle range "ranges" to "KeyRanges" firstly for multiple tables.

func (*RequestBuilder) SetIndexRanges

func (builder *RequestBuilder) SetIndexRanges(dctx *distsqlctx.DistSQLContext, tid, idxID int64, ranges []*ranger.Range) *RequestBuilder

SetIndexRanges sets "KeyRanges" for "kv.Request" by converting index range "ranges" to "KeyRanges" firstly.

func (*RequestBuilder) SetIndexRangesForTables

func (builder *RequestBuilder) SetIndexRangesForTables(dctx *distsqlctx.DistSQLContext, tids []int64, idxID int64, ranges []*ranger.Range) *RequestBuilder

SetIndexRangesForTables sets "KeyRanges" for "kv.Request" by converting multiple indexes range "ranges" to "KeyRanges" firstly.

func (*RequestBuilder) SetIsStaleness

func (builder *RequestBuilder) SetIsStaleness(is bool) *RequestBuilder

SetIsStaleness sets request IsStaleness

func (*RequestBuilder) SetKeepOrder

func (builder *RequestBuilder) SetKeepOrder(order bool) *RequestBuilder

SetKeepOrder sets "KeepOrder" for "kv.Request".

func (*RequestBuilder) SetKeyRanges

func (builder *RequestBuilder) SetKeyRanges(keyRanges []kv.KeyRange) *RequestBuilder

SetKeyRanges sets "KeyRanges" for "kv.Request".

func (*RequestBuilder) SetKeyRangesWithHints

func (builder *RequestBuilder) SetKeyRangesWithHints(keyRanges []kv.KeyRange, hints []int) *RequestBuilder

SetKeyRangesWithHints sets "KeyRanges" for "kv.Request" with row count hints.

func (*RequestBuilder) SetMemTracker

func (builder *RequestBuilder) SetMemTracker(tracker *memory.Tracker) *RequestBuilder

SetMemTracker sets a memTracker for this request.

func (*RequestBuilder) SetPaging

func (builder *RequestBuilder) SetPaging(paging bool) *RequestBuilder

SetPaging sets "Paging" flag for "kv.Request".

func (*RequestBuilder) SetPartitionIDAndRanges

func (builder *RequestBuilder) SetPartitionIDAndRanges(partitionIDAndRanges []kv.PartitionIDAndRanges) *RequestBuilder

SetPartitionIDAndRanges sets `PartitionIDAndRanges` property.

func (*RequestBuilder) SetPartitionKeyRanges

func (builder *RequestBuilder) SetPartitionKeyRanges(keyRanges [][]kv.KeyRange) *RequestBuilder

SetPartitionKeyRanges sets the "KeyRanges" for "kv.Request" on partitioned table cases.

func (*RequestBuilder) SetPartitionsAndHandles

func (builder *RequestBuilder) SetPartitionsAndHandles(handles []kv.Handle) *RequestBuilder

SetPartitionsAndHandles sets "KeyRanges" for "kv.Request" by converting ParitionHandles to KeyRanges. handles in slice must be kv.PartitionHandle.

func (*RequestBuilder) SetReadReplicaScope

func (builder *RequestBuilder) SetReadReplicaScope(scope string) *RequestBuilder

SetReadReplicaScope sets request readReplicaScope

func (*RequestBuilder) SetResourceGroupName

func (builder *RequestBuilder) SetResourceGroupName(name string) *RequestBuilder

SetResourceGroupName sets the request resource group name.

func (*RequestBuilder) SetResourceGroupTagger

func (builder *RequestBuilder) SetResourceGroupTagger(tagger *kv.ResourceGroupTagBuilder) *RequestBuilder

SetResourceGroupTagger sets the request resource group tagger.

func (*RequestBuilder) SetStartTS

func (builder *RequestBuilder) SetStartTS(startTS uint64) *RequestBuilder

SetStartTS sets "StartTS" for "kv.Request".

func (*RequestBuilder) SetStoreType

func (builder *RequestBuilder) SetStoreType(storeType kv.StoreType) *RequestBuilder

SetStoreType sets "StoreType" for "kv.Request".

func (*RequestBuilder) SetTableHandles

func (builder *RequestBuilder) SetTableHandles(tid int64, handles []kv.Handle) *RequestBuilder

SetTableHandles sets "KeyRanges" for "kv.Request" by converting table handles "handles" to "KeyRanges" firstly.

func (*RequestBuilder) SetTableRanges

func (builder *RequestBuilder) SetTableRanges(tid int64, tableRanges []*ranger.Range) *RequestBuilder

SetTableRanges sets "KeyRanges" for "kv.Request" by converting "tableRanges" to "KeyRanges" firstly. Note this function should be deleted or at least not exported, but currently br refers it, so have to keep it.

func (*RequestBuilder) SetTiDBServerID

func (builder *RequestBuilder) SetTiDBServerID(serverID uint64) *RequestBuilder

SetTiDBServerID sets "TiDBServerID" for "kv.Request"

ServerID is a unique id of TiDB instance among the cluster.
See https://github.com/pingcap/tidb/blob/master/docs/design/2020-06-01-global-kill.md

func (*RequestBuilder) SetTxnScope

func (builder *RequestBuilder) SetTxnScope(scope string) *RequestBuilder

SetTxnScope sets request TxnScope

func (*RequestBuilder) SetWrappedKeyRanges

func (builder *RequestBuilder) SetWrappedKeyRanges(keyRanges *kv.KeyRanges) *RequestBuilder

SetWrappedKeyRanges sets "KeyRanges" for "kv.Request".

type SelectResult

type SelectResult interface {
	// NextRaw gets the next raw result.
	NextRaw(context.Context) ([]byte, error)
	// Next reads the data into chunk.
	Next(context.Context, *chunk.Chunk) error
	// Close closes the iterator.
	Close() error
}

SelectResult is an iterator of coprocessor partial results.

func Analyze

func Analyze(ctx context.Context, client kv.Client, kvReq *kv.Request, vars any,
	isRestrict bool, dctx *distsqlctx.DistSQLContext) (SelectResult, error)

Analyze do a analyze request.

func Checksum

func Checksum(ctx context.Context, client kv.Client, kvReq *kv.Request, vars any) (SelectResult, error)

Checksum sends a checksum request.

func GenSelectResultFromMPPResponse

func GenSelectResultFromMPPResponse(dctx *distsqlctx.DistSQLContext, fieldTypes []*types.FieldType, planIDs []int, rootID int, resp kv.Response) SelectResult

GenSelectResultFromMPPResponse generates an iterator from response.

func NewSerialSelectResults

func NewSerialSelectResults(selectResults []SelectResult) SelectResult

NewSerialSelectResults create a SelectResult which will read each SelectResult serially.

func NewSortedSelectResults

func NewSortedSelectResults(ectx expression.EvalContext, selectResult []SelectResult, schema *expression.Schema, byitems []*util.ByItems, memTracker *memory.Tracker) SelectResult

NewSortedSelectResults is only for partition table If schema == nil, sort by first few columns.

func Select

func Select(ctx context.Context, dctx *distsqlctx.DistSQLContext, kvReq *kv.Request, fieldTypes []*types.FieldType) (SelectResult, error)

Select sends a DAG request, returns SelectResult. In kvReq, KeyRanges is required, Concurrency/KeepOrder/Desc/IsolationLevel/Priority are optional.

func SelectWithRuntimeStats

func SelectWithRuntimeStats(ctx context.Context, dctx *distsqlctx.DistSQLContext, kvReq *kv.Request,
	fieldTypes []*types.FieldType, copPlanIDs []int, rootPlanID int) (SelectResult, error)

SelectWithRuntimeStats sends a DAG request, returns SelectResult. The difference from Select is that SelectWithRuntimeStats will set copPlanIDs into selectResult, which can help selectResult to collect runtime stats.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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