Skip to content

Optimize Aggregator/Join/Set keys#6135

Merged
ti-chi-bot merged 22 commits intopingcap:masterfrom
solotzg:optimize-agg
Oct 29, 2022
Merged

Optimize Aggregator/Join/Set keys#6135
ti-chi-bot merged 22 commits intopingcap:masterfrom
solotzg:optimize-agg

Conversation

@solotzg
Copy link
Contributor

@solotzg solotzg commented Oct 14, 2022

What problem does this PR solve?

Issue Number: ref #5294

What is changed and how it works?

  • optimize agg with one string key
    • type: str-bin, str-bin-padding
    • struct AggregationMethodOneKeyStringNoCache
  • optimize agg with two keys
    • type: number-64-bytes, str-bin, str-bin-padding
    • struct AggregationMethodFastPathTwoKeysNoCache
  • AggregationMethodOneKeyStringNoCache and AggregationMethodFastPathTwoKeysNoCache will generate empty data for string column because such column will be discarded.
    • /** Deserializes a value that was serialized using IColumn::serializeValueIntoArena method.
      * Returns pointer to the position after the read data.
      * Note:
      * 1. For string columns with collation it is actually impossible to restore the value.
      * In this case, the column restored by this function is discarded, the compiler will add a
      * special aggregate function(any) as the group by column's output. For example:
      * select string_column, count(*) from table group by string_column
      * if string_column has collation information, the query will be rewrite to
      * select any(string_column), count(*) from table group by string_column
      * 2. The input parameter `collator` does not work well for complex columns(column tuple),
      * but it is only used by TiDB , which does not support complex columns, so just ignore
      * the complex column will be ok.
      */
      virtual const char * deserializeAndInsertFromArena(const char * pos, std::shared_ptr<TiDB::ITiDBCollator> collator = nullptr) = 0;
    • if (collator != nullptr)
      {
      /// if the column is a string with collation info, the `sort_key` of the column is used during
      /// aggregation, but we can not reconstruct the origin column by `sort_key`, so add an extra
      /// extra aggregation function any(group_by_column) here as the output of the group by column
      const String & agg_func_name = "any";
      AggregateDescription aggregate;
      DataTypes types(1);
      aggregate.argument_names.resize(1);
      types[0] = type;
      aggregate.argument_names[0] = name;
      String func_string = genFuncString(agg_func_name, aggregate.argument_names);
      bool duplicate = false;
      for (const auto & pre_agg : aggregate_descriptions)
      {
      if (pre_agg.column_name == func_string)
      {
      aggregated_columns.emplace_back(func_string, pre_agg.function->getReturnType());
      duplicate = true;
      break;
      }
      }
      if (duplicate)
      continue;
      aggregate.column_name = func_string;
      aggregate.parameters = Array();
      aggregate.function = AggregateFunctionFactory::instance().get(agg_func_name, types, {}, 0, false);
      aggregate.function->setCollator(getCollatorFromExpr(expr));
      aggregate_descriptions.push_back(aggregate);
      DataTypePtr result_type = aggregate.function->getReturnType();
      // this is a temp result since implicit cast maybe added on these aggregated_columns
      aggregated_columns.emplace_back(func_string, result_type);
      }
  • optimize ColumnString::deserializeAndInsertFromArena by same way above.

We may need JIT for further optimization about AGG/JOIN/SET later.

Benchmark

ENV

Time(s) Original Optimized Improvement: (Original) / (Optimized) - 1.0
ClickBench TiFlash x 1 TIFLASH-REPLICA 1
Q14 2.075 1.835 13.08%
Q15 1.21 1.155 4.76%
Q17 3.695 3.365 9.81%
Q18 2.925 2.805 4.28%
Q34 6.4 6.085 5.18%
Q35 6.575 6.28 4.70%
TPCH-100 TiFlash x 1 TIFLASH-REPLICA 1
Q1 7.28 7.08 2.82%

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 14, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker
  • zanmato1984

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 14, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 14, 2022

/rebuild

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 16, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 17, 2022
Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
@solotzg
Copy link
Contributor Author

solotzg commented Oct 21, 2022

/run-all-tests

Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
@solotzg
Copy link
Contributor Author

solotzg commented Oct 21, 2022

/run-all-tests

@solotzg
Copy link
Contributor Author

solotzg commented Oct 24, 2022

/run-all-tests

Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
@solotzg
Copy link
Contributor Author

solotzg commented Oct 25, 2022

/run-all-tests

Signed-off-by: Zhigao Tong <tongzhigao@pingcap.com>
@solotzg solotzg added type/enhancement The issue or PR belongs to an enhancement. type/performance labels Oct 26, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 28, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/run-sanitizer-test asan

@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 28, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

DetailsCommit hash: 4940a43

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 28, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/run-all-tests

@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/run-sanitizer-test asan

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Oct 28, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

DetailsCommit hash: 8105e41

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 28, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 28, 2022

/run-sanitizer-test asan tsan

@solotzg
Copy link
Contributor Author

solotzg commented Oct 29, 2022

/unhold

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 29, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Oct 29, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit 1a50e00 into pingcap:master Oct 29, 2022
@solotzg solotzg deleted the optimize-agg branch October 29, 2022 03:00
CalvinNeo pushed a commit to CalvinNeo/tiflash that referenced this pull request Nov 4, 2022
ref pingcap#5294

Signed-off-by: CalvinNeo <calvinneo1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement. type/performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants