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 1ow8Ss-00016d-AK for pgsql-general@arkaria.postgresql.org; Fri, 18 Nov 2022 20:59:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ow8Sq-0001Bd-JW for pgsql-general@arkaria.postgresql.org; Fri, 18 Nov 2022 20:59:56 +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 1ow8Sq-0001BU-82 for pgsql-general@lists.postgresql.org; Fri, 18 Nov 2022 20:59:56 +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 1ow8So-0002Pr-5M for pgsql-general@lists.postgresql.org; Fri, 18 Nov 2022 20:59:55 +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 2AIKxkBO2267926; Fri, 18 Nov 2022 15:59:46 -0500 From: Tom Lane To: "Peter J. Holzer" cc: pgsql-general@lists.postgresql.org Subject: Re: Lots of read activity on index only scan In-reply-to: <20221118204617.z5pziyz4n6mllvhe@hjp.at> References: <20221118204617.z5pziyz4n6mllvhe@hjp.at> Comments: In-reply-to "Peter J. Holzer" message dated "Fri, 18 Nov 2022 21:46:17 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2267924.1668805186.1@sss.pgh.pa.us> Date: Fri, 18 Nov 2022 15:59:46 -0500 Message-ID: <2267925.1668805186@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Peter J. Holzer" writes: > Both do a parallel index only scan. Both perform 0 heap fetches. > But one reads 27336 buffers (or about 22 bytes per index entry, which > sounds reasonable) while the other reads 9995216 buffers (or almost one > full buffer per row). Why? The entries should be dense in the index in > both cases and since it's an index only scan (and explain says there > were 0 heap fetches) I would not expect extra accesses. Where do these > buffer reads come from? An "index only" scan is only that if the table's all-visible map is fully set. Did you vacuum this table after building it, or wait long enough for autovacuum to do so? regards, tom lane