tidb: github.com/pingcap/tidb/executor/aggfuncs Index | Files

package aggfuncs

import "github.com/pingcap/tidb/executor/aggfuncs"

Index

Package Files

aggfuncs.go builder.go func_avg.go func_bitfuncs.go func_count.go func_count_distinct.go func_cume_dist.go func_first_row.go func_group_concat.go func_json_objectagg.go func_lead_lag.go func_max_min.go func_ntile.go func_percent_rank.go func_percentile.go func_rank.go func_stddevpop.go func_stddevsamp.go func_sum.go func_value.go func_varpop.go func_varsamp.go row_number.go

Constants

const (
    // DefUint32Size is the size of uint32
    DefUint32Size = int64(unsafe.Sizeof(uint32(0)))
    // DefUint64Size is the size of uint64
    DefUint64Size = int64(unsafe.Sizeof(uint64(0)))
    // DefInt64Size is the size of int64
    DefInt64Size = int64(unsafe.Sizeof(int64(0)))
    // DefFloat64Size is the size of float64
    DefFloat64Size = int64(unsafe.Sizeof(float64(0)))
    // DefTimeSize is the size of time
    DefTimeSize = int64(unsafe.Sizeof(types.Time{}))
    // DefRowSize is the size of row
    DefRowSize = int64(unsafe.Sizeof(chunk.Row{}))
    // DefBoolSize is the size of bool
    DefBoolSize = int64(unsafe.Sizeof(false))
    // DefInterfaceSize is the size of interface
    DefInterfaceSize = int64(16)
    // DefMyDecimalSize is the size of MyDecimal
    DefMyDecimalSize = int64(unsafe.Sizeof(types.MyDecimal{}))
    // DefDurationSize is the size of duration
    DefDurationSize = int64(unsafe.Sizeof(types.Duration{}))
)
const (
    // DefPartialResult4AvgDecimalSize is the size of partialResult4AvgDecimal
    DefPartialResult4AvgDecimalSize = int64(unsafe.Sizeof(partialResult4AvgDecimal{}))
    // DefPartialResult4AvgDistinctDecimalSize is the size of partialResult4AvgDistinctDecimal
    DefPartialResult4AvgDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4AvgDistinctDecimal{}))
    // DefPartialResult4AvgFloat64Size is the size of partialResult4AvgFloat64
    DefPartialResult4AvgFloat64Size = int64(unsafe.Sizeof(partialResult4AvgFloat64{}))
    // DefPartialResult4AvgDistinctFloat64Size is the size of partialResult4AvgDistinctFloat64
    DefPartialResult4AvgDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4AvgDistinctFloat64{}))
)
const (
    // DefPartialResult4CountDistinctIntSize is the size of partialResult4CountDistinctInt
    DefPartialResult4CountDistinctIntSize = int64(unsafe.Sizeof(partialResult4CountDistinctInt{}))
    // DefPartialResult4CountDistinctRealSize is the size of partialResult4CountDistinctReal
    DefPartialResult4CountDistinctRealSize = int64(unsafe.Sizeof(partialResult4CountDistinctReal{}))
    // DefPartialResult4CountDistinctDecimalSize is the size of partialResult4CountDistinctDecimal
    DefPartialResult4CountDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4CountDistinctDecimal{}))
    // DefPartialResult4CountDistinctDurationSize is the size of partialResult4CountDistinctDuration
    DefPartialResult4CountDistinctDurationSize = int64(unsafe.Sizeof(partialResult4CountDistinctDuration{}))
    // DefPartialResult4CountDistinctStringSize is the size of partialResult4CountDistinctString
    DefPartialResult4CountDistinctStringSize = int64(unsafe.Sizeof(partialResult4CountDistinctString{}))
    // DefPartialResult4CountWithDistinctSize is the size of partialResult4CountWithDistinct
    DefPartialResult4CountWithDistinctSize = int64(unsafe.Sizeof(partialResult4CountWithDistinct{}))
    // DefPartialResult4ApproxCountDistinctSize is the size of partialResult4ApproxCountDistinct
    DefPartialResult4ApproxCountDistinctSize = int64(unsafe.Sizeof(partialResult4ApproxCountDistinct{}))
)
const (
    // DefPartialResult4FirstRowIntSize is the size of partialResult4FirstRowInt
    DefPartialResult4FirstRowIntSize = int64(unsafe.Sizeof(partialResult4FirstRowInt{}))
    // DefPartialResult4FirstRowFloat32Size is the size of partialResult4FirstRowFloat32
    DefPartialResult4FirstRowFloat32Size = int64(unsafe.Sizeof(partialResult4FirstRowFloat32{}))
    // DefPartialResult4FirstRowFloat64Size is the size of partialResult4FirstRowFloat64
    DefPartialResult4FirstRowFloat64Size = int64(unsafe.Sizeof(partialResult4FirstRowFloat64{}))
    // DefPartialResult4FirstRowStringSize is the size of partialResult4FirstRowString
    DefPartialResult4FirstRowStringSize = int64(unsafe.Sizeof(partialResult4FirstRowString{}))
    // DefPartialResult4FirstRowTimeSize is the size of partialResult4FirstRowTime
    DefPartialResult4FirstRowTimeSize = int64(unsafe.Sizeof(partialResult4FirstRowTime{}))
    // DefPartialResult4FirstRowDurationSize is the size of partialResult4FirstRowDuration
    DefPartialResult4FirstRowDurationSize = int64(unsafe.Sizeof(partialResult4FirstRowDuration{}))
    // DefPartialResult4FirstRowJSONSize is the size of partialResult4FirstRowJSON
    DefPartialResult4FirstRowJSONSize = int64(unsafe.Sizeof(partialResult4FirstRowJSON{}))
    // DefPartialResult4FirstRowDecimalSize is the size of partialResult4FirstRowDecimal
    DefPartialResult4FirstRowDecimalSize = int64(unsafe.Sizeof(partialResult4FirstRowDecimal{}))
    // DefPartialResult4FirstRowEnumSize is the size of partialResult4FirstRowEnum
    DefPartialResult4FirstRowEnumSize = int64(unsafe.Sizeof(partialResult4FirstRowEnum{}))
    // DefPartialResult4FirstRowSetSize is the size of partialResult4FirstRowSet
    DefPartialResult4FirstRowSetSize = int64(unsafe.Sizeof(partialResult4FirstRowSet{}))
)
const (
    // DefPartialResult4GroupConcatSize is the size of partialResult4GroupConcat
    DefPartialResult4GroupConcatSize = int64(unsafe.Sizeof(partialResult4GroupConcat{}))
    // DefPartialResult4GroupConcatDistinctSize is the size of partialResult4GroupConcatDistinct
    DefPartialResult4GroupConcatDistinctSize = int64(unsafe.Sizeof(partialResult4GroupConcatDistinct{}))
    // DefPartialResult4GroupConcatOrderSize is the size of partialResult4GroupConcatOrder
    DefPartialResult4GroupConcatOrderSize = int64(unsafe.Sizeof(partialResult4GroupConcatOrder{}))
    // DefPartialResult4GroupConcatOrderDistinctSize is the size of partialResult4GroupConcatOrderDistinct
    DefPartialResult4GroupConcatOrderDistinctSize = int64(unsafe.Sizeof(partialResult4GroupConcatOrderDistinct{}))
)
const (
    // DefPartialResult4MaxMinIntSize is the size of partialResult4MaxMinInt
    DefPartialResult4MaxMinIntSize = int64(unsafe.Sizeof(partialResult4MaxMinInt{}))
    // DefPartialResult4MaxMinUintSize is the size of partialResult4MaxMinUint
    DefPartialResult4MaxMinUintSize = int64(unsafe.Sizeof(partialResult4MaxMinUint{}))
    // DefPartialResult4MaxMinDecimalSize is the size of partialResult4MaxMinDecimal
    DefPartialResult4MaxMinDecimalSize = int64(unsafe.Sizeof(partialResult4MaxMinDecimal{}))
    // DefPartialResult4MaxMinFloat32Size is the size of partialResult4MaxMinFloat32
    DefPartialResult4MaxMinFloat32Size = int64(unsafe.Sizeof(partialResult4MaxMinFloat32{}))
    // DefPartialResult4MaxMinFloat64Size is the size of partialResult4MaxMinFloat64
    DefPartialResult4MaxMinFloat64Size = int64(unsafe.Sizeof(partialResult4MaxMinFloat64{}))
    // DefPartialResult4TimeSize is the size of partialResult4Time
    DefPartialResult4TimeSize = int64(unsafe.Sizeof(partialResult4Time{}))
    // DefPartialResult4MaxMinDurationSize is the size of partialResult4MaxMinDuration
    DefPartialResult4MaxMinDurationSize = int64(unsafe.Sizeof(partialResult4MaxMinDuration{}))
    // DefPartialResult4MaxMinStringSize is the size of partialResult4MaxMinString
    DefPartialResult4MaxMinStringSize = int64(unsafe.Sizeof(partialResult4MaxMinString{}))
    // DefPartialResult4MaxMinJSONSize is the size of partialResult4MaxMinJSON
    DefPartialResult4MaxMinJSONSize = int64(unsafe.Sizeof(partialResult4MaxMinJSON{}))
    // DefPartialResult4MaxMinEnumSize is the size of partialResult4MaxMinEnum
    DefPartialResult4MaxMinEnumSize = int64(unsafe.Sizeof(partialResult4MaxMinEnum{}))
    // DefPartialResult4MaxMinSetSize is the size of partialResult4MaxMinSet
    DefPartialResult4MaxMinSetSize = int64(unsafe.Sizeof(partialResult4MaxMinSet{}))
)
const (
    // DefPartialResult4SumFloat64Size is the size of partialResult4SumFloat64
    DefPartialResult4SumFloat64Size = int64(unsafe.Sizeof(partialResult4SumFloat64{}))
    // DefPartialResult4SumDecimalSize is the size of partialResult4SumDecimal
    DefPartialResult4SumDecimalSize = int64(unsafe.Sizeof(partialResult4SumDecimal{}))
    // DefPartialResult4SumDistinctFloat64Size is the size of partialResult4SumDistinctFloat64
    DefPartialResult4SumDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4SumDistinctFloat64{}))
    // DefPartialResult4SumDistinctDecimalSize is the size of partialResult4SumDistinctDecimal
    DefPartialResult4SumDistinctDecimalSize = int64(unsafe.Sizeof(partialResult4SumDistinctDecimal{}))
)
const (
    // DefPartialResult4FirstValueSize is the size of partialResult4FirstValue
    DefPartialResult4FirstValueSize = int64(unsafe.Sizeof(partialResult4FirstValue{}))
    // DefPartialResult4LastValueSize is the size of partialResult4LastValue
    DefPartialResult4LastValueSize = int64(unsafe.Sizeof(partialResult4LastValue{}))
    // DefPartialResult4NthValueSize is the size of partialResult4NthValue
    DefPartialResult4NthValueSize = int64(unsafe.Sizeof(partialResult4NthValue{}))

    // DefValue4IntSize is the size of value4Int
    DefValue4IntSize = int64(unsafe.Sizeof(value4Int{}))
    // DefValue4Float32Size is the size of value4Float32
    DefValue4Float32Size = int64(unsafe.Sizeof(value4Float32{}))
    // DefValue4Float64Size is the size of value4Float64
    DefValue4Float64Size = int64(unsafe.Sizeof(value4Float64{}))
    // DefValue4DecimalSize is the size of value4Decimal
    DefValue4DecimalSize = int64(unsafe.Sizeof(value4Decimal{}))
    // DefValue4TimeSize is the size of value4Time
    DefValue4TimeSize = int64(unsafe.Sizeof(value4Time{}))
    // DefValue4DurationSize is the size of value4Duration
    DefValue4DurationSize = int64(unsafe.Sizeof(value4Duration{}))
    // DefValue4StringSize is the size of value4String
    DefValue4StringSize = int64(unsafe.Sizeof(value4String{}))
    // DefValue4JSONSize is the size of value4JSON
    DefValue4JSONSize = int64(unsafe.Sizeof(value4JSON{}))
)
const (
    // DefPartialResult4VarPopFloat64Size is the size of partialResult4VarPopFloat64
    DefPartialResult4VarPopFloat64Size = int64(unsafe.Sizeof(partialResult4VarPopFloat64{}))
    // DefPartialResult4VarPopDistinctFloat64Size is the size of partialResult4VarPopDistinctFloat64
    DefPartialResult4VarPopDistinctFloat64Size = int64(unsafe.Sizeof(partialResult4VarPopDistinctFloat64{}))
)
const (
    // DefPartialResult4BitFuncSize the size of partialResult4BitFunc
    DefPartialResult4BitFuncSize = int64(unsafe.Sizeof(partialResult4BitFunc(0)))
)
const (
    // DefPartialResult4CountSize is the size of partialResult4Count
    DefPartialResult4CountSize = int64(unsafe.Sizeof(partialResult4Count(0)))
)
const (
    // DefPartialResult4CumeDistSize is the size of partialResult4CumeDist
    DefPartialResult4CumeDistSize = int64(unsafe.Sizeof(partialResult4CumeDist{}))
)
const (
    // DefPartialResult4JsonObjectAgg is the size of partialResult4JsonObject
    DefPartialResult4JsonObjectAgg = int64(unsafe.Sizeof(partialResult4JsonObjectAgg{}))
)
const (
    // DefPartialResult4LeadLagSize is the size of partialResult4LeadLag
    DefPartialResult4LeadLagSize = int64(unsafe.Sizeof(partialResult4LeadLag{}))
)
const (
    // DefPartialResult4Ntile is the size of partialResult4Ntile
    DefPartialResult4Ntile = int64(unsafe.Sizeof(partialResult4Ntile{}))
)
const (
    //DefPartialResult4RankSize is the size of partialResult4Rank
    DefPartialResult4RankSize = int64(unsafe.Sizeof(partialResult4Rank{}))
)
const (
    // DefPartialResult4RowNumberSize is the size of partialResult4RowNumberSize
    DefPartialResult4RowNumberSize = int64(unsafe.Sizeof(partialResult4RowNumber{}))
)
const (
    // DefSliceSize represents size of an empty Slice
    DefSliceSize = int64(unsafe.Sizeof([]interface{}{}))
)

