Thread: Novice questions about HeapTupleSatisfies

Novice questions about HeapTupleSatisfies

From
"murphy pope"
Date:
In backend/access/heap/heapam.c, there are two functions that I've been 
looking at.

The first is heapgettup() and the other is heap_fetch().

I'm guessing that one (heapgettup()) is used for sequential scans and the 
other (heap_fetch()) is used to retreive a tuple based on an index entry.  
Is that right? (or close to right - I would guess that heap_fetch() might 
also be called for other purposes).

Each of these functions calls HeapTupleSatisfies().

My (novice) interpretation of this code is that, if HeapTupleSatisfies() 
succeeds (that is, it sets the 'valid' parameter to TRUE), the given tuple 
is visible to the current transaction.  If HeapTupleSatisfies() fails (sets 
'valid' to FALSE), the tuple is *not* visible to the current transaction.

HeapTupleSatisfies() will return FALSE for a tuple that has been deleted but 
not yet VACUUMed away, or for a tuple that has been modified (or added) by 
another transaction that has not yet committed, or for a tuple that has been 
committed by another transaction but it was committed since our current 
command started scanning.  (There are probably some other rules that I can 
glean from the documentation, but if I got any of those wrong, can someone 
correct me?)

If HeapTupleSatisfies() returns FALSE, that means that we have read a page 
from disk that contains at least one invisible tuple.  If I read a page that 
contains only invisible tuples, that was a wasted I/O (at least from my 
transaction's perspective).

Did I get (most or any of) this right?

TIA - Murphy

_________________________________________________________________
Concerned that messages may bounce because your Hotmail account has exceeded 
its 2MB storage limit? Get Hotmail Extra Storage!         
http://join.msn.com/?PAGE=features/es



Re: Novice questions about HeapTupleSatisfies

From
Tom Lane
Date:
"murphy pope" <pope_murphy@hotmail.com> writes:
> Did I get (most or any of) this right?

Mostly.  A couple of comments: HeapTupleSatisfies can do scankey testing
(that is, see whether columns satisfy "col op constant" conditions) in
addition to the time-qual checking you are thinking about.  Also, the
time qual is defined by reference to a "snapshot" --- there is not
necessarily a unique notion of which tuples are good, even within a
single transaction.  It all depends on the snapshot you use.

You can learn more about time qual testing by reading the comments in
src/backend/utils/time/tqual.c.
        regards, tom lane