Skip to content

Commit c91560d

Browse files
committed
Move remaining code from tqual.[ch] to heapam.h / heapam_visibility.c.
Given these routines are heap specific, and that there will be more generic visibility support in via table AM, it makes sense to move the prototypes to heapam.h (routines like HeapTupleSatisfiesVacuum will not be exposed in a generic fashion, because they are too storage specific). Similarly, the code in tqual.c is specific to heap, so moving it into access/heap/ makes sense. Author: Andres Freund Discussion: https://postgr.es/m/[email protected]
1 parent b7eda3e commit c91560d

32 files changed

+65
-101
lines changed

contrib/pg_visibility/pg_visibility.c

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "storage/smgr.h"
2323
#include "utils/rel.h"
2424
#include "utils/snapmgr.h"
25-
#include "utils/tqual.h"
2625

2726
PG_MODULE_MAGIC;
2827

contrib/pgrowlocks/pgrowlocks.c

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "utils/builtins.h"
3939
#include "utils/rel.h"
4040
#include "utils/snapmgr.h"
41-
#include "utils/tqual.h"
4241
#include "utils/varlena.h"
4342

4443
PG_MODULE_MAGIC;

contrib/pgstattuple/pgstatapprox.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#include "postgres.h"
1414

15+
#include "access/heapam.h"
1516
#include "access/relation.h"
1617
#include "access/transam.h"
1718
#include "access/visibilitymap.h"
@@ -26,7 +27,6 @@
2627
#include "storage/procarray.h"
2728
#include "storage/lmgr.h"
2829
#include "utils/builtins.h"
29-
#include "utils/tqual.h"
3030
#include "commands/vacuum.h"
3131

3232
PG_FUNCTION_INFO_V1(pgstattuple_approx);

contrib/pgstattuple/pgstattuple.c

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "storage/bufmgr.h"
3737
#include "storage/lmgr.h"
3838
#include "utils/builtins.h"
39-
#include "utils/tqual.h"
4039
#include "utils/varlena.h"
4140

4241
PG_MODULE_MAGIC;

src/backend/access/heap/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ subdir = src/backend/access/heap
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = heapam.o hio.o pruneheap.o rewriteheap.o syncscan.o tuptoaster.o \
16-
vacuumlazy.o visibilitymap.o
15+
OBJS = heapam.o heapam_visibility.o hio.o pruneheap.o rewriteheap.o \
16+
syncscan.o tuptoaster.o vacuumlazy.o visibilitymap.o
1717

1818
include $(top_srcdir)/src/backend/common.mk

src/backend/access/heap/heapam.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
#include "utils/lsyscache.h"
6767
#include "utils/relcache.h"
6868
#include "utils/snapmgr.h"
69-
#include "utils/tqual.h"
7069

7170

