Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b8b942

Browse files
author
Artur Zakirov
committed
Added comments to rumget.c
1 parent353ea47 commit6b8b942

File tree

3 files changed

+93
-30
lines changed

3 files changed

+93
-30
lines changed

‎rum.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ typedef signed char RumNullCategory;
259259

260260
typedefstruct
261261
{
262-
ItemPointerDataiptr;
263-
OffsetNumberoffsetNumer;
264-
uint16pageOffset;
262+
ItemPointerDataiptr;
263+
OffsetNumberoffsetNumer;
264+
uint16pageOffset;
265265
}RumDataLeafItemIndex;
266266

267267
#defineRumDataLeafIndexCount 32

‎rumbtree.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ rumPrepareFindLeafPage(RumBtree btree, BlockNumber blkno)
7272
RumBtreeStack*
7373
rumReFindLeafPage(RumBtreebtree,RumBtreeStack*stack)
7474
{
75+
/*
76+
* Traverse the tree upwards until we sure that requested leaf page is
77+
* in this subtree. Or we can stop at root page.
78+
*/
7579
while (stack->parent)
7680
{
7781
RumBtreeStack*ptr;
@@ -90,6 +94,11 @@ rumReFindLeafPage(RumBtree btree, RumBtreeStack *stack)
9094
page=BufferGetPage(stack->buffer);
9195
maxoff=RumPageGetOpaque(page)->maxoff;
9296

97+
/*
98+
* We don't know right bound of rightmost pointer. So, we can be sure
99+
* that requested leaf page is in this subtree only when requested item
100+
* pointer is less than item pointer previous to rightmost.
101+
*/
93102
if (rumCompareItemPointers(
94103
&(((PostingItem*)RumDataPageGetItem(page,maxoff-1))->key),
95104
&btree->items[btree->curitem].iptr) >=0)
@@ -98,6 +107,7 @@ rumReFindLeafPage(RumBtree btree, RumBtreeStack *stack)
98107
}
99108
}
100109

110+
/* Traverse tree downwards. */
101111
stack=rumFindLeafPage(btree,stack);
102112
returnstack;
103113
}

‎rumget.c

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ callConsistentFn(RumState *rumstate, RumScanKey key)
8080

