pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.41k stars 5.85k forks source link

Separate signatures for PlusInt #13973

Open breezewish opened 4 years ago

breezewish commented 4 years ago

Description

Currently for the PlusInt built-in function, TiDB executes different logic according to whether LHS and RHS is signed or unsigned:

The actual logic is determined in func (b *builtinArithmeticPlusIntSig) vecEvalInt, i.e. re-checked every 1024 rows.

Meanwhile, at TiKV side, TiKV also does the same thing in the function signature mapper:

fn plus_mapper(lhs_is_unsigned: bool, rhs_is_unsigned: bool) -> RpnFnMeta {
    match (lhs_is_unsigned, rhs_is_unsigned) {
        (false, false) => arithmetic_fn_meta::<IntIntPlus>(),
        (false, true) => arithmetic_fn_meta::<IntUintPlus>(),
        (true, false) => arithmetic_fn_meta::<UintIntPlus>(),
        (true, true) => arithmetic_fn_meta::<UintUintPlus>(),
    }
}

A better way is to separate UU/US/SU/SS into different signatures at the planning stage instead of execution stage, i.e. func (c *arithmeticPlusFunctionClass) getFunction. A separation in getFunction can benefit both TiDB execution and TiKV execution, which can make the code simple, keep TiKV pure (no function deduction logic) and make execution slightly faster.

To finish this task, you need to:

  1. Modify tipb to introduce 4 new signatures, like:

    • builtinArithmeticPlusIntUnsignedUnsigned
    • builtinArithmeticPlusIntUnsignedSigned
    • ...

    (for compatibility consideration, builtinArithmeticPlusInt should be kept in tipb so that TiKV can still support old TiDB)

  2. Modify the func (c *arithmeticPlusFunctionClass) getFunction to introduce dispatch logic, dispatching to the new 4 signatures according to the operator's unsigned flag.

  3. Implement the new 4 function signature (and their vectorized version) by copying and refining code from the original function signature.

Optionally, you may consider modifying TiKV code base as well, to support these 4 newly added signatures. This will be in a separated task in TiKV side.

Difficulty

Score

Mentor(s)

Recommended Skills

ChiaoTeo commented 4 years ago

I am trying fix it

ChiaoTeo commented 4 years ago

/pick-up-challenge

sre-bot commented 4 years ago

@ZhaoQian888 pick up issue success

Tjianke commented 3 years ago

/pick-up-challenge #22026