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.94.2) (envelope-from ) id 1vCHK6-00BYFW-OE for pgsql-general@arkaria.postgresql.org; Fri, 24 Oct 2025 12:55:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vCHJ6-00GHaR-L2 for pgsql-general@arkaria.postgresql.org; Fri, 24 Oct 2025 12:54:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vCHJ6-00GHaI-9x for pgsql-general@lists.postgresql.org; Fri, 24 Oct 2025 12:54:11 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vCHJ3-003XcN-1u for pgsql-general@lists.postgresql.org; Fri, 24 Oct 2025 12:54:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 59OCs6aB1754334; Fri, 24 Oct 2025 08:54:06 -0400 From: Tom Lane To: depesz@depesz.com cc: PostgreSQL General Subject: Re: Why is this query touching 4gb of buffers? In-reply-to: References: Comments: In-reply-to hubert depesz lubaczewski message dated "Fri, 24 Oct 2025 13:19:03 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1754332.1761310446.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 24 Oct 2025 08:54:06 -0400 Message-ID: <1754333.1761310446@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk hubert depesz lubaczewski writes: > First run of the query generated: > ... > -> Index Scan using index_some_table_pending on some_table (cost=3D= 0.42..178322.57 rows=3D611988 width=3D16) (actual time=3D27962.567..27962.= 567 rows=3D0 loops=3D1) > Index Cond: (send_at <=3D '2025-10-23 12:35:48'::timestamp with= out time zone) > Buffers: shared hit=3D4624 read=3D117838 dirtied=3D486 > Then, immediately I reran it, without reindex, without analyze, without = anything. And I got: > -> Index Scan using index_some_table_pending on some_table (cost=3D= 0.42..178328.27 rows=3D612009 width=3D16) (actual time=3D0.438..0.438 rows= =3D0 loops=3D1) > Index Cond: (send_at <=3D '2025-10-23 12:35:48'::timestamp with= out time zone) > Buffers: shared hit=3D424 > Time is irrelevant, the point is that we are going down from ~120k buffe= rs > "touched" to 424 buffers. What is going on? The first execution probably had to set hint bits on a whole lot of recently-deleted rows. regards, tom lane