Re: disabling seqscan not using primary key index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Luca Ferrari <fluca1978(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: disabling seqscan not using primary key index?
Date: 2021-05-15 17:17:15
Message-ID: 2312912.1621099035@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Luca Ferrari <fluca1978(at)gmail(dot)com> writes:
> On Sat, May 15, 2021 at 4:40 PM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
>> The answer is fairly simple, the planner just never considers using
>> the primary key index as there are no possible cases where it would be
>> useful.

> Does this mean that any UNIQUE constraint on the table is subject to
> the same consideration?

David's statement applies to any index. Per the code in indxpath.c:

* 4. Generate an indexscan path if there are relevant restriction clauses
* in the current clauses, OR the index ordering is potentially useful for
* later merging or final output ordering, OR the index has a useful
* predicate, OR an index-only scan is possible.

If none of those cases apply, an indexscan is guaranteed to be worse
than a seqscan, so we don't consider it.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Venkata B Nagothi 2021-05-16 00:53:55 Re: Postgres upgrade 12 - issues with OIDs
Previous Message Luca Ferrari 2021-05-15 16:38:40 Re: disabling seqscan not using primary key index?