Skip to content

Commit

Permalink
Internal duckdb#3381: Window Race Condition
Browse files Browse the repository at this point in the history
Multiple threads setting the same global value need a mutex.
  • Loading branch information
hawkfish committed Oct 28, 2024
1 parent b83a0be commit d751f51
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/execution/window_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,15 @@ class WindowValueGlobalState : public WindowExecutorGlobalState {
child_idx(executor.child_idx) {
}

void Finalize(CollectionPtr collection) {
if (child_idx != DConstants::INVALID_INDEX && executor.wexpr.ignore_nulls) {
lock_guard<mutex> ingore_nulls_guard(lock);
ignore_nulls = &collection->validities[child_idx];
}
}

// IGNORE NULLS
mutex lock;
ValidityMask all_valid;
optional_ptr<ValidityMask> ignore_nulls;

Expand Down Expand Up @@ -1877,10 +1885,8 @@ unique_ptr<WindowExecutorGlobalState> WindowValueExecutor::GetGlobalState(const

void WindowValueExecutor::Finalize(WindowExecutorGlobalState &gstate, WindowExecutorLocalState &lstate,
CollectionPtr collection) const {
if (child_idx != DConstants::INVALID_INDEX && wexpr.ignore_nulls) {
auto &gvstate = gstate.Cast<WindowValueGlobalState>();
gvstate.ignore_nulls = &collection->validities[child_idx];
}
auto &gvstate = gstate.Cast<WindowValueGlobalState>();
gvstate.Finalize(collection);

WindowExecutor::Finalize(gstate, lstate, collection);
}
Expand Down

0 comments on commit d751f51

Please sign in to comment.