Re: Much Ado About COUNT(*) - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: Much Ado About COUNT(*)
Date
Msg-id 200501222006.j0MK6XD14490@candle.pha.pa.us
Whole thread Raw
In response to Re: Much Ado About COUNT(*)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Much Ado About COUNT(*)  (Ron Mayer <rm_pg@cheapcomplexdevices.com>)
List pgsql-hackers
Added to TODO based on this discusion:

---------------------------------------------------------------------------

* Speed up COUNT(*)
 We could use a fixed row count and a +/- count to follow MVCC visibility rules, or a single cached value could be used
andinvalidated if anyone modifies the table.  Another idea is to  <-- get a count directly from a unique index, but for
thisto be faster than a sequential scan it must avoid access to the heap to obtain tuple visibility information.
 

* Allow data to be pulled directly from indexes
 Currently indexes do not have enough tuple tuple visibility information to allow data to be pulled from the index
withoutalso accessing the heap.  One way to allow this is to set a bit to index tuples to indicate if a tuple is
currentlyvisible to all transactions when the first valid heap lookup happens.  This bit would have to be cleared when
aheap tuple is expired.
 



---------------------------------------------------------------------------

Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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.
> 
> 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.
> 
>             regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 

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


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: [PATCHES] Merge pg_shadow && pg_group -- UNTESTED
Next
From: Nicolai Tufar
Date:
Subject: Re: %2$, %1$ gettext placeholder replacement is not working under Win32