TiDB HashAggregation 學(xué)習(xí)日志

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
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子榕莺,更是在濱河造成了極大的恐慌羡鸥,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件涧狮,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機笨奠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來唤殴,“玉大人艰躺,你說我怎么就攤上這事≌0耍” “怎么了腺兴?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長廉侧。 經(jīng)常有香客問我页响,道長篓足,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任闰蚕,我火速辦了婚禮栈拖,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘没陡。我一直安慰自己涩哟,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布盼玄。 她就那樣靜靜地躺著贴彼,像睡著了一般。 火紅的嫁衣襯著肌膚如雪埃儿。 梳的紋絲不亂的頭發(fā)上器仗,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天,我揣著相機與錄音童番,去河邊找鬼精钮。 笑死,一個胖子當(dāng)著我的面吹牛剃斧,可吹牛的內(nèi)容都是我干的轨香。 我是一名探鬼主播,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼幼东,長吁一口氣:“原來是場噩夢啊……” “哼弹沽!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起筋粗,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤策橘,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后娜亿,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體丽已,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年买决,在試婚紗的時候發(fā)現(xiàn)自己被綠了沛婴。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡督赤,死狀恐怖嘁灯,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情躲舌,我是刑警寧澤丑婿,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響羹奉,放射性物質(zhì)發(fā)生泄漏秒旋。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一诀拭、第九天 我趴在偏房一處隱蔽的房頂上張望迁筛。 院中可真熱鬧,春花似錦耕挨、人聲如沸细卧。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽贪庙。三九已至,卻和暖如春赋铝,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背沽瘦。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工革骨, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人析恋。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓良哲,卻偏偏與公主長得像,于是被迫代替她去往敵國和親助隧。 傳聞我的和親對象是個殘疾皇子筑凫,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,601評論 2 353

推薦閱讀更多精彩內(nèi)容