Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3a3bd25

Browse files
committed
Support all indexes for global temp tables
1 parent f46e3a2 commit 3a3bd25

File tree

7 files changed

+72
-14
lines changed

7 files changed

+72
-14
lines changed

src/backend/access/brin/brin_revmap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "access/brin_revmap.h"
2626
#include "access/brin_tuple.h"
2727
#include "access/brin_xlog.h"
28+
#include "access/brin.h"
2829
#include "access/rmgr.h"
2930
#include "access/xloginsert.h"
3031
#include "miscadmin.h"
@@ -79,6 +80,11 @@ brinRevmapInitialize(Relation idxrel, BlockNumber *pagesPerRange,
7980
meta = ReadBuffer(idxrel, BRIN_METAPAGE_BLKNO);
8081
LockBuffer(meta, BUFFER_LOCK_SHARE);
8182
page = BufferGetPage(meta);
83+
84+
if (GlobalTempRelationPageIsNotInitialized(idxrel, page))
85+
brin_metapage_init(page, BrinGetPagesPerRange(idxrel),
86+
BRIN_CURRENT_VERSION);
87+
8288
TestForOldSnapshot(snapshot, idxrel, page);
8389
metadata = (BrinMetaPageData *) PageGetContents(page);
8490

src/backend/access/gin/ginfast.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
241241
metabuffer = ReadBuffer(index, GIN_METAPAGE_BLKNO);
242242
metapage = BufferGetPage(metabuffer);
243243

244+
if (GlobalTempRelationPageIsNotInitialized(index, metapage))
245+
{
246+
Buffer rootbuffer = ReadBuffer(index, GIN_ROOT_BLKNO);
247+
LockBuffer(rootbuffer, BUFFER_LOCK_EXCLUSIVE);
248+
GinInitMetabuffer(metabuffer);
249+
GinInitBuffer(rootbuffer, GIN_LEAF);
250+
MarkBufferDirty(rootbuffer);
251+
UnlockReleaseBuffer(rootbuffer);
252+
}
253+
244254
/*
245255
* An insertion to the pending list could logically belong anywhere in the
246256
* tree, so it conflicts with all serializable scans. All scans acquire a

src/backend/access/gin/ginget.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ collectMatchesForHeapRow(IndexScanDesc scan, pendingPosition *pos)
17501750
/*
17511751
* Collect all matched rows from pending list into bitmap.
17521752
*/
1753-
static void
1753+
static bool
17541754
scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
17551755
{
17561756
GinScanOpaque so = (GinScanOpaque) scan->opaque;
@@ -1774,6 +1774,12 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
17741774
LockBuffer(metabuffer, GIN_SHARE);
17751775
page = BufferGetPage(metabuffer);
17761776
TestForOldSnapshot(scan->xs_snapshot, scan->indexRelation, page);
1777+
1778+
if (GlobalTempRelationPageIsNotInitialized(scan->indexRelation, page))
1779+
{
1780+
UnlockReleaseBuffer(metabuffer);
1781+
return false;
1782+
}
17771783
blkno = GinPageGetMeta(page)->head;
17781784

17791785
/*
@@ -1784,7 +1790,7 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
17841790
{
17851791
/* No pending list, so proceed with normal scan */
17861792
UnlockReleaseBuffer(metabuffer);
1787-
return;
1793+
return true;
17881794
}
17891795

17901796
pos.pendingBuffer = ReadBuffer(scan->indexRelation, blkno);
@@ -1840,6 +1846,7 @@ scanPendingInsert(IndexScanDesc scan, TIDBitmap *tbm, int64 *ntids)
18401846
}
18411847

18421848
pfree(pos.hasMatchKey);
1849+
return true;
18431850
}
18441851

18451852

@@ -1875,7 +1882,8 @@ gingetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
18751882
* to scan the main index before the pending list, since concurrent
18761883
* cleanup could then make us miss entries entirely.
18771884
*/
1878-
scanPendingInsert(scan, tbm, &ntids);
1885+
if (!scanPendingInsert(scan, tbm, &ntids))
1886+
return 0;
18791887

