From 1d1cec71c0144780f7d15b4778186a12bf155bf2 Mon Sep 17 00:00:00 2001 From: Leonid Krugliak Date: Sun, 10 May 2026 12:17:44 +0300 Subject: [PATCH] Fix eviction queue Purge() loop running excessive iterations on counter underflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When total_dead_nodes underflows (decremented more than incremented due to accounting mismatch), the wrapped unsigned value is always greater than approx_q_size. The old code clamped it to approx_q_size, making approx_alive_nodes=0, which prevented condition 2.2 from ever triggering. This caused the loop to run all max_purges iterations unnecessarily. Fix: if approx_dead_nodes > approx_q_size, break immediately — the counter is unreliable and there is no meaningful dead node pressure to address. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/storage/buffer/buffer_pool.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/storage/buffer/buffer_pool.cpp b/src/storage/buffer/buffer_pool.cpp index 104d3fba62eb..c38074836756 100644 --- a/src/storage/buffer/buffer_pool.cpp +++ b/src/storage/buffer/buffer_pool.cpp @@ -203,7 +203,9 @@ void EvictionQueue::Purge() { } idx_t approx_dead_nodes = total_dead_nodes; - approx_dead_nodes = approx_dead_nodes > approx_q_size ? approx_q_size : approx_dead_nodes; + if (approx_dead_nodes > approx_q_size) { + break; + } idx_t approx_alive_nodes = approx_q_size - approx_dead_nodes; // early-out according to (2.2)