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 1mTBzO-0003Ea-FM for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 23:49:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTByq-0003xO-Vt for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 23:48:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTByq-0003xF-Mq for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 23:48:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTByo-0007VS-AX for pgsql-general@postgresql.org; Wed, 22 Sep 2021 23:48:47 +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 18MNmds12245343; Wed, 22 Sep 2021 19:48:39 -0400 From: Tom Lane To: Michael Lewis cc: "David G. Johnston" , Israel Brewster , PostgreSQL Mailing Lists Subject: Re: Faster distinct query? In-reply-to: References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu> <2228441.1632343722@sss.pgh.pa.us> Comments: In-reply-to Michael Lewis message dated "Wed, 22 Sep 2021 16:51:51 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2245341.1632354519.1@sss.pgh.pa.us> Date: Wed, 22 Sep 2021 19:48:39 -0400 Message-ID: <2245342.1632354519@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Lewis writes: > On Wed, Sep 22, 2021 at 2:48 PM Tom Lane wrote: >> The "index-only" scan is reported to do 86m heap fetches along the >> way to returning 812m rows, so the data is apparently pretty dirty. > Do you say that because you would expect many more than 10 tuples per page? No, I say that because if the table were entirely all-visible, there would have been *zero* heap fetches. As it stands, it's reasonable to suspect that a pretty sizable fraction of the index-only scan's runtime went into random-access heap fetches made to verify visibility of individual rows. (You will, of course, never get to exactly zero heap fetches in an IOS unless the table data is quite static. But one dirty page out of every ten seems like there were a lot of recent changes. A VACUUM to clean that up might be well worthwhile.) regards, tom lane