Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsS6I-001ocZ-2t for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 20:55:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vsS6F-00C4Dy-33 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Feb 2026 20:55:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vsS6F-00C4Dj-1m for pgsql-hackers@lists.postgresql.org; Tue, 17 Feb 2026 20:55:15 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vsS6D-00000001Fpx-0244 for pgsql-hackers@lists.postgresql.org; Tue, 17 Feb 2026 20:55:15 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 635AF443F2; Tue, 17 Feb 2026 20:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1771361711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2FYyygjSvghHyq73oiy76RBvQI/TmYnzlup9/VNDqjI=; b=S50mkNI4oSaAkEo24B2Vp7CL9hUfcmOAgNwlz83SqX2gHv5WZWE+UersHeMFJfIOqwL55H H+lV0W+aiHxBZiC5I3xhO1farE6vFZumDeqa0oO4e8NjSuiDTw53/gkN55TJajsrbzExUy RosOgr+z28BfZM2GrHuZ0lah3/fv6dDTbz2/SCgYWu3tkrfzYhpgeblCPjB25D+3PpJz9Y W5IsJmJDWLwGlLTS3waF+mR18FfjzErOOhSZjYVVuXXTcyt4AniVSvsQN2shnPob4G9Gu3 6Bbngbt0o+JSiGBCn/+ZZQ7Ux7Pi9v4R3uAISzIF5U753HBg2qB7rq6qPNjl9A== Message-ID: <76579da6-ca00-4486-8d9f-4032e510edbe@vondra.me> Date: Tue, 17 Feb 2026 21:55:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: index prefetching To: Peter Geoghegan Cc: Andres Freund , Alexandre Felipe , Thomas Munro , Nazir Bilal Yavuz , Robert Haas , Melanie Plageman , PostgreSQL Hackers , Georgios , Konstantin Knizhnik , Dilip Kumar References: <9411f220-007d-4f1e-9c8f-ca8eb09e6788@vondra.me> <984dcf9e-ada0-4dff-ae58-1f97bc904ccb@vondra.me> <7herwtpae3ptqdng3s7tcft4ljkc23fyocp3mbrvc7xyk7s2lk@uq3qbm4blizo> <433c7359-3c5d-4fe3-a488-93a17f44d0bf@vondra.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: tomas@vondra.me X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvddtjeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomhepvfhomhgrshcugghonhgurhgruceothhomhgrshesvhhonhgurhgrrdhmvgeqnecuggftrfgrthhtvghrnhepuedvvdeifefffeekudeggfdtieeglefggeduheffveeihefggfehgfdvudetffevnecukfhppeekiedrgeelrddvfedtrddvtdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeeirdegledrvdeftddrvddtiedphhgvlhhopegluddtrddufeejrddtrddvngdpmhgrihhlfhhrohhmpehtohhmrghssehvohhnughrrgdrmhgvpdhqihgupeeifeehtefhgeegfefhvddpmhhouggvpehsmhhtphhouhhtpdhnsggprhgtphhtthhopeduuddprhgtphhtthhopehpghessghofihtrdhivgdprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtthhopehorghlvgigrghnughrvghfvghlihhpvgesghhmrghilhdrtghomhdprhgtphhtthhopehthhhomhgrshhmuhhnrhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhmpdhrtghpthhto heprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomh X-GND-State: clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/17/26 19:17, Peter Geoghegan wrote: > On Mon, Feb 16, 2026 at 10:44 AM Tomas Vondra wrote: >> I've described this exact behavior a couple months ago in this very >> thread. The queue of batches has limited size, the prefetch needs to be >> paused - at that point read_stream_pause did not exist, so it was done >> by terminating the stream and then read_stream_reset to "resume" it. >> >> That has the unfortunate effect that it resets distance to 1, and so it >> easily led exactly to the issue you describe. But without the pausing it >> would work perfectly fine, in many cases. > > Just to be clear: it *used* to work that way, back when we weren't > using Thomas Munro's built-in pausing mechanism. Because we'd actually > reset the read stream back then, as a workaround for the lack of any > built-in pausing mechanism. But we don't do that anymore; recent > versions only reset in cases where it's strictly necessary, such as on > a rescan, or when the scan direction changes. > > Recent versions of the patch are just about impossible to make pause. > Because (for better or worse) we'll yield before ever running out of > batch slots/before ever pausing. Andres has shown that this can be > detrimental to our ability to maintain an adequate prefetch distance. > But that's likely only because pausing hurts when it prevents us from > aggressively ramping up prefetch distance at the start of the scan. > > Even without yielding, pausing is rare and likely doesn't hurt us > much. After all, 64 batches is usually plenty. > >> With the resetting, this effect is pretty brutal. > > What resetting? We don't do that anymore? And even back when the patch > did things that way, we made sure to save the old prefetch distance > (which was a kludge upon a kludge)? > > Basically I'm confused about why you're now talking about how the > patch worked months ago, which was always a temporary workaround to > deal with the lack of a built-in pausing mechanism. All of our current > problems are due to yielding (not pausing), and/or issues on the read > stream side. > Yes, the patch no longer resets the stream like this. I was responding to Andres, explaining that we saw basically the same issue, with the twist that the impact strongly depends on the distance value at the moment we hit the particular hit/miss pattern. We no longer have that issue (with the "read_stream_reset" forcing the distance collapse). We still have the issue with decaying too early in some cases, depending on the exact pattern of hits/misses. Sorry if that wasn't clear. -- Tomas Vondra