18801888
/*
18811889
* Now scan the main index.

src/backend/access/gist/gist.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,10 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace,
677677
if (!xlocked)
678678
{
679679
LockBuffer(stack->buffer, GIST_SHARE);
680-
gistcheckpage(state.r, stack->buffer);
680+
if (stack->blkno == GIST_ROOT_BLKNO && GlobalTempRelationPageIsNotInitialized(state.r, BufferGetPage(stack->buffer)))
681+
GISTInitBuffer(stack->buffer, F_LEAF);
682+
else
683+
gistcheckpage(state.r, stack->buffer);
681684
}
682685

683686
stack->page = (Page) BufferGetPage(stack->buffer);

src/backend/access/gist/gistget.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,10 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem, double *myDistances,
339339
buffer = ReadBuffer(scan->indexRelation, pageItem->blkno);
340340
LockBuffer(buffer, GIST_SHARE);
341341
PredicateLockPage(r, BufferGetBlockNumber(buffer), scan->xs_snapshot);
342-
gistcheckpage(scan->indexRelation, buffer);
342+
if (pageItem->blkno == GIST_ROOT_BLKNO && GlobalTempRelationPageIsNotInitialized(r, BufferGetPage(buffer)))
343+
GISTInitBuffer(buffer, F_LEAF);
344+
else
345+
gistcheckpage(scan->indexRelation, buffer);
343346
page = BufferGetPage(buffer);
344347
TestForOldSnapshot(scan->xs_snapshot, r, page);
345348
opaque = GistPageGetOpaque(page);

src/backend/access/hash/hashpage.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ _hash_getbuf(Relation rel, BlockNumber blkno, int access, int flags)
7575

7676
buf = ReadBuffer(rel, blkno);
7777

78-
if (access != HASH_NOLOCK)
79-
LockBuffer(buf, access);
80-
8178
/* ref count and lock type are correct */
8279

83-
_hash_checkpage(rel, buf, flags);
84-
80+
if (blkno == HASH_METAPAGE && GlobalTempRelationPageIsNotInitialized(rel, BufferGetPage(buf)))
81+
{
82+
_hash_init(rel, 0, MAIN_FORKNUM);
83+
if (access != HASH_NOLOCK)
84+
LockBuffer(buf, access);
85+
}
86+
else
87+
{
88+
if (access != HASH_NOLOCK)
89+
LockBuffer(buf, access);
90+
_hash_checkpage(rel, buf, flags);
91+
}
8592
return buf;
8693
}
8794

@@ -339,7 +346,7 @@ _hash_init(Relation rel, double num_tuples, ForkNumber forkNum)
339346
bool use_wal;
340347

341348
/* safety check */
342-
if (RelationGetNumberOfBlocksInFork(rel, forkNum) != 0)
349+
if (rel->rd_rel->relpersistence != RELPERSISTENCE_SESSION && RelationGetNumberOfBlocksInFork(rel, forkNum) != 0)
343350
elog(ERROR, "cannot initialize non-empty hash index \"%s\"",
344351
RelationGetRelationName(rel));
345352

src/backend/access/spgist/spgutils.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ spgGetCache(Relation index)
106106
spgConfigIn in;
107107
FmgrInfo *procinfo;
108108
Buffer metabuffer;
109+
Page metapage;
109110
SpGistMetaPageData *metadata;
110111

111112
cache = MemoryContextAllocZero(index->rd_indexcxt,
@@ -155,12 +156,32 @@ spgGetCache(Relation index)
155156
metabuffer = ReadBuffer(index, SPGIST_METAPAGE_BLKNO);
156157
LockBuffer(metabuffer, BUFFER_LOCK_SHARE);
157158

158-
metadata = SpGistPageGetMeta(BufferGetPage(metabuffer));
159+
metapage = BufferGetPage(metabuffer);
160+
metadata = SpGistPageGetMeta(metapage);
159161

160162
if (metadata->magicNumber != SPGIST_MAGIC_NUMBER)
161-
elog(ERROR, "index \"%s\" is not an SP-GiST index",
162-
RelationGetRelationName(index));
163+
{
164+
if (GlobalTempRelationPageIsNotInitialized(index, metapage))
165+
{
166+
Buffer rootbuffer = ReadBuffer(index, SPGIST_ROOT_BLKNO);
167+
Buffer nullbuffer = ReadBuffer(index, SPGIST_NULL_BLKNO);
168+
169+
SpGistInitMetapage(metapage);
170+
171+
LockBuffer(rootbuffer, BUFFER_LOCK_EXCLUSIVE);
172+
SpGistInitPage(BufferGetPage(rootbuffer), SPGIST_LEAF);
173+
MarkBufferDirty(rootbuffer);
174+
UnlockReleaseBuffer(rootbuffer);
163175

176+
LockBuffer(nullbuffer, BUFFER_LOCK_EXCLUSIVE);
177+
SpGistInitPage(BufferGetPage(nullbuffer), SPGIST_LEAF | SPGIST_NULLS);
178+
MarkBufferDirty(nullbuffer);
179+
UnlockReleaseBuffer(nullbuffer);
180+
}
181+
else
182+
elog(ERROR, "index \"%s\" is not an SP-GiST index",
183+
RelationGetRelationName(index));
184+
}
164185
cache->lastUsedPages = metadata->lastUsedPages;
165186

166187
UnlockReleaseBuffer(metabuffer);

0 commit comments

Comments
 (0)