Skip to content

Commit aa2ce2c

Browse files
committed
Fix truncate of global temp tables
1 parent c11bd35 commit aa2ce2c

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/backend/commands/sequence.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,9 @@ read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple)
11881188
/* Initialize sequence for global temporary tables */
11891189
Datum value[SEQ_COL_LASTCOL] = {0};
11901190
bool null[SEQ_COL_LASTCOL] = {false};
1191+
HeapTuple tuple;
11911192
value[SEQ_COL_LASTVAL-1] = Int64GetDatumFast(1); /* start sequence with 1 */
1192-
HeapTuple tuple = heap_form_tuple(RelationGetDescr(rel), value, null);
1193+
tuple = heap_form_tuple(RelationGetDescr(rel), value, null);
11931194
fill_seq_with_data(rel, tuple, *buf);
11941195
}
11951196

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,8 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
17731773
* table or the current physical file to be thrown away anyway.
17741774
*/
17751775
if (rel->rd_createSubid == mySubid ||
1776-
rel->rd_newRelfilenodeSubid == mySubid)
1776+
rel->rd_newRelfilenodeSubid == mySubid ||
1777+
rel->rd_rel->relpersistence == RELPERSISTENCE_SESSION)
17771778
{
17781779
/* Immediate, non-rollbackable truncation is OK */
17791780
heap_truncate_one_rel(rel);

src/backend/storage/smgr/md.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ TruncateSessionRelations(int code, Datum arg)
176176
SessionRelation* rel;
177177
for (rel = SessionRelations; rel != NULL; rel = rel->next)
178178
{
179-
/* Remove relation pages from shared buffers */
180-
DropRelFileNodesAllBuffers(&rel->rnode, 1);
181-
182179
/* Delete relation files */
183180
mdunlink(rel->rnode, InvalidForkNumber, false);
184181
}

src/include/storage/bufmgr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ extern XLogRecPtr BufferGetLSNAtomic(Buffer buffer);
205205
extern void PrintPinnedBufs(void);
206206
#endif
207207
extern Size BufferShmemSize(void);
208-
extern void BufferGetTag(Buffer buffer, RelFileNodeBackend *rnode,
208+
extern void BufferGetTag(Buffer buffer, RelFileNode *rnode,
209209
ForkNumber *forknum, BlockNumber *blknum);
210210

211211
extern void MarkBufferDirtyHint(Buffer buffer, bool buffer_std);

0 commit comments

Comments
 (0)