Repository navigation
Conversation
|
Workflow [PR], commit [84e78c8] Summary: ✅
AI ReviewSummaryThis PR replaces locked aggregation of Findings
Tests
Final VerdictStatus: Minimum required action: fix the spill-threshold accounting so |
| std::lock_guard lock(hash_join->mutex); | ||
| res += hash_join->data->getTotalByteCount(); | ||
| } | ||
| res += hash_join->total_bytes.load(std::memory_order_relaxed); |
There was a problem hiding this comment.
SpillingHashJoin still uses ConcurrentHashJoin::getTotalByteCount as the pre-insert spill gate, but this now returns only the last completed snapshot for each slot. While another thread holds a slot mutex inside ConcurrentHashJoin::addBlockToJoin, that slot's inner HashJoin may already have grown but total_bytes is not stored until after the insert returns, so this load can undercount exactly when the wrapper decides whether to switch to GraceHashJoin. The old implementation waited on the slot mutex and observed the completed insert before making that decision. With max_bytes_before_external_join, a concurrent inserter can miss the half-threshold trigger and later promote the join in memory if the final total stays below the full cap. Please keep an exact/locking path for the spill decision or account for in-flight bytes before inserting.
There was a problem hiding this comment.
Couldn't this still happen with the old implementation? Multiple threads could perform ConcurrentHashJoin::getTotalByteCount, see a pre-insert counters, then start inserting concurrently?
There was a problem hiding this comment.
Yes, the old code could still miss a group of callers that all completed the pre-insert check before any of them started inserting. The difference is that the old getTotalByteCount then blocked on any slot already being mutated and observed that completed insert before deciding whether to switch; with the cached value, a caller can start its check after another thread has already grown a slot and still read the previous snapshot until that insert returns and stores total_bytes.
There was a problem hiding this comment.
wouldn't the worst case be the same? before we missed blocks that did not yet start insert, now we miss blocks that have not yet finished insert, but the same blocks could be in either state
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 25/26 (96.15%) · Uncovered code |
antaljanosbenjamin
left a comment
There was a problem hiding this comment.
I think this should be fine. In a perfect world temporary overshoot of memory is not acceptable, but as we already had the chance to overshoot I think it would be a mistake to block this PR because of that.
c575978
…ion-in-concurrent-hash-join Reduce lock-contention from getTotalByteCount in ConcurrentHashJoin
getTotalByteCount(andgetTotalRowCount) in ConcurrentHashJoin loop over all HashJoin instances and lock them to extract the total. This leads to high lock contention when such a function is called frequently (this is the case for SpillingHashJoin that checks the byte limit on each block).The contention can add a lot of overhead and make queries flaky.
For query 9 from TPC-H at sf100 for 7 queries runtime (warm) fluctuates between 2690ms and 2966ms (


getTotalByteCounttaking between 164ms and 347ms).This change records the current totals of each hash join instance during insert while the lock is already held and makes
getTotalByteCount(andgetTotalRowCount) lock-free.TPC-H q9 runtime improves to 2.4~2.5ms

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reduce the overhead coming from lock-contention in
parallel_hashjoin algorithm.Version info
26.7.1.474(included in26.7and later)