Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6GZK-0000X4-PY for pgsql-performance@arkaria.postgresql.org; Wed, 21 Jul 2021 18:03:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m6GZJ-0004N6-LJ for pgsql-performance@arkaria.postgresql.org; Wed, 21 Jul 2021 18:03:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6GZJ-0004My-Ch for pgsql-performance@lists.postgresql.org; Wed, 21 Jul 2021 18:03:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m6GZF-0003OH-UH for pgsql-performance@lists.postgresql.org; Wed, 21 Jul 2021 18:03:41 +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 16LI3Z2a713203; Wed, 21 Jul 2021 14:03:36 -0400 From: Tom Lane To: "Dirschel, Steve" cc: "pgsql-performance@lists.postgresql.org" Subject: Re: Query Performance In-reply-to: References: Comments: In-reply-to "Dirschel, Steve" message dated "Wed, 21 Jul 2021 17:13:05 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <713201.1626890615.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 21 Jul 2021 14:03:35 -0400 Message-ID: <713202.1626890615@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Dirschel, Steve" writes: > I have a sample query that is doing more work if some of the reads are p= hysical reads and I'm trying to understand why. If you look at attached Q= ueryWithPhyReads.txt it shows the query did Buffers: shared hit=3D171 read= =3D880. So it did 171 + 880 =3D 1051 total block reads (some logical, som= e physical). QueryWithNoPhyReads.txt shows execution statistics of the ex= ecution of the exact same query with same data point. The only difference= is the first execution loaded blocks into memory so this execution had al= l shared hits. In this case the query did this much work: Buffers: share= d hit=3D581. You haven't provided a lot of context for this observation, but I can think of at least one explanation for the discrepancy. If the first query was the first access to these tables after a bunch of updates, it would have been visiting a lot of now-dead row versions. It would then have marked the corresponding index entries dead, resulting in the second execution not having to visit as many heap pages. regards, tom lane