Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregator support prefetch #9679

Merged
merged 67 commits into from
Jan 17, 2025
Merged

Conversation

guo-shaoge
Copy link
Contributor

@guo-shaoge guo-shaoge commented Nov 28, 2024

What problem does this PR solve?

Issue Number: close #9680

Problem Summary:

What is changed and how it works?

  1. Support prefetch for HashTable. This PR mainly works for key32/key64/key128/key256, and it doesn't affect key_string/key_serialized

Benchmark

Workloads: TPCH-50G
Queries:

 # --q0 Q1-1: key_int64; distinct rate: 10M/300M; HashMap
  "select /*+ mpp_1phase_agg() */ sum(l_quantity) as csum, l_partkey from lineitem group by l_partkey having csum < 200;"
  # --q1 Q1-2: key_int64; 75M/300M; HashMp
  "select /*+ mpp_1phase_agg() */ sum(l_quantity) as csum, l_orderkey from lineitem group by  L_orderkey having csum < 1;"
  # --q2 Q1-3: key_int64; 7/300M; HashMap
  "select /*+ mpp_1phase_agg() */ sum(l_quantity), l_linenumber from lineitem group by  l_linenumber;"

  # --q3 Q2-1: one_key_strbinpadding; 2/300M; StringHashMap
  "select /*+ mpp_1phase_agg() */ sum(l_discount), l_linestatus from lineitem group by l_linestatus;"
  # --q4 Q2-2: one_key_strbinpadding; 104M/300M; StringHashMap
  "select /*+ mpp_1phase_agg() */ sum(l_discount) as csum from lineitem group by l_comment having csum > 800;"

  # --q5 Q3-1: key_serialized as group by method;  33/300M; HashMap with StringRef key
  "select /*+ mpp_1phase_agg() */ sum(l_discount), l_returnflag from lineitem group by l_returnflag, l_discount;"
  # --q6 Q3-2: key_serialized as group by method; 77M/300M; HashMap with StringRef key
  "select /*+ mpp_1phase_agg() */ sum(l_discount) as csum, l_returnflag from lineitem group by l_returnflag, l_discount, l_extendedprice having csum > 100;"


  # --q7 Q4-1: two_keys_num64_strbinpadding: 21/300M; HashMap with StringRef key
  "select /*+ mpp_1phase_agg() */ sum(l_discount) from lineitem group by l_returnflag, L_LINENUMBER;"
  # --q8 Q4-2: two_keys_num64_strbinpadding; 29.9M/300M; HashMap with StringRef key
  "select /*+ mpp_1phase_agg() */ sum(l_discount) as csum, l_partkey from lineitem group by l_returnflag, l_partkey having csum > 100;"

  # --q9 Q5-1: keys_128; 77/300M; HashMap with UInt128 key
  "select /*+ mpp_1phase_agg() */ sum(l_linenumber), l_discount from lineitem group by l_linenumber, l_discount;"
  # --q10 Q5-2: keys_128; 5M/300M; HashMap with UInt128 key
  "select /*+ mpp_1phase_agg() */ sum(l_linenumber) as csum, l_discount from lineitem group by l_suppkey, l_discount having csum > 800;"

  # --q11 Q6-1: key_string; 4/300M; StringHashMap
   "select /*+ mpp_1phase_agg() */ sum(l_quantity), l_shipinstruct from lineitem group by l_shipinstruct;"

  # --q12 Q7-1: keys_256; 290M/300M; HashMap;
  "select /*+ mpp_1phase_agg() */ sum(l_suppkey) as csum from lineitem group by l_suppkey, l_tax, l_discount, l_partkey having csum = 10;"

  # --q13 clickbench Q4
  "select count(distinct userid) from clickbench.hits;"

ENV:

  1. Internal benchbot env
  2. 1 tidb; 2 tikv; 1 PD; 2 tiflash(16C64G, amd64)

Results (google excel):

