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 1mT9Ai-0004sY-J3 for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 20:48:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mT9Ah-0004U8-Io for pgsql-general@arkaria.postgresql.org; Wed, 22 Sep 2021 20:48:51 +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 1mT9Ah-0004U0-A5 for pgsql-general@lists.postgresql.org; Wed, 22 Sep 2021 20:48:51 +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 1mT9Af-0005SY-9f for pgsql-general@postgresql.org; Wed, 22 Sep 2021 20:48:50 +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 18MKmgUw2228442; Wed, 22 Sep 2021 16:48:42 -0400 From: Tom Lane To: "David G. Johnston" cc: Michael Lewis , Israel Brewster , PostgreSQL Mailing Lists Subject: Re: Faster distinct query? In-reply-to: References: <0BB059BF-54BD-46FA-8B26-28FEF9A04198@alaska.edu> Comments: In-reply-to "David G. Johnston" message dated "Wed, 22 Sep 2021 13:26:55 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2228440.1632343722.1@sss.pgh.pa.us> Date: Wed, 22 Sep 2021 16:48:42 -0400 Message-ID: <2228441.1632343722@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > There is no where clause so I'm doubtful there is much to be gained going > down this path. The Index-Only scan seems like an optimal way to obtain > this data and the existing query already does that. 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. It's possible that a preliminary VACUUM to get page-all-visible hint bits set would be a net win. regards, tom lane