Repository navigation
Conversation
|
Workflow [PR], commit [acaf36f] Summary: ✅
AI ReviewSummaryThis PR adds a row-major payload layout for hash joins together with a match-feedback heuristic that tries to reuse previous executions when deciding whether the layout is worth building. The Findings
Tests
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 1050/1132 (92.76%) · Uncovered code |
|
This was fixed by #105146. Let's update the branch. |
|
@m-selmi |
@harikrishnan94 Thanks for taking a look. Right now it at least keeps the same memory footprint as separate columns, but that's a very good point, I can try it out. |
| <!-- Unique keys + non-nullable payload --> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_100k r ON (l.k % toUInt64(100000 / {match_rate})) = r.k FORMAT Null</query> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_10m r ON (l.k % toUInt64(10000000 / {match_rate})) = r.k FORMAT Null</query> | ||
|
|
||
| <!-- Unique keys + nullable payload --> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_100k_nullable r ON (l.k % toUInt64(100000 / {match_rate})) = r.k FORMAT Null</query> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_10m_nullable r ON (l.k % toUInt64(10000000 / {match_rate})) = r.k FORMAT Null</query> | ||
| <query>SELECT * FROM rs_probe_100m l FULL JOIN rs_right_10m r ON (l.k % toUInt64(10000000 / {match_rate})) = r.k FORMAT Null</query> | ||
|
|
||
| <!-- 10 matches per key + non-nullable payload --> | ||
| <query>SELECT * FROM (SELECT * FROM rs_probe_100m LIMIT 20000000) l JOIN rs_right_1m_x10 r ON (l.k % toUInt64(1000000 / {match_rate})) = r.k FORMAT Null</query> | ||
|
|
||
| <!-- 10 matches per key + nullable payload --> | ||
| <query>SELECT * FROM (SELECT * FROM rs_probe_100m LIMIT 20000000) l JOIN rs_right_1m_nullable_x10 r ON (l.k % toUInt64(1000000 / {match_rate})) = r.k FORMAT Null</query> | ||
|
|
||
| <!-- Mix of fixed sized and String columns --> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_mixed_10m r ON (l.k % toUInt64(10000000 / {match_rate})) = r.k FORMAT Null</query> | ||
|
|
||
| <!-- Wide build columns results in large blocks --> | ||
| <query>SELECT * FROM rs_probe_100m l JOIN rs_right_wide_10m r ON (l.k % toUInt64(10000000 / {match_rate})) = r.k FORMAT Null SETTINGS max_bytes_before_external_join = 0, max_bytes_ratio_before_external_join = 0</query> |
There was a problem hiding this comment.
These benchmark queries no longer force the row-store path on, but this PR is still claiming a Performance Improvement and PlannerJoins.cpp only enables the optimization when it has either min_rows_ratio_for_hash_join_row_store = 0 or a usable result_rows_estimation / cached match hint. As written, a future planner or statistics change can silently make this suite benchmark the preexisting columnar path instead of the new layout. Please pin the feature on here (for example with enable_hash_join_row_store = 1, min_rows_ratio_for_hash_join_row_store = 0) or otherwise assert that the measured queries actually initialized the row store.
Resolves #97883
Introduce an alternative layout for hash table payload in hash joins, where fixed and contiguous columns under a certain size are transformed into one row-major block of data.
Before the change:
After the change:
Rational:
The row-major format allows the output construction to be a tight loop over each column, basically one pointer load and data copy:
In comparison the columnar version has to do more work: load columns[j], row_numbers[j], replicated_columns access, insertFrom ...
For the following query
SELECT * FROM rs_probe_200m l JOIN rs_right_10m r ON (l.k % toUInt64(10000000 / 0.9)) = r.k FORMAT Nullfrom04054_hash_join_with_row_store.sqlthe perf counters forLazyOutput::buildOutputinAddedColumnslook as follows:Changes:
RowDataStorethat takes a set of columns and lays them in row major format. It exposes access to individual rows and the layout of each row (offset and size of fields in a row).IColumninterfaces that handle building the output columns from the row store, used manly byAddedColumns.cpp.Limitations:
Supporting non fixed rows would make the row-major layout non-uniform between rows and output column construction loop would not be as tight anymore. Also transforming unbounded unfixed types to row major could be very heavy.
Build overhead:
Benchmarks:
Experiments used for parameter tunning:
Absolute runtime diff:
Relative speedup:
TPC-H and TPC-DS:
At sf100, they were unaffected by the row store. There are multiple factors: build sides quite small, runtime filters pruning probe sides and another important factor: sort order. The tables are usually sorted/clustered on the join keys so cache locality is already good.
Effect of sort order and no runtime filters (left join):
from
04054_hash_join_with_row_store.sql:Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Introduce an alternative layout for hash table payload in hash joins, where qualifying columns are transformed into one row-major block of data in order to speed up join output reconstruction. Controlled by two new settings:
enable_hash_join_row_store(default true) andmin_rows_ratio_for_hash_join_row_store(default 5, the minimum estimated ratio of join output rows to build-side rows to enable the transformation).Workflow [PR]
Sync PR [sync-upstream/pr/104884]