ANALYZE and index/stats degradation

From: "Jeroen T(dot) Vermeulen" <jtv(at)xs4all(dot)nl>
To: pgsql-hackers(at)postgresql(dot)org
Subject: ANALYZE and index/stats degradation
Date: 2007-07-02 10:59:46
Message-ID: 22087.125.24.240.137.1183373986.squirrel@webmail.xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

I've run into a case where I get bad performance that doesn't sound too
hard to solve. Question is: is it worth solving?

The situation is this: I have a table that can grow to a large number of
rows, then shrink to zero over a large number of quick, consecutive
transactions. The primary key index for the table is getting a lot of use
in the process.

But whenever perhaps one-third or so of the rows have been deleted, the
planner stops using that index and resorts to sequential scans. I tried
suppressing that by toggling enable_seqscan: works as advertised, but
performance is still terrible until (as far as I can make out) the next
analyze run has completed!

So I suppose the planner has a good reason to ignore the index at that
point. I'm assuming that this is something to do with the correlation
between the index and the column's statistics degrading in some way.

I also tried doing my own analyze runs on just the primary key index.
That will complete very quickly, and performance is restored for a while.
But as far as I can tell, a regular automatic analyze run will block my
own, more limited one on the same table. So performance is still bad, and
now it's irregular to boot.

This makes me wonder: when the planner finds that an index is no longer
worth using because its corresponding statistics are out of date, and it's
cheap to update those same stats, maybe it should do so? Even if there's
also going to be a full analyze on the table, it could be worthwhile to do
this quick limited run first. (Though not if one is already underway, of
course).

All this is based largely on guesswork, so if I've got it all wrong,
please enlighten me!

Jeroen

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2007-07-02 11:03:32 Postgresql.conf cleanup
Previous Message Martijn van Oosterhout 2007-07-02 10:55:20 Re: GiST consistent function, expected arguments; multi-dimensional indexes