diff --git a/src/Common/OvercommitTracker.cpp b/src/Common/OvercommitTracker.cpp index 63cd069fa15..7ac74e761db 100644 --- a/src/Common/OvercommitTracker.cpp +++ b/src/Common/OvercommitTracker.cpp @@ -66,7 +66,11 @@ void UserOvercommitTracker::pickQueryToExcludeImpl() { if (query.second->isKilled()) continue; + auto * memory_tracker = query.second->getMemoryTracker(); + if (!memory_tracker) + continue; + auto ratio = memory_tracker->getOvercommitRatio(); LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit); if (ratio.soft_limit != 0 && current_ratio < ratio) @@ -96,6 +100,8 @@ void GlobalOvercommitTracker::pickQueryToExcludeImpl() return; auto * memory_tracker = query.getMemoryTracker(); + if (!memory_tracker) + return; auto ratio = memory_tracker->getOvercommitRatio(user_soft_limit); LOG_DEBUG(logger, "Query has ratio {}/{}", ratio.committed, ratio.soft_limit); if (current_ratio < ratio) diff --git a/src/Interpreters/ProcessList.cpp b/src/Interpreters/ProcessList.cpp index f27406c92b4..a5465223b51 100644 --- a/src/Interpreters/ProcessList.cpp +++ b/src/Interpreters/ProcessList.cpp @@ -309,11 +309,13 @@ QueryStatus::~QueryStatus() { assert(executors.empty()); - auto * memory_tracker = getMemoryTracker(); - if (user_process_list) - user_process_list->user_overcommit_tracker.unsubscribe(memory_tracker); - if (auto shared_context = getContext()) - shared_context->getGlobalOvercommitTracker()->unsubscribe(memory_tracker); + if (auto * memory_tracker = getMemoryTracker()) + { + if (user_process_list) + user_process_list->user_overcommit_tracker.unsubscribe(memory_tracker); + if (auto shared_context = getContext()) + shared_context->getGlobalOvercommitTracker()->unsubscribe(memory_tracker); + } } CancellationCode QueryStatus::cancelQuery(bool) diff --git a/src/Interpreters/ProcessList.h b/src/Interpreters/ProcessList.h index ec3bb93b8d9..b1a9da314c6 100644 --- a/src/Interpreters/ProcessList.h +++ b/src/Interpreters/ProcessList.h @@ -149,6 +149,8 @@ public: MemoryTracker * getMemoryTracker() const { + if (!thread_group) + return nullptr; return &thread_group->memory_tracker; }