func GetDatumMemSize Uses

func GetDatumMemSize(d *types.Datum) int64

GetDatumMemSize calculates the memory size of each types.Datum in sortRow.byItems. types.Datum memory size = variable type's memory size + variable value's memory size.

func NewPartialResult4ApproxCountDistinct Uses

func NewPartialResult4ApproxCountDistinct() *partialResult4ApproxCountDistinct

NewPartialResult4ApproxCountDistinct builds a partial result for agg function ApproxCountDistinct.

func WriteTime Uses

func WriteTime(buf []byte, t types.Time)

WriteTime writes `t` into `buf`.

type AggFunc Uses

type AggFunc interface {
    // AllocPartialResult allocates a specific data structure to store the
    // partial result, initializes it, and converts it to PartialResult to
    // return back. The second returned value is the memDelta used to trace
    // memory usage. Aggregate operator implementation, no matter it's a hash
    // or stream, should hold this allocated PartialResult for the further
    // operations like: "ResetPartialResult", "UpdatePartialResult".
    AllocPartialResult() (pr PartialResult, memDelta int64)

    // ResetPartialResult resets the partial result to the original state for a
    // specific aggregate function. It converts the input PartialResult to the
    // specific data structure which stores the partial result and then reset
    // every field to the proper original state.
    ResetPartialResult(pr PartialResult)

    // UpdatePartialResult updates the specific partial result for an aggregate
    // function using the input rows which all belonging to the same data group.
    // It converts the PartialResult to the specific data structure which stores
    // the partial result and then iterates on the input rows and update that
    // partial result according to the functionality and the state of the
    // aggregate function. The returned value is the memDelta used to trace memory
    // usage.
    UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) (memDelta int64, err error)

    // MergePartialResult will be called in the final phase when parallelly
    // executing. It converts the PartialResult `src`, `dst` to the same specific
    // data structure which stores the partial results, and then evaluate the
    // final result using the partial results as input values. The returned value
    // is the memDelta used to trace memory usage.
    MergePartialResult(sctx sessionctx.Context, src, dst PartialResult) (memDelta int64, err error)

    // AppendFinalResult2Chunk finalizes the partial result and append the
    // final result to the input chunk. Like other operations, it converts the
    // input PartialResult to the specific data structure which stores the
    // partial result and then calculates the final result and append that
    // final result to the chunk provided.
    AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error
}

