Re: The standard 'why does it take so long' question - Mailing list pgsql-general

From Tom Lane
Subject Re: The standard 'why does it take so long' question
Date
Msg-id 354.1028900476@sss.pgh.pa.us
Whole thread Raw
In response to Re: The standard 'why does it take so long' question  ("Nigel J. Andrews" <nandrews@investsystems.co.uk>)
List pgsql-general
"Nigel J. Andrews" <nandrews@investsystems.co.uk> writes:
> I really don't know sufficient to be able to see why the stats would
> favour one index over the other. Although looking at the pg_stats
> entries below now I notice that the correlation for the time column is
> 1, compared to 0.058 for the poster_id.

Ah, of course, that would do it.  Thinking about it, I see that the
system is not really very bright about ordering considerations for
multicolumn indexes.  On a macro scale, the posterid/time index is
poorly correlated with the physical table order --- but when you
consider only the set of entries for a single posterid over a small
time range, the index is pretty well correlated.  The planner doesn't
consider that effect, so it mistakenly credits the time/posterid
index with much higher correlation and hence lower scan cost than the
other.

I already had a todo item to reconsider the costing estimates for
multicolumn indexes --- will see if we can be smarter about cases like
this.

            regards, tom lane

pgsql-general by date:

Previous
From: Jeff Eckermann
Date:
Subject: Re: UNIQUE constraint matching given keys for referenced
Next
From: Tom Lane
Date:
Subject: Re: UNIQUE constraint matching given keys for referenced