PostgreSQL Source Code: src/backend/access/gist/gistbuildbuffers.c File Reference (original) (raw)

Go to the source code of this file.
◆ gistAddLoadedBuffer()
◆ gistAllocateNewPageBuffer()
◆ gistBuffersGetFreeBlock()
◆ gistBuffersReleaseBlock()
| static void gistBuffersReleaseBlock ( GISTBuildBuffers * gfbb, long blocknum ) | static |
|---|
◆ gistFreeBuildBuffers()
◆ gistGetItupFromPage()
◆ gistGetNodeBuffer()
Definition at line 111 of file gistbuildbuffers.c.
113{
115 bool found;
116
117
119 &nodeBlocknum,
121 &found);
122 if (!found)
123 {
124
125
126
128
129
134 nodeBuffer->isTemp = false;
135 nodeBuffer->level = level;
136
137
138
139
140
142 {
143 int i;
144
147 (level + 1) * sizeof(List *));
148
149
153 }
154
155
156
157
158
159
160
161
162
163
164
165
168
170 }
171
172 return nodeBuffer;
173}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
List * lcons(void *datum, List *list)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
GISTNodeBufferPage * pageBuffer
References GISTNodeBuffer::blocksCount, GISTBuildBuffers::buffersOnLevels, GISTBuildBuffers::buffersOnLevelsLen, GISTBuildBuffers::context, HASH_ENTER, hash_search(), i, InvalidBlockNumber, GISTNodeBuffer::isTemp, lcons(), GISTNodeBuffer::level, MemoryContextSwitchTo(), NIL, GISTBuildBuffers::nodeBuffersTab, GISTNodeBuffer::pageBlocknum, GISTNodeBuffer::pageBuffer, GISTNodeBuffer::queuedForEmptying, and repalloc().
Referenced by gistProcessItup(), and gistRelocateBuildBuffersOnSplit().
◆ gistInitBuildBuffers()
| GISTBuildBuffers * gistInitBuildBuffers | ( | int | pagesPerBuffer, |
|---|---|---|---|
| int | levelStep, | ||
| int | maxLevel | ||
| ) |
Definition at line 44 of file gistbuildbuffers.c.
45{
48
52
53
54
55
56
59
60
64
65
66
67
68
70
71
72
73
74
79 1024,
80 &hashCtl,
82
84
85
86
87
88
92
93
94
95
96
100
102
103 return gfbb;
104}
BufFile * BufFileCreateTemp(bool interXact)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
#define palloc_object(type)
#define palloc_array(type, count)
MemoryContext CurrentMemoryContext
List * bufferEmptyingQueue
References GISTBuildBuffers::bufferEmptyingQueue, GISTBuildBuffers::buffersOnLevels, GISTBuildBuffers::buffersOnLevelsLen, BufFileCreateTemp(), GISTBuildBuffers::context, CurrentMemoryContext, HASHCTL::entrysize, GISTBuildBuffers::freeBlocks, GISTBuildBuffers::freeBlocksLen, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASHCTL::hcxt, HASHCTL::keysize, GISTBuildBuffers::levelStep, GISTBuildBuffers::loadedBuffers, GISTBuildBuffers::loadedBuffersCount, GISTBuildBuffers::loadedBuffersLen, GISTBuildBuffers::nFileBlocks, GISTBuildBuffers::nFreeBlocks, NIL, GISTBuildBuffers::nodeBuffersTab, GISTBuildBuffers::pagesPerBuffer, palloc_array, palloc_object, GISTBuildBuffers::pfile, and GISTBuildBuffers::rootlevel.
Referenced by gistInitBuffering().
◆ gistLoadNodeBuffer()
Definition at line 219 of file gistbuildbuffers.c.
220{
221
223 {
224
226
227
230
231
233
234
237 }
238}
static void gistBuffersReleaseBlock(GISTBuildBuffers *gfbb, long blocknum)
static void gistAddLoadedBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer)
static GISTNodeBufferPage * gistAllocateNewPageBuffer(GISTBuildBuffers *gfbb)
static void ReadTempFileBlock(BufFile *file, long blknum, void *ptr)
References GISTNodeBuffer::blocksCount, gistAddLoadedBuffer(), gistAllocateNewPageBuffer(), gistBuffersReleaseBlock(), InvalidBlockNumber, GISTNodeBuffer::pageBlocknum, GISTNodeBuffer::pageBuffer, GISTBuildBuffers::pfile, and ReadTempFileBlock().
Referenced by gistPopItupFromNodeBuffer(), and gistPushItupToNodeBuffer().
◆ gistPlaceItupToPage()
◆ gistPopItupFromNodeBuffer()
Definition at line 404 of file gistbuildbuffers.c.
406{
407
408
409
411 return false;
412
413
416
417
418
419
421
422
423
424
425
427 {
429
430
431
432
434
435
436
437
440 {
441
444
445
446
447
448
450 }
451 else
452 {
453
457 }
458 }
459 return true;
460}
static void gistLoadNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer)
static void gistGetItupFromPage(GISTNodeBufferPage *pageBuffer, IndexTuple *itup)
void pfree(void *pointer)
References Assert(), GISTNodeBuffer::blocksCount, gistBuffersReleaseBlock(), gistGetItupFromPage(), gistLoadNodeBuffer(), InvalidBlockNumber, PAGE_IS_EMPTY, GISTNodeBuffer::pageBuffer, GISTBuildBuffers::pfile, pfree(), GISTNodeBufferPage::prev, and ReadTempFileBlock().
Referenced by gistProcessEmptyingQueue(), and gistRelocateBuildBuffersOnSplit().
◆ gistPushItupToNodeBuffer()
Definition at line 334 of file gistbuildbuffers.c.
336{
337
338
339
340
342
343
344
345
347 {
351 }
352
353
356
357
358
359
361 {
362
363
364
366
367
370
371
372
373
374
378
379
381 }
382
384
385
386
387
389 {
393 }
394
395
397}
#define BUFFER_HALF_FILLED(nodeBuffer, gfbb)
#define PAGE_NO_SPACE(nbp, itup)
static void WriteTempFileBlock(BufFile *file, long blknum, const void *ptr)
static void gistPlaceItupToPage(GISTNodeBufferPage *pageBuffer, IndexTuple itup)
static long gistBuffersGetFreeBlock(GISTBuildBuffers *gfbb)
References GISTNodeBuffer::blocksCount, BUFFER_HALF_FILLED, GISTBuildBuffers::bufferEmptyingQueue, GISTBuildBuffers::context, gistAddLoadedBuffer(), gistAllocateNewPageBuffer(), gistBuffersGetFreeBlock(), gistLoadNodeBuffer(), gistPlaceItupToPage(), lcons(), MAXALIGN, MemoryContextSwitchTo(), PAGE_FREE_SPACE, PAGE_NO_SPACE, GISTNodeBuffer::pageBuffer, GISTBuildBuffers::pfile, GISTNodeBufferPage::prev, GISTNodeBuffer::queuedForEmptying, and WriteTempFileBlock().
Referenced by gistProcessItup(), and gistRelocateBuildBuffersOnSplit().
◆ gistRelocateBuildBuffersOnSplit()
Definition at line 531 of file gistbuildbuffers.c.
534{
536 bool found;
540 int splitPagesCount = 0;
545
546
548 return;
549
550
551
552
556 if (!found)
557 {
558
559 return;
560 }
561
562
563
564
565
566
567
568
569
572 oldBuf.isTemp = true;
573
574
578
579
580
581
582 splitPagesCount = list_length(splitinfo);
584
585
586
587
588
589 foreach(lc, splitinfo)
590 {
594
595
598 relocationBuffersInfos[i].entry,
599 relocationBuffersInfos[i].isnull);
600
601
602
603
604
605
606
607
609
610 relocationBuffersInfos[i].nodeBuffer = newNodeBuffer;
611 relocationBuffersInfos[i].splitinfo = si;
612 }
613
614
615
616
617
618
619
620
621
622
624 {
626 int i,
627 which;
630
632 itup, NULL, (OffsetNumber) 0, entry, isnull);
633
634
635 which = 0;
636
637
638
639
640
641
642 best_penalty[0] = -1;
643
644
645
646
647
648 for (i = 0; i < splitPagesCount; i++)
649 {
651 bool zero_penalty;
652 int j;
653
654 zero_penalty = true;
655
656
658 {
659 float usize;
660
661
666 if (usize > 0)
667 zero_penalty = false;
668
669 if (best_penalty[j] < 0 || usize < best_penalty[j])
670 {
671
672
673
674
675
676
677
678
679
680 which = i;
681 best_penalty[j] = usize;
682
684 best_penalty[j + 1] = -1;
685 }
686 else if (best_penalty[j] == usize)
687 {
688
689
690
691
692
693 }
694 else
695 {
696
697
698
699
700
701 zero_penalty = false;
702 break;
703 }
704 }
705
706
707
708
709
710
711 if (zero_penalty)
712 break;
713 }
714
715
716 targetBufferInfo = &relocationBuffersInfos[which];
717
718
720
721
723 itup, giststate);
724 if (newtup)
725 {
728 targetBufferInfo->entry,
729 targetBufferInfo->isnull);
730
732 }
733 }
734
735 pfree(relocationBuffersInfos);
736}
BlockNumber BufferGetBlockNumber(Buffer buffer)
#define LEVEL_HAS_BUFFERS(nlevel, gfbb)
void gistPushItupToNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple itup)
bool gistPopItupFromNodeBuffer(GISTBuildBuffers *gfbb, GISTNodeBuffer *nodeBuffer, IndexTuple *itup)
GISTNodeBuffer * gistGetNodeBuffer(GISTBuildBuffers *gfbb, GISTSTATE *giststate, BlockNumber nodeBlocknum, int level)
void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, OffsetNumber o, GISTENTRY *attdata, bool *isnull)
IndexTuple gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
float gistpenalty(GISTSTATE *giststate, int attno, GISTENTRY *orig, bool isNullOrig, GISTENTRY *add, bool isNullAdd)
static int list_length(const List *l)
#define foreach_current_index(var_or_cell)
#define IndexRelationGetNumberOfKeyAttributes(relation)
bool isnull[INDEX_MAX_KEYS]
GISTPageSplitInfo * splitinfo
GISTNodeBuffer * nodeBuffer
GISTENTRY entry[INDEX_MAX_KEYS]
References Assert(), GISTNodeBuffer::blocksCount, GISTPageSplitInfo::buf, BufferGetBlockNumber(), GISTPageSplitInfo::downlink, RelocationBufferInfo::entry, foreach_current_index, GIST_ROOT_BLKNO, gistDeCompressAtt(), gistgetadjusted(), gistGetNodeBuffer(), gistpenalty(), gistPopItupFromNodeBuffer(), gistPushItupToNodeBuffer(), HASH_FIND, hash_search(), i, INDEX_MAX_KEYS, IndexRelationGetNumberOfKeyAttributes, InvalidBlockNumber, RelocationBufferInfo::isnull, GISTNodeBuffer::isTemp, j, LEVEL_HAS_BUFFERS, lfirst, list_length(), RelocationBufferInfo::nodeBuffer, GISTBuildBuffers::nodeBuffersTab, GISTNodeBuffer::pageBlocknum, GISTNodeBuffer::pageBuffer, palloc_array, pfree(), and RelocationBufferInfo::splitinfo.
Referenced by gistbufferinginserttuples().
◆ gistUnloadNodeBuffer()
◆ gistUnloadNodeBuffers()
◆ ReadTempFileBlock()
| static void ReadTempFileBlock ( BufFile * file, long blknum, void * ptr ) | static |
|---|
◆ WriteTempFileBlock()
| static void WriteTempFileBlock ( BufFile * file, long blknum, const void * ptr ) | static |
|---|