AggFunc is the interface to evaluate the aggregate functions.

func Build Uses

func Build(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDesc, ordinal int) AggFunc

Build is used to build a specific AggFunc implementation according to the input aggFuncDesc.

func BuildWindowFunctions Uses

func BuildWindowFunctions(ctx sessionctx.Context, windowFuncDesc *aggregation.AggFuncDesc, ordinal int, orderByCols []*expression.Column) AggFunc

BuildWindowFunctions builds specific window function according to function description and order by columns.

type PartialResult Uses

type PartialResult unsafe.Pointer

PartialResult represents data structure to store the partial result for the aggregate functions. Here we use unsafe.Pointer to allow the partial result to be any type.

type SlidingWindowAggFunc Uses

type SlidingWindowAggFunc interface {
    // Slide evaluates the aggregate functions using a sliding window. The input
    // lastStart and lastEnd are the interval of the former sliding window,
    // shiftStart, shiftEnd mean the sliding window offset. Note that the input
    // PartialResult stores the intermediate result which will be used in the next
    // sliding window, ensure call ResetPartialResult after a frame are evaluated
    // completely.
    Slide(sctx sessionctx.Context, rows []chunk.Row, lastStart, lastEnd uint64, shiftStart, shiftEnd uint64, pr PartialResult) error
}

SlidingWindowAggFunc is the interface to evaluate the aggregate functions using sliding window.

Package aggfuncs imports 32 packages (graph) and is imported by 17 packages. Updated 2020-11-24. Refresh now. Tools for package owners.