pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Frank Millman <frank@chagford.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: SELECT is faster on SQL Server
Date: Fri, 19 Mar 2021 10:38:14 -0400
Message-ID: <4059132.1616164694@sss.pgh.pa.us> (raw)
In-Reply-To: <b4b09b66-9ad3-a8ad-3dd8-28d23a0d112c@chagford.com>
References: <d002a9e4-433c-3f44-90aa-46568db4bc00@chagford.com>
	<33b19e80-75da-a455-7e78-a01e14e4d4d6@gmx.net>
	<fbdd2bdd-1957-1b49-eeca-0278d43de71d@chagford.com>
	<CAFj8pRAU8N9hhotGhrxEcnae+tjy_CQoJA3fMYH9o58Du1SjLQ@mail.gmail.com>
	<c6befefe-a4ab-25ab-ceed-66d7d362de13@chagford.com>
	<CAFj8pRBLakshW08Har67iJcx=OnSsazqXb8CeY-k3dLUpqSrwQ@mail.gmail.com>
	<5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com>
	<b4b09b66-9ad3-a8ad-3dd8-28d23a0d112c@chagford.com>

Frank Millman <frank@chagford.com> 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





view thread (18+ messages)  latest in thread

Message-ID: <4059132.1616164694@sss.pgh.pa.us>
Permalink:  ../4059132.1616164694@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4059132.1616164694@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, frank@chagford.com
  Subject: Re: SELECT is faster on SQL Server
  In-Reply-To: <4059132.1616164694@sss.pgh.pa.us>
  References: <d002a9e4-433c-3f44-90aa-46568db4bc00@chagford.com> <33b19e80-75da-a455-7e78-a01e14e4d4d6@gmx.net> <fbdd2bdd-1957-1b49-eeca-0278d43de71d@chagford.com> <CAFj8pRAU8N9hhotGhrxEcnae+tjy_CQoJA3fMYH9o58Du1SjLQ@mail.gmail.com> <c6befefe-a4ab-25ab-ceed-66d7d362de13@chagford.com> <CAFj8pRBLakshW08Har67iJcx=OnSsazqXb8CeY-k3dLUpqSrwQ@mail.gmail.com> <5a6f07d7-1d0f-f685-6743-d4dbc1730177@chagford.com> <b4b09b66-9ad3-a8ad-3dd8-28d23a0d112c@chagford.com> <4059132.1616164694@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox