Skip to content

Commit e525ef8

Browse files
committed
Some refactorting based on Craig Ringer review
1 parent 69910cd commit e525ef8

File tree

7 files changed

+25
-11
lines changed

7 files changed

+25
-11
lines changed

src/backend/access/gist/gistutil.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ gistGetFakeLSN(Relation rel)
10281028
{
10291029
static XLogRecPtr counter = FirstNormalUnloggedLSN;
10301030

1031-
if (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP ||
1032-
rel->rd_rel->relpersistence == RELPERSISTENCE_SESSION)
1031+
if (RelationHasSessionScope(rel))
10331032
{
10341033
/*
10351034
* Temporary relations are only accessible in our session, so a simple

src/backend/access/nbtree/nbtpage.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ _bt_getbuf(Relation rel, BlockNumber blkno, int access)
764764
buf = ReadBuffer(rel, blkno);
765765
LockBuffer(buf, access);
766766
/* Session temporary relation may be not yet initialized for this backend. */
767-
if (blkno == BTREE_METAPAGE && PageIsNew(BufferGetPage(buf)) && IsSessionRelationBackendId(rel->rd_backend))
767+
if (blkno == BTREE_METAPAGE && GlobalTempRelationPageIsNotInitialized(rel, BufferGetPage(buf)))
768768
_bt_initmetapage(BufferGetPage(buf), P_NONE, 0);
769769
else
770770
_bt_checkpage(rel, buf);

src/backend/commands/sequence.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple)
11831183
LockBuffer(*buf, BUFFER_LOCK_EXCLUSIVE);
11841184

11851185
page = BufferGetPage(*buf);
1186-
if (rel->rd_rel->relpersistence == RELPERSISTENCE_SESSION && PageIsNew(page))
1186+
if (GlobalTempRelationPageIsNotInitialized(rel, page))
11871187
{
11881188
/* Initialize sequence for global temporary tables */
11891189
Datum value[SEQ_COL_LASTCOL] = {0};

src/backend/commands/tablecmds.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
586586
* Check consistency of arguments
587587
*/
588588
if (stmt->oncommit != ONCOMMIT_NOOP
589-
&& stmt->relation->relpersistence != RELPERSISTENCE_TEMP
590-
&& stmt->relation->relpersistence != RELPERSISTENCE_SESSION)
589+
&& !IsLocalRelpersistence(stmt->relation->relpersistence))
591590
ereport(ERROR,
592591
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
593592
errmsg("ON COMMIT can only be used on temporary tables")));

src/backend/postmaster/autovacuum.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,7 @@ do_autovacuum(void)
20692069
* Check if it is a temp table (presumably, of some other backend's).
20702070
* We cannot safely process other backends' temp tables.
20712071
*/
2072-
if (classForm->relpersistence == RELPERSISTENCE_TEMP ||
2073-
classForm->relpersistence == RELPERSISTENCE_SESSION)
2072+
if (IsLocalRelpersistence(classForm->relpersistence))
20742073
{
20752074
/*
20762075
* We just ignore it if the owning backend is still active and
@@ -2155,8 +2154,7 @@ do_autovacuum(void)
21552154
/*
21562155
* We cannot safely process other backends' temp tables, so skip 'em.
21572156
*/
2158-
if (classForm->relpersistence == RELPERSISTENCE_TEMP ||
2159-
classForm->relpersistence == RELPERSISTENCE_SESSION)
2157+
if (IsLocalRelpersistence(classForm->relpersistence))
21602158
continue;
21612159

21622160
relid = classForm->oid;

src/include/storage/bufpage.h

+7
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ typedef PageHeaderData *PageHeader;
228228
*/
229229
#define PageIsNew(page) (((PageHeader) (page))->pd_upper == 0)
230230

231+
/*
232+
* Page of temporary relation is not initialized
233+
*/
234+
#define GlobalTempRelationPageIsNotInitialized(rel, page) \
235+
((rel)->rd_rel->relpersistence == RELPERSISTENCE_SESSION && PageIsNew(page))
236+
237+
231238
/*
232239
* PageGetItemId
233240
* Returns an item identifier of a page.

src/include/utils/rel.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ typedef struct StdRdOptions
328328
((relation)->rd_options ? \
329329
((StdRdOptions *) (relation)->rd_options)->parallel_workers : (defaultpw))
330330

331+
/*
332+
* Relation persistence is either TEMP either SESSION
333+
*/
334+
#define IsLocalRelpersistence(relpersistence) \
335+
((relpersistence) == RELPERSISTENCE_TEMP || (relpersistence) == RELPERSISTENCE_SESSION)
336+
337+
/*
338+
* Relation is either global either local temp table
339+
*/
340+
#define RelationHasSessionScope(relation) \
341+
IsLocalRelpersistence(((relation)->rd_rel->relpersistence))
331342

332343
/*
333344
* ViewOptions
@@ -524,7 +535,7 @@ typedef struct ViewOptions
524535
* True if relation's pages are stored in local buffers.
525536
*/
526537
#define RelationUsesLocalBuffers(relation) \
527-
((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP)
538+
RelationHasSessionScope(relation)
528539

529540
/*
530541
* RELATION_IS_LOCAL

0 commit comments

Comments
 (0)