From: Stephen Frost <sfrost@snowman.net>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thomas Kellerer <shammat@gmx.net>
Cc: pgsql-performance@lists.postgresql.org <pgsql-performance@lists.postgresql.org>
Subject: Re: PostgreSQL does not choose my indexes well
Date: Thu, 23 Apr 2020 13:20:48 -0400
Message-ID: <20200423172048.GF13712@tamriel.snowman.net> (raw)
In-Reply-To: <CAKFQuwZ5FmpgQQOmUCWu0MmJNuoW+KM_y-Q3YhRaAKVXi58vXg@mail.gmail.com>
References: <35dc90d6-e0c2-13b8-3184-e3db5d854a78@gmail.com>
<1bb37a19-77f6-8c49-073e-ed6251c98583@gmx.net>
<CAKFQuwY9twbudMDvmuo+9Mjy0y-cJcvzPazD07-oB+WV1qOMnA@mail.gmail.com>
<4315.1587655779@sss.pgh.pa.us>
<CAKFQuwZ5FmpgQQOmUCWu0MmJNuoW+KM_y-Q3YhRaAKVXi58vXg@mail.gmail.com>
Greetings,
* David G. Johnston (david.g.johnston@gmail.com) wrote:
> On Thu, Apr 23, 2020 at 8:29 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > > On Thursday, April 23, 2020, Thomas Kellerer <shammat@gmx.net> wrote:
> > >> Plus: scanning idx_tabla_entidad is more efficient because that index is
> > >> smaller.
> >
> > > Really? The absence of 33 million rows in the partial index seems like
> > it
> > > would compensate fully and then some for the extra included columns.
> >
> > On the other hand, an indexscan is likely to end up being effectively
> > random-access rather than the purely sequential access involved in
> > a seqscan.
>
> I feel like I'm missing something as the OP's query is choosing indexscan -
> just it is choosing to scan the full index containing the searched upon
> field instead of a partial index that doesn't contain the field but whose
> predicate matches the where condition - in furtherance of a count(*)
> computation where the columns don't really matter.
The actual query isn't a count(*) though, it's a 'select *'.
> I do get "its going to perform 1.4 million random index entries and heap
> lookup anyway - so it doesn't really matter" - but the first answer was
> "the full index is smaller than the partial" which goes against my
> intuition.
Yeah, I'm pretty sure the full index is quite a bit bigger than the
partial index- see my note from just a moment ago.
> The sequential scan that isn't being used would have to touch 25x the
> number of records - so its non-preference seems reasonable.
Agreed on that.
Thanks,
Stephen
Attachments:
[application/pgp-signature] signature.asc (818B, ../20200423172048.GF13712@tamriel.snowman.net/2-signature.asc)
download
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: sfrost@snowman.net, david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, shammat@gmx.net, pgsql-performance@lists.postgresql.org
Subject: Re: PostgreSQL does not choose my indexes well
In-Reply-To: <20200423172048.GF13712@tamriel.snowman.net>
* 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