Commit 80c79ab2 authored by Robert Haas's avatar Robert Haas

pgstattuple: Use SnapshotDirty, not SnapshotNow.

Tuples belonging to uncommitted transactions should not be
counted as dead.

This is arguably a bug fix that should be back-patched, but
as no one ever noticed until it came time to try to get rid
of SnapshotNow, I'm only doing this in master for now.
parent 3483f433
...@@ -278,9 +278,11 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) ...@@ -278,9 +278,11 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
Buffer buffer; Buffer buffer;
pgstattuple_type stat = {0}; pgstattuple_type stat = {0};
BufferAccessStrategy bstrategy; BufferAccessStrategy bstrategy;
SnapshotData SnapshotDirty;
/* Disable syncscan because we assume we scan from block zero upwards */ /* Disable syncscan because we assume we scan from block zero upwards */
scan = heap_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false); scan = heap_beginscan_strat(rel, SnapshotAny, 0, NULL, true, false);
InitDirtySnapshot(SnapshotDirty);
nblocks = scan->rs_nblocks; /* # blocks to be scanned */ nblocks = scan->rs_nblocks; /* # blocks to be scanned */
...@@ -296,7 +298,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo) ...@@ -296,7 +298,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
/* must hold a buffer lock to call HeapTupleSatisfiesVisibility */ /* must hold a buffer lock to call HeapTupleSatisfiesVisibility */
LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE); LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE);
if (HeapTupleSatisfiesVisibility(tuple, SnapshotNow, scan->rs_cbuf)) if (HeapTupleSatisfiesVisibility(tuple, &SnapshotDirty, scan->rs_cbuf))
{ {
stat.tuple_len += tuple->t_len; stat.tuple_len += tuple->t_len;
stat.tuple_count++; stat.tuple_count++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment