Skip site navigation (1) Skip section navigation (2)

Re: Much Ado About COUNT(*)

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Jonah H(dot) Harris" <jharris(at)tvi(dot)edu>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Much Ado About COUNT(*)
Date: 2005-01-13 14:04:46
Message-ID: 200501131404.j0DE4kd03279@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-announcepgsql-hackerspgsql-patches
Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> >> Ah, right, I missed the connection.  Hmm ... that's sort of the inverse
> >> of the "killed tuple" optimization we put in a release or two back,
> >> where an index tuple is marked as definitely dead once it's committed
> >> dead and the deletion is older than all active transactions.
> 
> > Yes, it is sort of the reverse, but how do you get around the delete
> > case?
> 
> A would-be deleter of a tuple would have to go and clear the "known
> good" bits on all the tuple's index entries before it could commit.
> This would bring the tuple back into the "uncertain status" condition
> where backends would have to visit the heap to find out what's up.
> Eventually the state would become certain again (either dead to
> everyone or live to everyone) and one or the other hint bit could be
> set again.

Right.  Do you think the extra overhead of clearing those bits on
update/delete would be worth it?

> The ugly part of this is that clearing the bit is not like setting a
> hint bit, ie it's not okay if we lose that change.  Therefore, each
> bit-clearing would have to be WAL-logged.  This is a big part of my
> concern about the cost.

Yep, that was my concern too.  My feeling is that once you mark the
tuple for expiration (update/delete), you then clear the index bit. 
When reading WAL on recovery, you have to clear index bits on rows as
you read expire information from WAL.  I don't think it would require
extra WAL information.

The net effect of this idea is that indexes have to look up heap row
status information only for rows that have been recently
created/expired.

If we did have those bits, it would allow us to read data directly from
the index, which is something we don't do now.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

Responses

pgsql-announce by date

Next:From: Tom LaneDate: 2005-01-13 15:29:16
Subject: Re: Much Ado About COUNT(*)
Previous:From: Christopher Kings-LynneDate: 2005-01-13 10:12:49
Subject: Re: Much Ado About COUNT(*)

pgsql-hackers by date

Next:From: Csaba NagyDate: 2005-01-13 14:48:51
Subject: Re: [HACKERS] Much Ado About COUNT(*)
Previous:From: Greg StarkDate: 2005-01-13 13:59:31
Subject: Re: [HACKERS] Much Ado About COUNT(*)

pgsql-patches by date

Next:From: Tom LaneDate: 2005-01-13 15:29:16
Subject: Re: Much Ado About COUNT(*)
Previous:From: Christopher Kings-LynneDate: 2005-01-13 10:12:49
Subject: Re: Much Ado About COUNT(*)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group