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 1lNGGn-0007pa-1d for pgsql-general@arkaria.postgresql.org; Fri, 19 Mar 2021 14:38:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lNGGl-0000dU-Vr for pgsql-general@arkaria.postgresql.org; Fri, 19 Mar 2021 14:38:31 +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 1lNGGl-0000dM-Nt for pgsql-general@lists.postgresql.org; Fri, 19 Mar 2021 14:38:31 +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 1lNGGj-0005CW-Ke for pgsql-general@lists.postgresql.org; Fri, 19 Mar 2021 14:38:31 +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 12JEcE1h4059133; Fri, 19 Mar 2021 10:38:14 -0400 From: Tom Lane To: Frank Millman cc: pgsql-general@lists.postgresql.org Subject: Re: SELECT is faster on SQL Server In-reply-to: References: <33b19e80-75da-a455-7e78-a01e14e4d4d6@gmx.net> <5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com> Comments: In-reply-to Frank Millman message dated "Fri, 19 Mar 2021 14:28:27 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4059131.1616164694.1@sss.pgh.pa.us> Date: Fri, 19 Mar 2021 10:38:14 -0400 Message-ID: <4059132.1616164694@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Frank Millman writes: > However, the bizarre thing is that I have simply restored the index to > what it was in the first place. If you look at the table definition in > my original message you can see that all the columns were included in > the index. But the query did not use it as a covering index. Now the > EXPLAIN ANALYSE clearly shows 'Index Only Scan using ar_tots_cover'. I > have no idea what changed. VACUUM, maybe? Even if there's a covering index, the planner is not likely to prefer an index-only scan unless it thinks that most of the table's pages are known all-visible. If they're not, most of the rows will require heap probes anyway to check row visibility, meaning that the "index-only" scan's performance degrades to about that of a regular indexscan. In this example, since you're fetching such a large fraction of the table (which the planner is accurately estimating), there's not a lot of daylight between the estimated costs of seqscan and index-only scan to begin with. I'm not surprised that it'd prefer the former if the table isn't recently vacuumed. regards, tom lane