diff --git a/utils/rowgroup/rowstorage.cpp b/utils/rowgroup/rowstorage.cpp index 558ba2759..c326dab9f 100644 --- a/utils/rowgroup/rowstorage.cpp +++ b/utils/rowgroup/rowstorage.cpp @@ -1666,6 +1666,8 @@ void RowAggStorage::dump() if (!fEnabledDiskAggregation) return; + constexpr const int freeMemLimit = 50ULL * 1024ULL * 1024ULL; + const int64_t leaveFree = fNumOfInputRGPerThread * fRowGroupOut->getRowSize() * getBucketSize(); uint64_t freeAttempts{0}; int64_t freeMem = 0; @@ -1698,6 +1700,10 @@ void RowAggStorage::dump() { startNewGeneration(); } + else if (fAllowGenerations && fMM->getFree() < freeMemLimit) + { + startNewGeneration(); + } else if (!fAllowGenerations && freeMem < 0 && freeAttempts == 1) { // safety guard so aggregation couldn't eat all available memory