Re: Inaccuracy in VACUUM's tuple count estimates

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inaccuracy in VACUUM's tuple count estimates
Date: 2014-06-09 06:31:32
Message-ID: CAA4eK1LhyqeWavaTgLaT6PkMmcY22bgo=PfCoBCAe0NbUqxoqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Jun 7, 2014 at 1:28 AM, Andres Freund <andres(at)2ndquadrant(dot)com>
wrote:
>
> On 2014-06-06 15:44:25 -0400, Tom Lane wrote:
> > I figured it'd be easy enough to get a better estimate by adding another
> > counter to count just LIVE and INSERT_IN_PROGRESS tuples (thus
effectively
> > assuming that in-progress inserts and deletes will both commit). I did
> > that, and found that it helped Tim's test case not at all :-(. A bit of
> > sleuthing revealed that HeapTupleSatisfiesVacuum actually returns
> > INSERT_IN_PROGRESS for any tuple whose xmin isn't committed, regardless
of
> > whether the transaction has since marked it for deletion:
> >
> > /*
> > * It'd be possible to discern between INSERT/DELETE in
progress
> > * here by looking at xmax - but that doesn't seem
beneficial for
> > * the majority of callers and even detrimental for some.
We'd
> > * rather have callers look at/wait for xmin than xmax. It's
> > * always correct to return INSERT_IN_PROGRESS because
that's
> > * what's happening from the view of other backends.
> > */
> > return HEAPTUPLE_INSERT_IN_PROGRESS;
>
> That's only the case of a couple of days ago. I really wasn't sure
> wheter to go that way or discern the two cases. That changed in the wake
> of:
> http://www.postgresql.org/message-id/20140530143150.GA11051@localhost

Won't this change impact the calculation of number of live
rows for analyze (acquire_sample_rows() considers the

HEAPTUPLE_DELETE_IN_PROGRESS tuples as liverows

for tuples updated by transactions other than current transaction)?

Even if we think that estimates are okay, the below comment

in acquire_same_rows() doesn't seem to suggest it.

/*
* We count delete-in-progress rows as still live, using
* the same reasoning given above; but we don't bother to
* include them in the sample.
*
..
*/

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Johnston 2014-06-09 07:04:44 Re: "RETURNING PRIMARY KEY" syntax extension
Previous Message Ian Barwick 2014-06-09 06:17:12 Re: "RETURNING PRIMARY KEY" syntax extension