Luca Ferrari <fluca1978@gmail.com> writes:
> On Sat, May 15, 2021 at 4:40 PM David Rowley <dgrowleyml@gmail.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