ANALYZE and index/stats degradation - Mailing list pgsql-hackers

From Jeroen T. Vermeulen
Subject ANALYZE and index/stats degradation
Date
Msg-id 22087.125.24.240.137.1183373986.squirrel@webmail.xs4all.nl
Whole thread Raw
Responses Re: ANALYZE and index/stats degradation  (Gregory Stark <stark@enterprisedb.com>)
List 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




pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: GiST consistent function, expected arguments; multi-dimensional indexes
Next
From: Josh Berkus
Date:
Subject: Postgresql.conf cleanup