Re: VACUUM/ANALYZE counting of in-doubt tuples

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: VACUUM/ANALYZE counting of in-doubt tuples
Date: 2007-11-19 12:20:21
Message-ID: 20071119122020.GA11626@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:

> On further thought though, that's not the whole story, and in fact
> VACUUM itself isn't doing very well at accounting for in-doubt tuples.
> The current implementation is that whatever live and dead tuple totals
> are arrived at by a VACUUM or ANALYZE are sent to the stats collector
> and simply overwrite its counters on arrival. Meanwhile, the
> transaction that is responsible for an in-doubt tuple will send a
> stats message to increment either the live-tuple or dead-tuple count
> as appropriate when it commits or aborts. If that happens before
> the VACUUM or ANALYZE completes, the increment will get overwritten
> by VACUUM/ANALYZE's total; if afterwards, the increment will get
> added onto the total. So ideally we'd count the state change as already
> done if we knew the other transaction would commit first, otherwise
> not.

How about this: let's have VACUUM send a message at the start of
processing the table. pgstats saves the current counters for the table
somewhere and resets them to zero; and any transaction that sends
messages after that is counted to the new counter.

When vacuum finishes and commits, it sends another message and pgstats
forgets the counters it saved. At this point, the count of dead tuples
will be correct. (If during vacuum anyone retrieves the number of dead
tuples, the logical thing would be to report the saved counter).

If vacuum aborts, it sends a message saying so and pgstats restores the
saved counter, adding whatever has been accumulated on the other counter
during the vacuum.

If the system crashes there is no problem because the stats are reset
anyway.

--
Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4
Este mail se entrega garantizadamente 100% libre de sarcasmo.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2007-11-19 13:31:43 Re: [HACKERS] fulltext parser strange behave
Previous Message Zdenek Kotala 2007-11-19 10:59:29 Re: Spinlock backoff algorithm