idx query name nightly-b16a5f93 opt rate-opt
0 Q1-1 2.82 1.91 32.27%
1 Q1-2 2.15 1.71 20.47%
2 Q1-3 1.44 1.46 -1.39%
9 Q5-1 1.47 1.43 2.72%
10 Q5-2 4.16 3.63 12.74%
12 Q7-1 13.3 10.4 21.80%
13 clickbench Q4 0.46 0.4 13.04%

NOTE:

  1. infos:
    1.1 Query duration is in seconds
    1.2 baseline: nightly-b16a5f93; rate-opt2: (baseline - opt2)/baseline
  2. Queries like Q2-x/Q3-x are not listed because they are key_stirng/key_serialized, this PR only works for key_int64/key_int128/key_int256...). So these queries should not be affected.
  3. opt means(this is the final improvement of this PR)
    1. prefetch HashTable
    2. prefetch threshold be 2MB in byte instead of 8192 buckets
    3. prefetch when insertResultInto columns
    4. prefetch aggregation data for already exists key in HashTable
    5. mini batch(step is 256 for now) when emplace HashTable
  4. ClickBench Q4 is from: SELECT COUNT(DISTINCT UserID) FROM hits; https://github.com/ClickHouse/ClickBench/blob/main/mysql/queries.sql

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: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue 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. and removed do-not-merge/needs-linked-issue labels Nov 28, 2024
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
@guo-shaoge guo-shaoge changed the title Aggregator support prefetch Aggregator support prefetch and new hasher Dec 2, 2024
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
@guo-shaoge
Copy link
Contributor Author

/retest

Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
This reverts commit 3e30f95.
Signed-off-by: guo-shaoge <[email protected]>
This reverts commit 16937ff.
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
dbms/src/Interpreters/Aggregator.cpp Show resolved Hide resolved
Comment on lines +62 to +64
Mapped * value = nullptr;
Mapped * cached_value = nullptr;
bool inserted = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What specific issue does this change address?

Copy link
Contributor Author

@guo-shaoge guo-shaoge Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emplace_result_holder (std::optional< EmplaceResult >) needs copy assign operator

@guo-shaoge guo-shaoge requested a review from gengliqi January 9, 2025 09:46
dbms/src/Interpreters/Aggregator.cpp Outdated Show resolved Hide resolved
}
else
{
emplace_result.setMapped(place);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it save to push the fake address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment like clickhouse dose before auto * place = reinterpret_cast<AggregateDataPtr>(0x1);?

Signed-off-by: guo-shaoge <[email protected]>
@guo-shaoge guo-shaoge requested a review from windtalker January 12, 2025 04:16
@guo-shaoge
Copy link
Contributor Author

/retest

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 14, 2025
Copy link
Contributor

@gengliqi gengliqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

}
else
{
emplace_result.setMapped(place);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment like clickhouse dose before auto * place = reinterpret_cast<AggregateDataPtr>(0x1);?

dbms/src/Interpreters/Aggregator.cpp Outdated Show resolved Hide resolved
dbms/src/Interpreters/Aggregator.h Outdated Show resolved Hide resolved
dbms/src/Interpreters/Aggregator.h Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 17, 2025
Copy link
Contributor

ti-chi-bot bot commented Jan 17, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, windtalker

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [gengliqi,windtalker]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

ti-chi-bot bot commented Jan 17, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-01-14 03:49:31.540669471 +0000 UTC m=+4042.995715622: ☑️ agreed by windtalker.
  • 2025-01-17 05:21:16.369611382 +0000 UTC m=+268747.824657531: ☑️ agreed by gengliqi.

@gengliqi
Copy link
Contributor

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 17, 2025
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
Signed-off-by: guo-shaoge <[email protected]>
@guo-shaoge guo-shaoge removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 17, 2025
@ti-chi-bot ti-chi-bot bot merged commit 999018c into pingcap:master Jan 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregator support prefetch
3 participants