Re: Bad estimate with partial index - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Bad estimate with partial index
Date
Msg-id 2823861.1650464157@sss.pgh.pa.us
Whole thread Raw
In response to Re: Bad estimate with partial index  (Tomas Vondra <tomas.vondra@enterprisedb.com>)
Responses Re: Bad estimate with partial index  (Tomas Vondra <tomas.vondra@enterprisedb.com>)
List pgsql-hackers
Tomas Vondra <tomas.vondra@enterprisedb.com> writes:
> The whole idea is that instead of bailing out for non-RestrictInfo case,
> it calculates the necessary information for the clause from scratch.
> This means relids and pseudoconstant flag, which are checked to decide
> if the clause is compatible with extended stats.

Right.

> But when inspecting how to calculate pseudoconstant, I realized that
> maybe that's not really needed. Per distribute_qual_to_rels() we only
> set it to 'true' when bms_is_empty(relids), and we already check that
> relids is a singleton, so it can't be empty - which means pseudoconstant
> can't be true either.

Yeah, I would not bother with the pseudoconstant-related tests for a
bare clause.  Patch looks reasonably sane in a quick once-over otherwise,
and the fact that it fixes the presented test case is promising.
(If you set enable_indexscan = off, you can verify that the estimate
for the number of index entries retrieved is now sane.)  I did not look
to see if there were any other RestrictInfo dependencies, though.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Re: fix cost subqueryscan wrong parallel cost
Next
From: André Hänsel
Date:
Subject: RE: Bad estimate with partial index