Repository navigation
Bugfixes and performance improvements for parallel_hash - #37648
Conversation
|
I've observed significant slowdown when testing ssb 100g. |
|
@amosbird Do you have the sql to create table |
CREATE TABLE ssb.date
(
`D_DATEKEY` Date,
`D_DATE` String,
`D_DAYOFWEEK` String,
`D_MONTH` String,
`D_YEAR` Int32,
`D_YEARMONTHNUM` Int32,
`D_YEARMONTH` String,
`D_DAYNUMINWEEK` Int32,
`D_DAYNUMINMONTH` Int32,
`D_DAYNUMINYEAR` Int32,
`D_MONTHNUMINYEAR` Int32,
`D_WEEKNUMINYEAR` Int32,
`D_SELLINGSEASON` String,
`D_LASTDAYINWEEKFL` Int32,
`D_LASTDAYINMONTHFL` Int32,
`D_HOLIDAYFL` Int32,
`D_WEEKDAYFL` Int32
)
ENGINE = MergeTree
ORDER BY D_DATEKEY |
|
I observe that the right table is small. In this case, the overhead of dispatch blocks is high |
07425fe to
46d4378
Compare
|
Slow down may happen if we select lots of columns from left table, because it'll dispatch (call |
baca388 to
3e0fe1a
Compare
|
I think I discovered a rather subtle bug while working on the related code at #38191. The bug was introduced in d712985 with transition from SipHash to WeakHash32 for sharding: the hash tables within buckets use the last bits of CRC32 as hash value as well. Thus, the distribution of hash values within each bucket is skewed, the number of collisions increases significantly, and the performance of hash tables degrades. |
79cef15 to
68b30fb
Compare
|
I decided not to set it as a default for now, but running this algorithm on a complete test set helped to find some bugs and fix them. |
c8602a5 to
1bd334e
Compare
There was a problem hiding this comment.
do we have trace like in aggregator to see how data were distributed in actuality?
There was a problem hiding this comment.
I don't know about such thing, but it would be good to see this information.
I've made this change after @BigRedEye comment. I've checked on simple synthetic case and it was actually ~20% faster.
Just because lots of tests were changed and timeout doesn't adjust to the time required to run all of them
Looks suspicious |
a54254f to
d636674
Compare
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
ConcurrentHashJoin scatters right-side blocks by hashing the equality key, so rows with the same equality key always land in the same internal HashJoin partition. The per-key SortedLookupVector that backs ASOF lives entirely within that partition, so the parallel build behaves the same way as for non-ASOF strictness. The exclusion in allowParallelHashJoin appears to be defensive carryover from the original ConcurrentHashJoin PR (ClickHouse#37648, April 2022) — it shipped with the gate in place from day one with no rationale in the source or PR text, and ConcurrentHashJoin itself contains zero ASOF-specific code paths or assertions. For workloads where the ASOF equality key has low cardinality (e.g. SQL generated by visualization tools that compute multi-channel derived metrics like vector magnitude sqrt(x^2 + y^2 + z^2) and use a constant equality predicate to satisfy ASOF's syntactic requirement), this unblocks parallelism on the build phase: e.g. one of our workloads goes from ~93s wall (single-core build of a 250M-row hash table x 2 stacked ASOF joins) toward what the existing manual UNION-ALL time-shard workaround achieves (~25s with 4x CPU utilisation), per ClickHouse#73086. Adds a regression test that runs the same ASOF INNER and ASOF LEFT queries under both join_algorithm = 'hash' and 'parallel_hash' and checks per-row identity via mutual EXCEPT.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
parallel_hash