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 1vx8xJ-00HXoA-37 for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2026 19:29:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vx8xH-002kIc-0P for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Mar 2026 19:29:23 +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 1vx8xG-002kIT-1B for pgsql-hackers@lists.postgresql.org; Mon, 02 Mar 2026 19:29:23 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vx8xD-0000000042u-3Gje for pgsql-hackers@lists.postgresql.org; Mon, 02 Mar 2026 19:29:22 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 4A4A61D0015C; Mon, 2 Mar 2026 14:29:18 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 02 Mar 2026 14:29:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1772479758; x=1772566158; bh=DNT7Wx2qBl Hx61SC5q88yfW23ROl2/i9VKuGgbJrYYo=; b=2AeO4YDSHKSuJSWMeTmCxWgxTP PXmrII6MFuekdg0zkUepjWBU6ZJUTS4Jj5sv/V3qaatrnMHZHnpuOIJtRM1DAWqt O82vOnniq94to+kLTHJAGmxOucMDfFKNe/+/RwAvbmw0AnNWZ/jaFPA96WanE3Vz N3JLZU0MfXqPuUVziLyaK87JJlrTBxcks2QLfZLgB+1HchJN2I8ilDYHueanphcO CX5EG2oHdGQGneRm83sxrbgX08BR31MN5cuuxNbj8h9FtAmAkCHbKLj1Aptontah Lk5KDExps+/cpBWis7gUed4br53zrXdTVr6L2Nzl+yIcZNatrF3R07qKHFYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1772479758; x=1772566158; bh=DNT7Wx2qBlHx61SC5q88yfW23ROl2/i9VKu GgbJrYYo=; b=FNAWIXu1K4pOfX+8XHV2eJRbDhO1lE6Es84vmcyVOSRR/xkzpTD 1TVdxGbZ40oUNKx+IlxkNi5WPUZPS6isvVlyihM+5w9cJhnqGB1yFp3PfiWDUPP9 KztRVfNoI6hccvmcfHNu11clk2imKK7FjKrCQG2cDJPrz+CyNX3fRjO//S5Z0Kol 2Pemw+7bMLjeHLIHJqHMLn77uSOvPRJ7SQBxcZu98TQiauf0EU2B01qraWe2Xai0 pPVO0tUm0mdWxS0RYgb5k9NdtSvtSv58+SEFLhHdZJAbahH0I74yF9BPkBqInvk8 rN3M+q0rKhzo/oImwG4uXdLVq1qK+bJlx/Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvheekhedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeduuddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepphhgsegsohifthdrihgvpdhrtghpthhtohepkh hnihiihhhnihhksehgrghrrhgvthdrrhhupdhrtghpthhtohepsgihrghvuhiikedusehg mhgrihhlrdgtohhmpdhrtghpthhtohepughilhhiphgsrghlrghuthesghhmrghilhdrtg homhdprhgtphhtthhopehmvghlrghnihgvphhlrghgvghmrghnsehgmhgrihhlrdgtohhm pdhrtghpthhtohepohdrrghlvgigrghnughrvgdrfhgvlhhiphgvsehgmhgrihhlrdgtoh hmpdhrtghpthhtoheprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomhdprhgtphht thhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopehpgh hsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Mar 2026 14:29:16 -0500 (EST) Date: Mon, 2 Mar 2026 14:29:16 -0500 From: Andres Freund To: Alexandre Felipe Cc: Tomas Vondra , Peter Geoghegan , Thomas Munro , Nazir Bilal Yavuz , Robert Haas , Melanie Plageman , PostgreSQL Hackers , Georgios , Konstantin Knizhnik , Dilip Kumar Subject: Re: index prefetching Message-ID: References: <7e707787-272a-4c52-b5f1-5ac990514ecc@vondra.me> <3cbwjhwkomjv7jifau4yhb357gfnckut3sdrlbmhwzesd3kngj@affs2mpxg4gh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-03-02 18:45:03 +0000, Alexandre Felipe wrote: > > Unfortunately that has too big a performance penalty for fully cached > > workloads :(. Doing buffer mapping lookups ahead of the current point is > not > > free. > > Could you elaborate? Looking ahead requires pinning those buffers (or you need to do more buffer lookups, which also isn't free). The way things work right now is that the infrastructure to maintain buffer pins gets more expensive the more buffers you pin. That increased overhead doesnt' matter much if you actually avoid IO or you have fair bit of work for each buffer (like looking at each tuple), but if you just are fully cached and just look at a single tuple, it's painful. CREATE TABLE uncorrelated(id int8 primary key, balance float not null); INSERT INTO uncorrelated(id, balance) SELECT id, 0 FROM (SELECT generate_series(1, 1000000) AS id) ORDER BY random(); VACUUM (FREEZE, ANALYZE) uncorrelated; CREATE TABLE correlated(id int8 primary key, balance float not null); INSERT INTO correlated(id, balance) SELECT id, 0 FROM (SELECT generate_series(1, 1000000) AS id); VACUUM (FREEZE, ANALYZE) correlated; SELECT pg_prewarm('uncorrelated'); SET max_parallel_workers_per_gather=0;SET enable_bitmapscan = 0;SET enable_seqscan = 0; SELECT sum(balance) FROM uncorrelated WHERE id > 1000 and id < 500000; SELECT pg_prewarm('correlated'); SET max_parallel_workers_per_gather=0;SET enable_bitmapscan = 0;SET enable_seqscan = 0; SELECT sum(balance) FROM correlated WHERE id > 1000 and id < 500000; Index prefetching patch: uncorrelated: 228.936 ms correlated: 71.684 ms + minimum distance 2: uncorrelated: 244.361 ms correlated: 71.848 ms + minimum distance 4: uncorrelated: 246.164 ms correlated: 71.912 ms + minimum distance 8: uncorrelated: 268.686 ms correlated: 71.880 ms + minimum distance 16: uncorrelated: 310.320 ms correlated: 71.890 ms + minimum distance 32: uncorrelated: 330.714 ms correlated: 74.178 ms There starts to be some overhead of the increased distance even when correlated, but it's small and starts much later. We probably can reduce the overhead of buffer tracking, but probably not enough for it to not be a factor at all. Possible improvements to refcount tracking: - increase REFCOUNT_ARRAY_ENTRIES - there's a very significant cliff at 8 right now, and with vectorized lookup it might not hurt too much to go to 16 or so - To make the cliff at REFCOUNT_ARRAY_ENTRIES smaller, replace dynahash with simplehash. That should reduce the perf penalty a good bit. Unfortunately it's not just the refcount tracking, it's also resowner management that gets more expensive. Greetings, Andres Freund