Re: partial unique index and the planner

From: Michal Politowski <mpol+pg(at)meep(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: partial unique index and the planner
Date: 2009-02-16 18:18:38
Message-ID: 20090216181838.GA31135@meep.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 15 Feb 2009 13:41:05 -0500, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Michal Politowski <mpol+pg(at)meep(dot)pl> writes:
> > Is it normal that plans using a scan on a partial unique index
> > estimate that much more than one row is returned?
>
> There isn't currently any special logic to recognize that case;
> the estimate is just whatever is going to come out of the normal
> statistics-based estimation.

Too bad. It seems then that the schema is not well suited to what Postgres
would like. Maybe changing it will be the right thing to do.

The situation is that there are potentially several versions of a row,
only one of which is active at any given moment. The partial unique index
lets a query find the active row quickly, but since it is not known to the
planner that there is only one such row, a join caused problems.

So it looks like, at least for the current problem, separating the active
and inactive rows in their own tables would help.

On the other hand it seems that the table finally grew big enough for
Postgres to prefer index scans to heap scans even with the skewed
estimates.

> I'm unsure how hard it'd be to improve the situation. If we've already
> identified relevant partial indexes before any of the stats code has to
> run then it'd be pretty easy, but that might be a bit fragile.
>
> Anyway, the usual advice for such cases is to see if raising the
> statistics target helps.

Unfortunately it's already 1000. And it seems to me it woud not help here
anyway. The estimate is very correct for the number of rows with the most
common identifier, only it cannot take the active status into consideration.

--
Michał Politowski
Talking has been known to lead to communication if practiced carelessly.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2009-02-16 18:31:44 Re: partial unique index and the planner
Previous Message joel garry 2009-02-16 17:51:42 Re: Which SQL is the best for servers?