Re: Inconsistant use of index.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ron Mayer <ron(at)intervideo(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Inconsistant use of index.
Date: 2002-03-26 19:59:55
Message-ID: 8393.1017172795@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Ron Mayer <ron(at)intervideo(dot)com> writes:
>> I'm particularly interested in the correlation estimate for the dat
>> column. (Would you happen to have an idea whether the data has been
>> inserted more-or-less in dat order?)

> I beleve much of February was loaded first, then we back-filled January,
> and daily I've been adding March's results. I don't believe the index-usage
> stopped when we did the january fill... something happend a few days ago after
> a pretty routine daily load.

The correlation estimate for dat is pretty low (0.086088), which I think
reflects the fact that on a macro level your data is not very orderly
(Feb/Jan/Mar). However, if it's been loaded on a daily basis then the
records for any single day will be together --- which is why the indexed
probe for a single day is so fast. I don't see any way that we can
expect the system to model this effect with only one ordering-correlation
number :-( ... so a proper fix will have to wait for some future release
when we can think about having more extensive stats about ordering.

In the meantime, it would be interesting to see if re-establishing the
big-picture order correlation would persuade the planner to do the right
thing. Could you do something like this:

CREATE TABLE foo AS SELECT * FROM fact ORDER BY dat;
TRUNCATE TABLE fact;
INSERT INTO fact SELECT * FROM foo;
DROP TABLE foo;
VACUUM ANALYZE fact;

(this should leave you in a state where pg_stats shows correlation 1.0
for fact.dat) and then see what you get from EXPLAIN?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kallol Nandi 2002-03-27 00:37:27 Disastrous : Server shuts down abnormally
Previous Message Matt Peterson 2002-03-26 19:32:31 SEGV in contrib/array/array_iterator.c