pingcap / pingcap/tiflash

Improve the performance of `sum(int)` in TiFlash

Open
#9,764 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type/enhancement
Dominant language
C++
Stars
1k
Forks
423
Avg merge
1d 15h
Merged PRs (30d)
24

Description

Enhancement

Currently, in TiFlash the result type of sum(int) is bigint, and the result type of sum(decimal) is decimal, in TiDB/MySQL, sum(int) will return decimal. In order to make TiFlash compatible with TiDB/MySQL, the planner in TiDB add an implict cast of sum(int) when pushdown to TiFlash like
sum(cast(int as decimal)).(Note we can not add cast after sum like cast(sum(int) as decimal) because sum(int) may overflow.)

This brings an extra cost when calculating sum(int) in TiFlash, which may hurt the performance a little bit. Ideally, we should change the behavior of sum(int) in TiFLash so it can return decimal directly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating TiFlash's implementation of sum(int) and the planner path involved in the pushdown cast described in the issue. Compare the existing sum(int) and sum(decimal) behavior with TiDB/MySQL expectations, then verify that sum(int) returns decimal directly without overflow-related regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, mysql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.