8181
if (res&&key->attnum==rumstate->attrnAddToColumn)
8282
{
83-
inti;
83+
uint32i;
8484

8585
/* remember some addinfo value for later ordering by addinfo
8686
from another column */
8787

8888
key->outerAddInfoIsNull= true;
8989

90-
for(i=0;i<key->nuserentries;i++)
90+
for(i=0;i<key->nuserentries;i++)
9191
{
9292
if (key->entryRes[i]&&key->addInfoIsNull[0]== false)
9393
{
@@ -571,6 +571,10 @@ startScanKey(RumState *rumstate, RumScanKey key)
571571
key->isFinished= false;
572572
}
573573

574+
/*
575+
* Compare entries position. At first consider isFinished flag, then compare
576+
* item pointers.
577+
*/
574578
staticint
575579
cmpEntries(RumScanEntrye1,RumScanEntrye2)
576580
{
@@ -670,6 +674,10 @@ startScan(IndexScanDesc scan)
670674

671675
if (useFastScan)
672676
{
677+
/*
678+
* We are going to use fast scan. Do some preliminaries. Start scan
679+
* of each entry and sort entries by descending item pointers.
680+
*/
673681
so->sortedEntries= (RumScanEntry*)palloc(sizeof(RumScanEntry)*
674682
so->totalentries);
675683
memcpy(so->sortedEntries,so->entries,sizeof(RumScanEntry)*
@@ -1237,15 +1245,21 @@ scanGetItemRegular(IndexScanDesc scan, ItemPointer advancePast,
12371245
return TRUE;
12381246
}
12391247

1248+
/*
1249+
* Finds part of page containing requested item using small index at the end
1250+
* of page.
1251+
*/
12401252
staticbool
1241-
scanPage(RumState*rumstate,RumScanEntryentry,ItemPointeritem,Pagepage,boolequalOk)
1253+
scanPage(RumState*rumstate,RumScanEntryentry,ItemPointeritem,Pagepage,
1254+
boolequalOk)
12421255
{
1243-
intj;
1256+
intj;
12441257
RumKeyiter_item;
1245-
Pointerptr;
1246-
OffsetNumberfirst=FirstOffsetNumber,i,maxoff;
1247-
boolfound;
1248-
intcmp;
1258+
Pointerptr;
1259+
OffsetNumberfirst=FirstOffsetNumber,
1260+
i,maxoff;
1261+
boolfound;
1262+
intcmp;
12491263

12501264
ItemPointerSetMin(&iter_item.iptr);
12511265

@@ -1300,6 +1314,9 @@ scanPage(RumState *rumstate, RumScanEntry entry, ItemPointer item, Page page, bo
13001314
return true;
13011315
}
13021316

1317+
/*
1318+
* Find item pointer of entry with is greater or equal to given item pointer.
1319+
*/
13031320
staticvoid
13041321
entryFindItem(RumState*rumstate,RumScanEntryentry,RumKey*item)
13051322
{
@@ -1311,6 +1328,7 @@ entryFindItem(RumState *rumstate, RumScanEntry entry, RumKey *item)
13111328
return;
13121329
}
13131330

1331+
/* Try to find in loaded part of page */
13141332
if (rumCompareItemPointers(&entry->list[entry->nlist-1].iptr,
13151333
&item->iptr) >=0)
13161334
{
@@ -1329,13 +1347,13 @@ entryFindItem(RumState *rumstate, RumScanEntry entry, RumKey *item)
13291347
}
13301348
}
13311349

1332-
13331350
if (!BufferIsValid(entry->buffer))
13341351
{
13351352
entry->isFinished= TRUE;
13361353
return;
13371354
}
13381355

1356+
/* Check rest of page */
13391357
LockBuffer(entry->buffer,RUM_SHARE);
13401358

13411359
if (scanPage(rumstate,entry,&item->iptr,
@@ -1346,6 +1364,7 @@ entryFindItem(RumState *rumstate, RumScanEntry entry, RumKey *item)
13461364
return;
13471365
}
13481366

1367+
/* Try to traverse to another leaf page */
13491368
entry->gdi->btree.items=item;
13501369
entry->gdi->btree.curitem=0;
13511370

@@ -1363,6 +1382,7 @@ entryFindItem(RumState *rumstate, RumScanEntry entry, RumKey *item)
13631382
return;
13641383
}
13651384

1385+
/* At last try to traverse by right links */
13661386
for (;;)
13671387
{
13681388
/*
@@ -1402,17 +1422,20 @@ entryFindItem(RumState *rumstate, RumScanEntry entry, RumKey *item)
14021422
}
14031423
}
14041424

1425+
/*
1426+
* Do preConsistent check for all the key where applicable.
1427+
*/
14051428
staticbool
14061429
preConsistentCheck(RumScanOpaqueso)
14071430
{
1408-
RumState*rumstate=&so->rumstate;
1409-
inti,j;
1410-
boolrecheck;
1431+
RumState*rumstate=&so->rumstate;
1432+
uint32i,j;
1433+
boolrecheck;
14111434

14121435
for (j=0;j<so->nkeys;j++)
14131436
{
1414-
RumScanKeykey=&so->keys[j];
1415-
boolhasFalse= false;
1437+
RumScanKeykey=&so->keys[j];
1438+
boolhasFalse= false;
14161439

14171440
if (key->orderBy)
14181441
continue;
@@ -1448,29 +1471,43 @@ preConsistentCheck(RumScanOpaque so)
14481471
return true;
14491472
}
14501473

1474+
/*
1475+
* Shift value of some entry which index in so->sortedEntries is equal or greater
1476+
* to i.
1477+
*/
14511478
staticvoid
14521479
entryShift(inti,RumScanOpaqueso,boolfind)
14531480
{
1454-
intminIndex=-1,j;
1455-
uint32minPredictNumberResult=0;
1481+
intminIndex=-1,
1482+
j;
1483+
uint32minPredictNumberResult=0;
14561484
RumState*rumstate=&so->rumstate;
14571485

1486+
/*
1487+
* It's more efficient to move entry with smallest posting list/tree. So
1488+
* find one.
1489+
*/
14581490
for (j=i;j<so->totalentries;j++)
14591491
{
1460-
if (minIndex<0||so->sortedEntries[j]->predictNumberResult<minPredictNumberResult)
1492+
if (minIndex<0||
1493+
so->sortedEntries[j]->predictNumberResult<minPredictNumberResult)
14611494
{
14621495
minIndex=j;
14631496
minPredictNumberResult=so->sortedEntries[j]->predictNumberResult;
14641497
}
14651498
}
14661499

1500+
/* Do shift of required type */
14671501
if (find)
1468-
entryFindItem(rumstate,so->sortedEntries[minIndex],&so->sortedEntries[i-1]->curItem);
1502+
entryFindItem(rumstate,so->sortedEntries[minIndex],
1503+
&so->sortedEntries[i-1]->curItem);
14691504
elseif (!so->sortedEntries[minIndex]->isFinished)
14701505
entryGetItem(rumstate,so->sortedEntries[minIndex]);
14711506

1507+
/* Restore order of so->sortedEntries */
14721508
while (minIndex>0&&
1473-
cmpEntries(so->sortedEntries[minIndex],so->sortedEntries[minIndex-1])>0)
1509+
cmpEntries(so->sortedEntries[minIndex],
1510+
so->sortedEntries[minIndex-1])>0)
14741511
{
14751512
RumScanEntrytmp;
14761513
tmp=so->sortedEntries[minIndex];
@@ -1480,13 +1517,16 @@ entryShift(int i, RumScanOpaque so, bool find)
14801517
}
14811518
}
14821519

1520+
/*
1521+
* Get next item pointer using fast scan.
1522+
*/
14831523
staticbool
14841524
scanGetItemFast(IndexScanDescscan,ItemPointeradvancePast,
1485-
ItemPointerData*item,bool*recheck)
1525+
ItemPointerData*item,bool*recheck)
14861526
{
14871527
RumScanOpaqueso= (RumScanOpaque)scan->opaque;
1488-
inti,j,k;
1489-
boolpreConsistentFalse,consistentFalse;
1528+
inti,j,k;
1529+
boolpreConsistentFalse,consistentFalse;
14901530

14911531
if (so->entriesIncrIndex >=0)
14921532
{
@@ -1496,6 +1536,10 @@ scanGetItemFast(IndexScanDesc scan, ItemPointer advancePast,
14961536

14971537
for (;;)
14981538
{
1539+
/*
1540+
* Our entries is ordered by descending of item pointers.
1541+
* The first goal is to find border where preConsistent becomes false.
1542+
*/
14991543
preConsistentFalse= false;
15001544
j=0;
15011545
k=0;
@@ -1517,6 +1561,10 @@ scanGetItemFast(IndexScanDesc scan, ItemPointer advancePast,
15171561
}
15181562
}
15191563

1564+
/*
1565+
* If we found false in preConsistent then we can safely move entries
1566+
* which was true in preConsistent argument.
1567+
*/
15201568
if (so->sortedEntries[i-1]->isFinished== TRUE)
15211569
return false;
15221570

@@ -1526,6 +1574,7 @@ scanGetItemFast(IndexScanDesc scan, ItemPointer advancePast,
15261574
continue;
15271575
}
15281576

1577+
/* Call consistent method */
15291578
consistentFalse= false;
15301579
for (i=0;i<so->nkeys;i++)
15311580
{
@@ -1563,6 +1612,7 @@ scanGetItemFast(IndexScanDesc scan, ItemPointer advancePast,
15631612
if (consistentFalse)
15641613
continue;
15651614

1615+
/* Calculate recheck from each key */
15661616
*recheck= false;
15671617
for (i=0;i<so->nkeys;i++)
15681618
{
@@ -1586,6 +1636,9 @@ scanGetItemFast(IndexScanDesc scan, ItemPointer advancePast,
15861636
return false;
15871637
}
15881638

1639+
/*
1640+
* Get next item whether using regular or fast scan.
1641+
*/
15891642
staticbool
15901643
scanGetItem(IndexScanDescscan,ItemPointeradvancePast,
15911644
ItemPointerData*item,bool*recheck)
@@ -1776,7 +1829,7 @@ collectMatchesForHeapRow(IndexScanDesc scan, pendingPosition *pos)
17761829
OffsetNumberattrnum;
17771830
Pagepage;
17781831
IndexTupleitup;
1779-
inti,
1832+
uint32i,
17801833
j;
17811834

17821835
/*
@@ -1997,7 +2050,7 @@ scanPendingInsert(IndexScanDesc scan)
19972050
MemoryContextoldCtx;
19982051
boolrecheck,
19992052
match;
2000-
inti;
2053+
uint32i;
20012054
pendingPositionpos;
20022055
Buffermetabuffer=ReadBuffer(scan->indexRelation,RUM_METAPAGE_BLKNO);
20032056
BlockNumberblkno;
@@ -2145,7 +2198,7 @@ keyGetOrdering(RumState *rumstate, MemoryContext tempCtx, RumScanKey key,
21452198
ItemPointeriptr)
21462199
{
21472200
RumScanEntryentry;
2148-
inti;
2201+
uint32i;
21492202

21502203
if (key->useAddToColumn)
21512204
{
@@ -2200,7 +2253,7 @@ static void
22002253
insertScanItem(RumScanOpaqueso,boolrecheck)
22012254
{
22022255
RumSortItem*item;
2203-
inti,j;
2256+
uint32i,j;
22042257

22052258
item= (RumSortItem*)
22062259
MemoryContextAlloc(rum_tuplesort_get_memorycontext(so->sortstate),
@@ -2297,7 +2350,7 @@ rumgettuple(IndexScanDesc scan, ScanDirection direction)
22972350
item=rum_tuplesort_getrum(so->sortstate, true,&should_free);
22982351
if (item)
22992352
{
2300-
inti,j=0;
2353+
uint32i,j=0;
23012354

23022355
scan->xs_ctup.t_self=item->iptr;
23032356
scan->xs_recheck=item->recheck;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp