TiDB HashAggregation 学习日志

TiDB 源码阅读系列文章(二十二)Hash Aggregation

// AggFunc is the interface to evaluate the aggregate functions.
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
}

你可能感兴趣的:(TiDB HashAggregation 学习日志)