Refactor heap_page_prune so that instead of changing item states on-the-fly,
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 8 Mar 2008 21:58:07 +0000 (21:58 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 8 Mar 2008 21:58:07 +0000 (21:58 +0000)
commit94503f83117d627382cae71b02957b3263f43c76
tree495f7e9bc7f95b05f38da7dff8fc649620781f7b
parent0976e43832a355cfe4528800caf171b8cb4f44dc
Refactor heap_page_prune so that instead of changing item states on-the-fly,
it accumulates the set of changes to be made and then applies them.  It had
to accumulate the set of changes anyway to prepare a WAL record for the
pruning action, so this isn't an enormous change; the only new complexity is
to not doubly mark tuples that are visited twice in the scan.  The main
advantage is that we can substantially reduce the scope of the critical
section in which the changes are applied, thus avoiding PANIC in foreseeable
cases like running out of memory in inval.c.  A nice secondary advantage is
that it is now far clearer that WAL replay will actually do the same thing
that the original pruning did.

This commit doesn't do anything about the open problem that
CacheInvalidateHeapTuple doesn't have the right semantics for a CTID change
caused by collapsing out a redirect pointer.  But whatever we do about that,
it'll be a good idea to not do it inside a critical section.
src/backend/access/heap/heapam.c
src/backend/access/heap/pruneheap.c
src/include/access/heapam.h