7271
/* GUC variable */
@@ -5284,8 +5283,8 @@ test_lockmode_for_conflict(MultiXactStatus status, TransactionId xid,
52845283

52855284
/*
52865285
* Note: we *must* check TransactionIdIsInProgress before
5287-
* TransactionIdDidAbort/Commit; see comment at top of tqual.c for an
5288-
* explanation.
5286+
* TransactionIdDidAbort/Commit; see comment at top of heapam_visibility.c
5287+
* for an explanation.
52895288
*/
52905289
if (TransactionIdIsCurrentTransactionId(xid))
52915290
{
@@ -6254,7 +6253,8 @@ FreezeMultiXactId(MultiXactId multi, uint16 t_infomask,
62546253
*
62556254
* As with all tuple visibility routines, it's critical to test
62566255
* TransactionIdIsInProgress before TransactionIdDidCommit,
6257-
* because of race conditions explained in detail in tqual.c.
6256+
* because of race conditions explained in detail in
6257+
* heapam_visibility.c.
62586258
*/
62596259
if (TransactionIdIsCurrentTransactionId(xid) ||
62606260
TransactionIdIsInProgress(xid))

src/backend/utils/time/tqual.c renamed to src/backend/access/heap/heapam_visibility.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* tqual.c
4-
* POSTGRES "time qualification" code, ie, tuple visibility rules.
3+
* heapam_visibility.c
4+
* Tuple visibility rules for tuples stored in heap.
55
*
66
* NOTE: all the HeapTupleSatisfies routines will update the tuple's
77
* "hint" status bits if we see that the inserting or deleting transaction
@@ -56,13 +56,14 @@
5656
* Portions Copyright (c) 1994, Regents of the University of California
5757
*
5858
* IDENTIFICATION
59-
* src/backend/utils/time/tqual.c
59+
* src/backend/access/heap/heapam_visibility.c
6060
*
6161
*-------------------------------------------------------------------------
6262
*/
6363

6464
#include "postgres.h"
6565

66+
#include "access/heapam.h"
6667
#include "access/htup_details.h"
6768
#include "access/multixact.h"
6869
#include "access/subtrans.h"
@@ -74,7 +75,6 @@
7475
#include "utils/builtins.h"
7576
#include "utils/combocid.h"
7677
#include "utils/snapmgr.h"
77-
#include "utils/tqual.h"
7878

7979

8080
/*

src/backend/access/heap/pruneheap.c

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "storage/bufmgr.h"
2626
#include "utils/snapmgr.h"
2727
#include "utils/rel.h"
28-
#include "utils/tqual.h"
2928

3029
/* Working data for heap_page_prune and subroutines */
3130
typedef struct

src/backend/access/heap/rewriteheap.c

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130

131131
#include "utils/memutils.h"
132132
#include "utils/rel.h"
133-
#include "utils/tqual.h"
134133

135134
#include "storage/procarray.h"
136135

src/backend/access/heap/tuptoaster.c

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "utils/rel.h"
4343
#include "utils/snapmgr.h"
4444
#include "utils/typcache.h"
45-
#include "utils/tqual.h"
4645

4746

4847
#undef TOAST_DEBUG

src/backend/access/heap/vacuumlazy.c

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include "utils/memutils.h"
6060
#include "utils/pg_rusage.h"
6161
#include "utils/timestamp.h"
62-
#include "utils/tqual.h"
6362

6463

6564
/*

src/backend/access/index/genam.c

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "utils/ruleutils.h"
3636
#include "utils/snapmgr.h"
3737
#include "utils/syscache.h"
38-
#include "utils/tqual.h"
3938

4039

4140
/* ----------------------------------------------------------------

src/backend/access/spgist/spgvacuum.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ vacuumLeafPage(spgBulkDeleteState *bds, Relation index, Buffer buffer,
192192
* happened since VACUUM started.
193193
*
194194
* Note: we could make a tighter test by seeing if the xid is
195-
* "running" according to the active snapshot; but tqual.c doesn't
195+
* "running" according to the active snapshot; but snapmgr.c doesn't
196196
* currently export a suitable API, and it's not entirely clear
197197
* that a tighter test is worth the cycles anyway.
198198
*/

src/backend/access/transam/transam.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ TransactionIdDidAbort(TransactionId transactionId)
228228
* (and so it's not named TransactionIdDidComplete, which would be the
229229
* appropriate name for a function that worked that way). The intended
230230
* use is just to short-circuit TransactionIdIsInProgress calls when doing
231-
* repeated tqual.c checks for the same XID. If this isn't extremely fast
232-
* then it will be counterproductive.
231+
* repeated heapam_visibility.c checks for the same XID. If this isn't
232+
* extremely fast then it will be counterproductive.
233233
*
234234
* Note:
235235
* Assumes transaction identifier is valid.

src/backend/access/transam/xact.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,10 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
774774
* We always say that BootstrapTransactionId is "not my transaction ID"
775775
* even when it is (ie, during bootstrap). Along with the fact that
776776
* transam.c always treats BootstrapTransactionId as already committed,
777-
* this causes the tqual.c routines to see all tuples as committed, which
778-
* is what we need during bootstrap. (Bootstrap mode only inserts tuples,
779-
* it never updates or deletes them, so all tuples can be presumed good
780-
* immediately.)
777+
* this causes the heapam_visibility.c routines to see all tuples as
778+
* committed, which is what we need during bootstrap. (Bootstrap mode
779+
* only inserts tuples, it never updates or deletes them, so all tuples
780+
* can be presumed good immediately.)
781781
*
782782
* Likewise, InvalidTransactionId and FrozenTransactionId are certainly
783783
* not my transaction ID, so we can just return "false" immediately for

src/backend/catalog/index.c

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#include "utils/syscache.h"
7676
#include "utils/tuplesort.h"
7777
#include "utils/snapmgr.h"
78-
#include "utils/tqual.h"
7978

8079

8180
/* Potentially set by pg_upgrade_support functions */

src/backend/commands/analyze.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <math.h>
1818

1919
#include "access/genam.h"
20+
#include "access/heapam.h"
2021
#include "access/multixact.h"
2122
#include "access/relation.h"
2223
#include "access/sysattr.h"
@@ -63,7 +64,6 @@
6364
#include "utils/sortsupport.h"
6465
#include "utils/syscache.h"
6566
#include "utils/timestamp.h"
66-
#include "utils/tqual.h"
6767

6868

6969
/* Per-index data for ANALYZE */

src/backend/commands/async.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ asyncQueueProcessPageEntries(volatile QueuePosition *current,
19551955
* Note that we must test XidInMVCCSnapshot before we test
19561956
* TransactionIdDidCommit, else we might return a message from
19571957
* a transaction that is not yet visible to snapshots; compare
1958-
* the comments at the head of tqual.c.
1958+
* the comments at the head of heapam_visibility.c.
19591959
*
19601960
* Also, while our own xact won't be listed in the snapshot,
19611961
* we need not check for TransactionIdIsCurrentTransactionId

src/backend/commands/cluster.c

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "utils/relmapper.h"
5353
#include "utils/snapmgr.h"
5454
#include "utils/syscache.h"
55-
#include "utils/tqual.h"
5655
#include "utils/tuplesort.h"
5756

5857

src/backend/executor/nodeBitmapHeapscan.c

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "utils/rel.h"
5252
#include "utils/spccache.h"
5353
#include "utils/snapmgr.h"
54-
#include "utils/tqual.h"
5554

5655

5756
static TupleTableSlot *BitmapHeapNext(BitmapHeapScanState *node);

src/backend/executor/nodeModifyTable.c

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "utils/builtins.h"
5454
#include "utils/memutils.h"
5555
#include "utils/rel.h"
56-
#include "utils/tqual.h"
5756

5857

5958
static bool ExecOnConflictUpdate(ModifyTableState *mtstate,

src/backend/executor/nodeSamplescan.c

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "storage/predicate.h"
2626
#include "utils/builtins.h"
2727
#include "utils/rel.h"
28-
#include "utils/tqual.h"
2928

3029
static TupleTableSlot *SampleNext(SampleScanState *node);
3130
static void tablesample_init(SampleScanState *scanstate);

src/backend/replication/logical/reorderbuffer.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <unistd.h>
5757
#include <sys/stat.h>
5858

59+
#include "access/heapam.h"
5960
#include "access/rewriteheap.h"
6061
#include "access/transam.h"
6162
#include "access/tuptoaster.h"
@@ -78,7 +79,6 @@
7879
#include "utils/memutils.h"
7980
#include "utils/rel.h"
8081
#include "utils/relfilenodemap.h"
81-
#include "utils/tqual.h"
8282

8383

8484
/* entry for a hash table we use to map from xid to our transaction state */
@@ -1269,7 +1269,7 @@ ReorderBufferCleanupTXN(ReorderBuffer *rb, ReorderBufferTXN *txn)
12691269

12701270
/*
12711271
* Build a hash with a (relfilenode, ctid) -> (cmin, cmax) mapping for use by
1272-
* tqual.c's HeapTupleSatisfiesHistoricMVCC.
1272+
* HeapTupleSatisfiesHistoricMVCC.
12731273
*/
12741274
static void
12751275
ReorderBufferBuildTupleCidHash(ReorderBuffer *rb, ReorderBufferTXN *txn)

src/backend/replication/logical/snapbuild.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xact
11191119
* NB: We only increase xmax when a catalog modifying transaction commits
11201120
* (see SnapBuildCommitTxn). Because of this, xmax can be lower than
11211121
* xmin, which looks odd but is correct and actually more efficient, since
1122-
* we hit fast paths in tqual.c.
1122+
* we hit fast paths in heapam_visibility.c.
11231123
*/
11241124
builder->xmin = running->oldestRunningXid;
11251125

src/backend/storage/ipc/procarray.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ GetMaxSnapshotSubxidCount(void)
14981498
* information may not be available. If we find any overflowed subxid arrays,
14991499
* we have to mark the snapshot's subxid data as overflowed, and extra work
15001500
* *may* need to be done to determine what's running (see XidInMVCCSnapshot()
1501-
* in tqual.c).
1501+
* in heapam_visibility.c).
15021502
*
15031503
* We also update the following backend-global variables:
15041504
* TransactionXmin: the oldest xmin of any snapshot in use in the

src/backend/storage/lmgr/predicate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185

186186
#include "postgres.h"
187187

188+
#include "access/heapam.h"
188189
#include "access/htup_details.h"
189190
#include "access/slru.h"
190191
#include "access/subtrans.h"
@@ -202,7 +203,6 @@
202203
#include "storage/procarray.h"
203204
#include "utils/rel.h"
204205
#include "utils/snapmgr.h"
205-
#include "utils/tqual.h"
206206

207207
/* Uncomment the next line to test the graceful degradation code. */
208208
/* #define TEST_OLDSERXID */

src/backend/utils/adt/ri_triggers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "postgres.h"
3232

33+
#include "access/heapam.h"
3334
#include "access/htup_details.h"
3435
#include "access/sysattr.h"
3536
#include "access/table.h"
@@ -57,7 +58,6 @@
5758
#include "utils/rls.h"
5859
#include "utils/snapmgr.h"
5960
#include "utils/syscache.h"
60-
#include "utils/tqual.h"
6161

6262

6363
/* ----------

src/backend/utils/cache/inval.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* When a tuple is updated or deleted, our standard time qualification rules
99
* consider that it is *still valid* so long as we are in the same command,
1010
* ie, until the next CommandCounterIncrement() or transaction commit.
11-
* (See utils/time/tqual.c, and note that system catalogs are generally
12-
* scanned under the most current snapshot available, rather than the
13-
* transaction snapshot.) At the command boundary, the old tuple stops
11+
* (See acces/heap/heapam_visibility.c, and note that system catalogs are
12+
* generally scanned under the most current snapshot available, rather than
13+
* the transaction snapshot.) At the command boundary, the old tuple stops
1414
* being valid and the new version, if any, becomes valid. Therefore,
1515
* we cannot simply flush a tuple from the system caches during heap_update()
1616
* or heap_delete(). The tuple is still good at that point; what's more,

src/backend/utils/time/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ subdir = src/backend/utils/time
1212
top_builddir = ../../../..
1313
include $(top_builddir)/src/Makefile.global
1414

15-
OBJS = combocid.o tqual.o snapmgr.o
15+
OBJS = combocid.o snapmgr.o
1616

1717
include $(top_srcdir)/src/backend/common.mk

src/include/access/heapam.h

+34
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ typedef struct HeapUpdateFailureData
6060
CommandId cmax;
6161
} HeapUpdateFailureData;
6262

63+
/* Result codes for HeapTupleSatisfiesVacuum */
64+
typedef enum
65+
{
66+
HEAPTUPLE_DEAD, /* tuple is dead and deletable */
67+
HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
68+
HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
69+
HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
70+
HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
71+
} HTSV_Result;
6372

6473
/* ----------------
6574
* function prototypes for heap access method
@@ -178,4 +187,29 @@ extern Size SyncScanShmemSize(void);
178187
struct VacuumParams;
179188
extern void heap_vacuum_rel(Relation onerel, int options,
180189
struct VacuumParams *params, BufferAccessStrategy bstrategy);
190+
191+
/* in heap/heapam_visibility.c */
192+
extern bool HeapTupleSatisfiesVisibility(HeapTuple stup, Snapshot snapshot,
193+
Buffer buffer);
194+
extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple stup, CommandId curcid,
195+
Buffer buffer);
196+
extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple stup, TransactionId OldestXmin,
197+
Buffer buffer);
198+
extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
199+
uint16 infomask, TransactionId xid);
200+
extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
201+
extern bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
202+
extern bool HeapTupleIsSurelyDead(HeapTuple htup, TransactionId OldestXmin);
203+
204+
/*
205+
* To avoid leaking too much knowledge about reorderbuffer implementation
206+
* details this is implemented in reorderbuffer.c not heapam_visibility.c
207+
*/
208+
struct HTAB;
209+
extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
210+
Snapshot snapshot,
211+
HeapTuple htup,
212+
Buffer buffer,
213+
CommandId *cmin, CommandId *cmax);
214+
181215
#endif /* HEAPAM_H */

0 commit comments

Comments
 (0)