Skip to content

Commit 5f7b58f

Browse files
committed
Generalize concept of temporary relations to "relation persistence".
This commit replaces pg_class.relistemp with pg_class.relpersistence; and also modifies the RangeVar node type to carry relpersistence rather than istemp. It also removes removes rd_istemp from RelationData and instead performs the correct computation based on relpersistence. For clarity, we add three new macros: RelationNeedsWAL(), RelationUsesLocalBuffers(), and RelationUsesTempNamespace(), so that we can clarify the purpose of each check that previous depended on rd_istemp. This is intended as infrastructure for the upcoming unlogged tables patch, as well as for future possible work on global temporary tables.
1 parent 0c90442 commit 5f7b58f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+334
-230
lines changed

src/backend/access/gin/ginbtree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
304304

305305
MarkBufferDirty(stack->buffer);
306306

307-
if (!btree->index->rd_istemp)
307+
if (RelationNeedsWAL(btree->index))
308308
{
309309
XLogRecPtr recptr;
310310

@@ -373,7 +373,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
373373
MarkBufferDirty(lbuffer);
374374
MarkBufferDirty(stack->buffer);
375375

376-
if (!btree->index->rd_istemp)
376+
if (RelationNeedsWAL(btree->index))
377377
{
378378
XLogRecPtr recptr;
379379

@@ -422,7 +422,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
422422
MarkBufferDirty(rbuffer);
423423
MarkBufferDirty(stack->buffer);
424424

425-
if (!btree->index->rd_istemp)
425+
if (RelationNeedsWAL(btree->index))
426426
{
427427
XLogRecPtr recptr;
428428

src/backend/access/gin/ginfast.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ writeListPage(Relation index, Buffer buffer,
103103

104104
MarkBufferDirty(buffer);
105105

106-
if (!index->rd_istemp)
106+
if (RelationNeedsWAL(index))
107107
{
108108
XLogRecData rdata[2];
109109
ginxlogInsertListPage data;
@@ -384,7 +384,7 @@ ginHeapTupleFastInsert(Relation index, GinState *ginstate,
384384
*/
385385
MarkBufferDirty(metabuffer);
386386

387-
if (!index->rd_istemp)
387+
if (RelationNeedsWAL(index))
388388
{
389389
XLogRecPtr recptr;
390390

@@ -564,7 +564,7 @@ shiftList(Relation index, Buffer metabuffer, BlockNumber newHead,
564564
MarkBufferDirty(buffers[i]);
565565
}
566566

567-
if (!index->rd_istemp)
567+
if (RelationNeedsWAL(index))
568568
{
569569
XLogRecPtr recptr;
570570

src/backend/access/gin/gininsert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems)
5555

5656
MarkBufferDirty(buffer);
5757

58-
if (!index->rd_istemp)
58+
if (RelationNeedsWAL(index))
5959
{
6060
XLogRecPtr recptr;
6161
XLogRecData rdata[2];
@@ -325,7 +325,7 @@ ginbuild(PG_FUNCTION_ARGS)
325325
GinInitBuffer(RootBuffer, GIN_LEAF);
326326
MarkBufferDirty(RootBuffer);
327327

328-
if (!index->rd_istemp)
328+
if (RelationNeedsWAL(index))
329329
{
330330
XLogRecPtr recptr;
331331
XLogRecData rdata;

src/backend/access/gin/ginutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ ginUpdateStats(Relation index, const GinStatsData *stats)
410410

411411
MarkBufferDirty(metabuffer);
412412

413-
if (!index->rd_istemp)
413+
if (RelationNeedsWAL(index))
414414
{
415415
XLogRecPtr recptr;
416416
ginxlogUpdateMeta data;

src/backend/access/gin/ginvacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ xlogVacuumPage(Relation index, Buffer buffer)
9393

9494
Assert(GinPageIsLeaf(page));
9595

96-
if (index->rd_istemp)
96+
if (!RelationNeedsWAL(index))
9797
return;
9898

9999
data.node = index->rd_node;
@@ -308,7 +308,7 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn
308308
MarkBufferDirty(lBuffer);
309309
MarkBufferDirty(dBuffer);
310310

311-
if (!gvs->index->rd_istemp)
311+
if (RelationNeedsWAL(gvs->index))
312312
{
313313
XLogRecPtr recptr;
314314
XLogRecData rdata[4];

src/backend/access/gist/gist.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ gistbuild(PG_FUNCTION_ARGS)
115115

116116
MarkBufferDirty(buffer);
117117

118-
if (!index->rd_istemp)
118+
if (RelationNeedsWAL(index))
119119
{
120120
XLogRecPtr recptr;
121121
XLogRecData rdata;
@@ -401,7 +401,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
401401
dist->page = BufferGetPage(dist->buffer);
402402
}
403403

404-
if (!state->r->rd_istemp)
404+
if (RelationNeedsWAL(state->r))
405405
{
406406
XLogRecPtr recptr;
407407
XLogRecData *rdata;
@@ -465,7 +465,7 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
465465

466466
MarkBufferDirty(state->stack->buffer);
467467

468-
if (!state->r->rd_istemp)
468+
if (RelationNeedsWAL(state->r))
469469
{
470470
OffsetNumber noffs = 0,
471471
offs[1];
@@ -550,7 +550,7 @@ gistfindleaf(GISTInsertState *state, GISTSTATE *giststate)
550550
opaque = GistPageGetOpaque(state->stack->page);
551551

552552
state->stack->lsn = PageGetLSN(state->stack->page);
553-
Assert(state->r->rd_istemp || !XLogRecPtrIsInvalid(state->stack->lsn));
553+
Assert(!RelationNeedsWAL(state->r) || !XLogRecPtrIsInvalid(state->stack->lsn));
554554

555555
if (state->stack->blkno != GIST_ROOT_BLKNO &&
556556
XLByteLT(state->stack->parent->lsn, opaque->nsn))
@@ -911,7 +911,7 @@ gistmakedeal(GISTInsertState *state, GISTSTATE *giststate)
911911
}
912912

913913
/* say to xlog that insert is completed */
914-
if (state->needInsertComplete && !state->r->rd_istemp)
914+
if (state->needInsertComplete && RelationNeedsWAL(state->r))
915915
gistxlogInsertCompletion(state->r->rd_node, &(state->key), 1);
916916
}
917917

@@ -1011,7 +1011,7 @@ gistnewroot(Relation r, Buffer buffer, IndexTuple *itup, int len, ItemPointer ke
10111011

10121012
MarkBufferDirty(buffer);
10131013

1014-
if (!r->rd_istemp)
1014+
if (RelationNeedsWAL(r))
10151015
{
10161016
XLogRecPtr recptr;
10171017
XLogRecData *rdata;

src/backend/access/gist/gistvacuum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ gistbulkdelete(PG_FUNCTION_ARGS)
248248
PageIndexTupleDelete(page, todelete[i]);
249249
GistMarkTuplesDeleted(page);
250250

251-
if (!rel->rd_istemp)
251+
if (RelationNeedsWAL(rel))
252252
{
253253
XLogRecData *rdata;
254254
XLogRecPtr recptr;

src/backend/access/heap/heapam.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ initscan(HeapScanDesc scan, ScanKey key, bool is_rescan)
124124
*
125125
* During a rescan, don't make a new strategy object if we don't have to.
126126
*/
127-
if (!scan->rs_rd->rd_istemp &&
127+
if (!RelationUsesLocalBuffers(scan->rs_rd) &&
128128
scan->rs_nblocks > NBuffers / 4)
129129
{
130130
allow_strat = scan->rs_allow_strat;
@@ -905,7 +905,7 @@ relation_open(Oid relationId, LOCKMODE lockmode)
905905
elog(ERROR, "could not open relation with OID %u", relationId);
906906

907907
/* Make note that we've accessed a temporary relation */
908-
if (r->rd_istemp)
908+
if (RelationUsesLocalBuffers(r))
909909
MyXactAccessedTempRel = true;
910910

911911
pgstat_initstats(r);
@@ -951,7 +951,7 @@ try_relation_open(Oid relationId, LOCKMODE lockmode)
951951
elog(ERROR, "could not open relation with OID %u", relationId);
952952

953953
/* Make note that we've accessed a temporary relation */
954-
if (r->rd_istemp)
954+
if (RelationUsesLocalBuffers(r))
955955
MyXactAccessedTempRel = true;
956956

957957
pgstat_initstats(r);
@@ -1917,7 +1917,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
19171917
MarkBufferDirty(buffer);
19181918

19191919
/* XLOG stuff */
1920-
if (!(options & HEAP_INSERT_SKIP_WAL) && !relation->rd_istemp)
1920+
if (!(options & HEAP_INSERT_SKIP_WAL) && RelationNeedsWAL(relation))
19211921
{
19221922
xl_heap_insert xlrec;
19231923
xl_heap_header xlhdr;
@@ -2227,7 +2227,7 @@ heap_delete(Relation relation, ItemPointer tid,
22272227
MarkBufferDirty(buffer);
22282228

22292229
/* XLOG stuff */
2230-
if (!relation->rd_istemp)
2230+
if (RelationNeedsWAL(relation))
22312231
{
22322232
xl_heap_delete xlrec;
22332233
XLogRecPtr recptr;
@@ -2780,7 +2780,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
27802780
MarkBufferDirty(buffer);
27812781

27822782
/* XLOG stuff */
2783-
if (!relation->rd_istemp)
2783+
if (RelationNeedsWAL(relation))
27842784
{
27852785
XLogRecPtr recptr = log_heap_update(relation, buffer, oldtup.t_self,
27862786
newbuf, heaptup,
@@ -3403,7 +3403,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
34033403
* (Also, in a PITR log-shipping or 2PC environment, we have to have XLOG
34043404
* entries for everything anyway.)
34053405
*/
3406-
if (!relation->rd_istemp)
3406+
if (RelationNeedsWAL(relation))
34073407
{
34083408
xl_heap_lock xlrec;
34093409
XLogRecPtr recptr;
@@ -3505,7 +3505,7 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
35053505
MarkBufferDirty(buffer);
35063506

35073507
/* XLOG stuff */
3508-
if (!relation->rd_istemp)
3508+
if (RelationNeedsWAL(relation))
35093509
{
35103510
xl_heap_inplace xlrec;
35113511
XLogRecPtr recptr;
@@ -3867,8 +3867,8 @@ log_heap_clean(Relation reln, Buffer buffer,
38673867
XLogRecPtr recptr;
38683868
XLogRecData rdata[4];
38693869

3870-
/* Caller should not call me on a temp relation */
3871-
Assert(!reln->rd_istemp);
3870+
/* Caller should not call me on a non-WAL-logged relation */
3871+
Assert(RelationNeedsWAL(reln));
38723872

38733873
xlrec.node = reln->rd_node;
38743874
xlrec.block = BufferGetBlockNumber(buffer);
@@ -3950,8 +3950,8 @@ log_heap_freeze(Relation reln, Buffer buffer,
39503950
XLogRecPtr recptr;
39513951
XLogRecData rdata[2];
39523952

3953-
/* Caller should not call me on a temp relation */
3954-
Assert(!reln->rd_istemp);
3953+
/* Caller should not call me on a non-WAL-logged relation */
3954+
Assert(RelationNeedsWAL(reln));
39553955
/* nor when there are no tuples to freeze */
39563956
Assert(offcnt > 0);
39573957

@@ -3996,8 +3996,8 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
39963996
XLogRecData rdata[4];
39973997
Page page = BufferGetPage(newbuf);
39983998

3999-
/* Caller should not call me on a temp relation */
4000-
Assert(!reln->rd_istemp);
3999+
/* Caller should not call me on a non-WAL-logged relation */
4000+
Assert(RelationNeedsWAL(reln));
40014001

40024002
if (HeapTupleIsHeapOnly(newtup))
40034003
info = XLOG_HEAP_HOT_UPDATE;
@@ -4997,7 +4997,7 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
49974997
* heap_sync - sync a heap, for use when no WAL has been written
49984998
*
49994999
* This forces the heap contents (including TOAST heap if any) down to disk.
5000-
* If we skipped using WAL, and it's not a temp relation, we must force the
5000+
* If we skipped using WAL, and WAL is otherwise needed, we must force the
50015001
* relation down to disk before it's safe to commit the transaction. This
50025002
* requires writing out any dirty buffers and then doing a forced fsync.
50035003
*
@@ -5010,8 +5010,8 @@ heap2_desc(StringInfo buf, uint8 xl_info, char *rec)
50105010
void
50115011
heap_sync(Relation rel)
50125012
{
5013-
/* temp tables never need fsync */
5014-
if (rel->rd_istemp)
5013+
/* non-WAL-logged tables never need fsync */
5014+
if (!RelationNeedsWAL(rel))
50155015
return;
50165016

50175017
/* main heap */

src/backend/access/heap/pruneheap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ heap_page_prune(Relation relation, Buffer buffer, TransactionId OldestXmin,
233233
/*
234234
* Emit a WAL HEAP_CLEAN record showing what we did
235235
*/
236-
if (!relation->rd_istemp)
236+
if (RelationNeedsWAL(relation))
237237
{
238238
XLogRecPtr recptr;
239239

src/backend/access/heap/rewriteheap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ end_heap_rewrite(RewriteState state)
277277
}
278278

279279
/*
280-
* If the rel isn't temp, must fsync before commit. We use heap_sync to
281-
* ensure that the toast table gets fsync'd too.
280+
* If the rel is WAL-logged, must fsync before commit. We use heap_sync
281+
* to ensure that the toast table gets fsync'd too.
282282
*
283283
* It's obvious that we must do this when not WAL-logging. It's less
284284
* obvious that we have to do it even if we did WAL-log the pages. The
@@ -287,7 +287,7 @@ end_heap_rewrite(RewriteState state)
287287
* occurring during the rewriteheap operation won't have fsync'd data we
288288
* wrote before the checkpoint.
289289
*/
290-
if (!state->rs_new_rel->rd_istemp)
290+
if (RelationNeedsWAL(state->rs_new_rel))
291291
heap_sync(state->rs_new_rel);
292292

293293
/* Deleting the context frees everything */

src/backend/access/nbtree/nbtinsert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ _bt_insertonpg(Relation rel,
766766
}
767767

768768
/* XLOG stuff */
769-
if (!rel->rd_istemp)
769+
if (RelationNeedsWAL(rel))
770770
{
771771
xl_btree_insert xlrec;
772772
BlockNumber xldownlink;
@@ -1165,7 +1165,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
11651165
}
11661166

11671167
/* XLOG stuff */
1168-
if (!rel->rd_istemp)
1168+
if (RelationNeedsWAL(rel))
11691169
{
11701170
xl_btree_split xlrec;
11711171
uint8 xlinfo;
@@ -1914,7 +1914,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
19141914
MarkBufferDirty(metabuf);
19151915

19161916
/* XLOG stuff */
1917-
if (!rel->rd_istemp)
1917+
if (RelationNeedsWAL(rel))
19181918
{
19191919
xl_btree_newroot xlrec;
19201920
XLogRecPtr recptr;

src/backend/access/nbtree/nbtpage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ _bt_getroot(Relation rel, int access)
224224
MarkBufferDirty(metabuf);
225225

226226
/* XLOG stuff */
227-
if (!rel->rd_istemp)
227+
if (RelationNeedsWAL(rel))
228228
{
229229
xl_btree_newroot xlrec;
230230
XLogRecPtr recptr;
@@ -452,7 +452,7 @@ _bt_checkpage(Relation rel, Buffer buf)
452452
static void
453453
_bt_log_reuse_page(Relation rel, BlockNumber blkno, TransactionId latestRemovedXid)
454454
{
455-
if (rel->rd_istemp)
455+
if (!RelationNeedsWAL(rel))
456456
return;
457457

458458
/* No ereport(ERROR) until changes are logged */
@@ -751,7 +751,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
751751
MarkBufferDirty(buf);
752752

753753
/* XLOG stuff */
754-
if (!rel->rd_istemp)
754+
if (RelationNeedsWAL(rel))
755755
{
756756
XLogRecPtr recptr;
757757
XLogRecData rdata[2];
@@ -829,7 +829,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
829829
MarkBufferDirty(buf);
830830

831831
/* XLOG stuff */
832-
if (!rel->rd_istemp)
832+
if (RelationNeedsWAL(rel))
833833
{
834834
XLogRecPtr recptr;
835835
XLogRecData rdata[3];
@@ -1365,7 +1365,7 @@ _bt_pagedel(Relation rel, Buffer buf, BTStack stack)
13651365
MarkBufferDirty(lbuf);
13661366

13671367
/* XLOG stuff */
1368-
if (!rel->rd_istemp)
1368+
if (RelationNeedsWAL(rel))
13691369
{
13701370
xl_btree_delete_page xlrec;
13711371
xl_btree_metadata xlmeta;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy