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 113 of file gistbuildbuffers.c.
115{
117 bool found;
118
119
121 &nodeBlocknum,
123 &found);
124 if (!found)
125 {
126
127
128
130
131
136 nodeBuffer->isTemp = false;
137 nodeBuffer->level = level;
138
139
140
141
142
144 {
145 int i;
146
149 (level + 1) * sizeof(List *));
150
151
155 }
156
157
158
159
160
161
162
163
164
165
166
167
170
172 }
173
174 return nodeBuffer;
175}
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
93
94
95
96
97
102
104
105 return gfbb;
106}
BufFile * BufFileCreateTemp(bool interXact)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
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(), GISTBuildBuffers::pfile, and GISTBuildBuffers::rootlevel.
Referenced by gistInitBuffering().
◆ gistLoadNodeBuffer()
Definition at line 221 of file gistbuildbuffers.c.
222{
223
225 {
226
228
229
232
233
235
236
239 }
240}
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 406 of file gistbuildbuffers.c.
408{
409
410
411
413 return false;
414
415
418
419
420
421
423
424
425
426
427
429 {
431
432
433
434
436
437
438
439
442 {
443
446
447
448
449
450
452 }
453 else
454 {
455
459 }
460 }
461 return true;
462}
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 336 of file gistbuildbuffers.c.
338{
339
340
341
342
344
345
346
347
349 {
353 }
354
355
358
359
360
361
363 {
364
365
366
368
369
372
373
374
375
376
380
381
383 }
384
386
387
388
389
391 {
395 }
396
397
399}
#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 533 of file gistbuildbuffers.c.
536{
538 bool found;
542 int splitPagesCount = 0;
547
548
550 return;
551
552
553
554
558 if (!found)
559 {
560
561 return;
562 }
563
564
565
566
567
568
569
570
571
574 oldBuf.isTemp = true;
575
576
580
581
582
583
584 splitPagesCount = list_length(splitinfo);
585 relocationBuffersInfos =
587 splitPagesCount);
588
589
590
591
592
593 foreach(lc, splitinfo)
594 {
598
599
602 relocationBuffersInfos[i].entry,
603 relocationBuffersInfos[i].isnull);
604
605
606
607
608
609
610
611
613
614 relocationBuffersInfos[i].nodeBuffer = newNodeBuffer;
615 relocationBuffersInfos[i].splitinfo = si;
616 }
617
618
619
620
621
622
623
624
625
626
628 {
630 int i,
631 which;
634
636 itup, NULL, (OffsetNumber) 0, entry, isnull);
637
638
639 which = 0;
640
641
642
643
644
645
646 best_penalty[0] = -1;
647
648
649
650
651
652 for (i = 0; i < splitPagesCount; i++)
653 {
655 bool zero_penalty;
656 int j;
657
658 zero_penalty = true;
659
660
662 {
663 float usize;
664
665
670 if (usize > 0)
671 zero_penalty = false;
672
673 if (best_penalty[j] < 0 || usize < best_penalty[j])
674 {
675
676
677
678
679
680
681
682
683
684 which = i;
685 best_penalty[j] = usize;
686
688 best_penalty[j + 1] = -1;
689 }
690 else if (best_penalty[j] == usize)
691 {
692
693
694
695
696
697 }
698 else
699 {
700
701
702
703
704
705 zero_penalty = false;
706 break;
707 }
708 }
709
710
711
712
713
714
715 if (zero_penalty)
716 break;
717 }
718
719
720 targetBufferInfo = &relocationBuffersInfos[which];
721
722
724
725
727 itup, giststate);
728 if (newtup)
729 {
732 targetBufferInfo->entry,
733 targetBufferInfo->isnull);
734
736 }
737 }
738
739 pfree(relocationBuffersInfos);
740}
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(), 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 |
---|