tidb: github.com/pingcap/tidb/util/ranger Index | Files

package ranger

import "github.com/pingcap/tidb/util/ranger"


Package Files

checker.go detacher.go points.go ranger.go types.go


var (
    ErrUnsupportedType = terror.ClassOptimizer.New(errno.ErrUnsupportedType, errno.MySQLErrName[errno.ErrUnsupportedType])

Error instances.

func CutDatumByPrefixLen Uses

func CutDatumByPrefixLen(v *types.Datum, length int, tp *types.FieldType) bool

CutDatumByPrefixLen cuts the datum according to the prefix length. If it's UTF8 encoded, we will cut it by characters rather than bytes.

func DetachCondsForColumn Uses

func DetachCondsForColumn(sctx sessionctx.Context, conds []expression.Expression, col *expression.Column) (accessConditions, otherConditions []expression.Expression)

DetachCondsForColumn detaches access conditions for specified column from other filter conditions.

func ExtractAccessConditionsForColumn Uses

func ExtractAccessConditionsForColumn(conds []expression.Expression, uniqueID int64) []expression.Expression

ExtractAccessConditionsForColumn extracts the access conditions used for range calculation. Since we don't need to return the remained filter conditions, it is much simpler than DetachCondsForColumn.

func ExtractEqAndInCondition Uses

func ExtractEqAndInCondition(sctx sessionctx.Context, conditions []expression.Expression,
    cols []*expression.Column, lengths []int) ([]expression.Expression, []expression.Expression, []expression.Expression, bool)

ExtractEqAndInCondition will split the given condition into three parts by the information of index columns and their lengths. accesses: The condition will be used to build range. filters: filters is the part that some access conditions need to be evaluate again since it's only the prefix part of char column. newConditions: We'll simplify the given conditions if there're multiple in conditions or eq conditions on the same column.

e.g. if there're a in (1, 2, 3) and a in (2, 3, 4). This two will be combined to a in (2, 3) and pushed to newConditions.

bool: indicate whether there's nil range when merging eq and in conditions.

type DetachRangeResult Uses

type DetachRangeResult struct {
    // Ranges is the ranges extracted and built from conditions.
    Ranges []*Range
    // AccessConds is the extracted conditions for access.
    AccessConds []expression.Expression
    // RemainedConds is the filter conditions which should be kept after access.
    RemainedConds []expression.Expression
    // EqCondCount is the number of equal conditions extracted.
    EqCondCount int
    // EqOrInCount is the number of equal/in conditions extracted.
    EqOrInCount int
    // IsDNFCond indicates if the top layer of conditions are in DNF.
    IsDNFCond bool

DetachRangeResult wraps up results when detaching conditions and builing ranges.

func DetachCondAndBuildRangeForIndex Uses

func DetachCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression, cols []*expression.Column,
    lengths []int) (*DetachRangeResult, error)

DetachCondAndBuildRangeForIndex will detach the index filters from table filters. The returned values are encapsulated into a struct DetachRangeResult, see its comments for explanation.

type Range Uses

type Range struct {
    LowVal  []types.Datum
    HighVal []types.Datum

    LowExclude  bool // Low value is exclusive.
    HighExclude bool // High value is exclusive.

Range represents a range generated in physical plan building phase.

func BuildColumnRange Uses

func BuildColumnRange(conds []expression.Expression, sc *stmtctx.StatementContext, tp *types.FieldType, colLen int) ([]*Range, error)

BuildColumnRange builds range from access conditions for general columns.

func BuildTableRange Uses

func BuildTableRange(accessConditions []expression.Expression, sc *stmtctx.StatementContext, tp *types.FieldType) ([]*Range, error)

BuildTableRange builds range of PK column for PhysicalTableScan.

func DetachSimpleCondAndBuildRangeForIndex Uses

func DetachSimpleCondAndBuildRangeForIndex(sctx sessionctx.Context, conditions []expression.Expression,
    cols []*expression.Column, lengths []int) ([]*Range, []expression.Expression, error)

DetachSimpleCondAndBuildRangeForIndex will detach the index filters from table filters. It will find the point query column firstly and then extract the range query column.

func FullIntRange Uses

func FullIntRange(isUnsigned bool) []*Range

FullIntRange is used for table range. Since table range cannot accept MaxValueDatum as the max value. So we need to set it to MaxInt64.

func FullNotNullRange Uses

func FullNotNullRange() []*Range

FullNotNullRange is (-∞, +∞) for Range.

func FullRange Uses

func FullRange() []*Range

FullRange is [null, +∞) for Range.

func NullRange Uses

func NullRange() []*Range

NullRange is [null, null] for Range.

func UnionRanges Uses

func UnionRanges(sc *stmtctx.StatementContext, ranges []*Range) ([]*Range, error)

UnionRanges sorts `ranges`, union adjacent ones if possible. For two intervals [a, b], [c, d], we have guaranteed that a <= c. If b >= c. Then two intervals are overlapped. And this two can be merged as [a, max(b, d)]. Otherwise they aren't overlapped.

func (*Range) Clone Uses

func (ran *Range) Clone() *Range

Clone clones a Range.

func (*Range) Encode Uses

func (ran *Range) Encode(sc *stmtctx.StatementContext, lowBuffer, highBuffer []byte) ([]byte, []byte, error)

Encode encodes the range to its encoded value.

func (*Range) IsFullRange Uses

func (ran *Range) IsFullRange() bool

IsFullRange check if the range is full scan range

func (*Range) IsPoint Uses

func (ran *Range) IsPoint(sc *stmtctx.StatementContext) bool

IsPoint returns if the range is a point.

func (*Range) PrefixEqualLen Uses

func (ran *Range) PrefixEqualLen(sc *stmtctx.StatementContext) (int, error)

PrefixEqualLen tells you how long the prefix of the range is a point. e.g. If this range is (1 2 3, 1 2 +inf), then the return value is 2.

func (*Range) String Uses

func (ran *Range) String() string

String implements the Stringer interface.

type RangeType Uses

type RangeType int

RangeType is alias for int.

const (
    IntRangeType RangeType = iota

RangeType constants.

Package ranger imports 20 packages (graph) and is imported by 132 packages. Updated 2020-05-31. Refresh now. Tools for package owners.