Skip to content

Commit

Permalink
fix assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Sep 2, 2024
1 parent 1e3b306 commit 00229e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/storage/temporary_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem
sum_of_initial_res += initial_reservation;
if (RefersToSameObject(state.get(), temporary_memory_state)) {
state_index = i;
} else if (state.get().GetReservation() >= state.get().GetRemainingSize()) {
} else if (initial_reservation >= state.get().GetRemainingSize()) {
continue;
}
states.emplace_back(state);
Expand All @@ -247,6 +247,7 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem
idx_t remaining_memory = free_memory;
const idx_t optimization_iterations = OPTIMIZATION_ITERATIONS_MULTIPLIER * n;
for (idx_t opt_idx = 0; opt_idx < optimization_iterations; opt_idx++) {
D_ASSERT(remaining_memory != 0);
ComputeDerivatives(states, res, der, n);

// Find the index of the state with the lowest derivative
Expand All @@ -267,12 +268,12 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem
// Compute how much we can add
const auto state_room = min_state.GetRemainingSize() - res[min_idx];
const auto delta = MinValue(iter_memory, state_room);
D_ASSERT(delta <= remaining_memory);

// Update counts
res[min_idx] += delta;
remaining_memory -= delta;
}
D_ASSERT(remaining_memory == 0);

// We computed how the memory should be assigned to the states,
// but we did not yet take into account the upper bound of MAXIMUM_FREE_MEMORY_RATIO * free_memory.
Expand All @@ -294,7 +295,7 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem
remaining_memory = free_memory;
for (const auto idx : idxs) {
auto &state = states[idx].get();
D_ASSERT(state.GetReservation() < state.GetRemainingSize());
D_ASSERT(state.GetReservation() <= state.GetRemainingSize());
const auto initial_state_reservation = ComputeInitialReservation(state);
const auto upper_bound = LossyNumericCast<idx_t>(
MAXIMUM_FREE_MEMORY_RATIO * static_cast<double>(initial_state_reservation + remaining_memory));
Expand Down
2 changes: 1 addition & 1 deletion test/sql/join/external/many_external_joins.test_slow
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SET memory_limit='500mb';

# disable the join order optimizer to be sure we probe all HTs in a single pipeline
statement ok
SET disabled_optimizers TO 'join_order';
SET disabled_optimizers TO 'join_order,build_side_probe_side';

# we shouldn't run out of memory
query IIIII
Expand Down

0 comments on commit 00229e1

Please sign in to comment.