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

Commitd978c8b

Browse files
committed
move forward to order by addinfo in posting tree
1 parentf6ae370 commitd978c8b

File tree

4 files changed

+89
-49
lines changed

4 files changed

+89
-49
lines changed

‎rum.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ typedef struct RumOptions
303303
#defineRUM_SHAREBUFFER_LOCK_SHARE
304304
#defineRUM_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE
305305

306-
typedefstructRumKey {
307-
ItemPointerDataipd;
308-
boolisNull;
309-
DatumaddToCompare;
310-
}RumKey;
306+
typedefstructRumEntryAccumulatorItemRumKey;
311307

312308
/*
313309
* RumState: working data structure describing the index being worked on
@@ -492,18 +488,19 @@ extern ItemPointerData updateItemIndexes(Page page, OffsetNumber attnum, RumStat
492488
externvoidcheckLeafDataPage(RumState*rumstate,AttrNumberattrnum,Pagepage);
493489

494490
/* rumdatapage.c */
495-
externintrumCompareItemPointers(ItemPointera,ItemPointerb);
496-
externintcompareRumKey(RumState*state,RumKey*a,RumKey*b);
491+
externintrumCompareItemPointers(constItemPointerData*a,constItemPointerData*b);
492+
externintcompareRumKey(RumState*state,constRumKey*a,constRumKey*b);
497493
externchar*rumDataPageLeafWriteItemPointer(char*ptr,ItemPointeriptr,ItemPointerprev,booladdInfoIsNull);
498494
externPointerrumPlaceToDataPageLeaf(Pointerptr,OffsetNumberattnum,
499495
ItemPointeriptr,DatumaddInfo,booladdInfoIsNull,ItemPointerprev,
500496
RumState*rumstate);
501497
externSizerumCheckPlaceToDataPageLeaf(OffsetNumberattnum,
502498
ItemPointeriptr,DatumaddInfo,booladdInfoIsNull,ItemPointerprev,
503499
RumState*rumstate,Sizesize);
504-
externuint32rumMergeItemPointers(ItemPointerData*dst,Datum*dst2,bool*dst3,
505-
ItemPointerData*a,Datum*a2,bool*a3,uint32na,
506-
ItemPointerData*b,Datum*b2,bool*b3,uint32nb);
500+
externuint32rumMergeItemPointers(RumState*rumstate,
501+
ItemPointerData*dst,Datum*dst2,bool*dst3,
502+
ItemPointerData*a,Datum*a2,bool*a3,uint32na,
503+
ItemPointerData*b,Datum*b2,bool*b3,uint32nb);
507504
externvoidRumDataPageAddItem(Pagepage,void*data,OffsetNumberoffset);
508505
externvoidRumPageDeletePostingItem(Pagepage,OffsetNumberoffset);
509506

@@ -683,7 +680,7 @@ extern IndexBulkDeleteResult *rumbulkdelete(IndexVacuumInfo *info,
683680
externIndexBulkDeleteResult*rumvacuumcleanup(IndexVacuumInfo*info,
684681
IndexBulkDeleteResult*stats);
685682

686-
typedefstruct
683+
typedefstructRumEntryAccumulatorItem
687684
{
688685
ItemPointerDataiptr;
689686
booladdInfoIsNull;
@@ -713,6 +710,8 @@ typedef struct
713710
RumEntryAccumulator*entryallocator;
714711
uint32eas_used;
715712
RBTree*tree;
713+
RumKey*sortSpace;
714+
uint32sortSpaceN;
716715
}BuildAccumulator;
717716

718717
externvoidrumInitBA(BuildAccumulator*accum);

‎rumbulk.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ rumCombineData(RBNode *existing, const RBNode *newdata, void *arg)
4242
accum->allocatedMemory+=GetMemoryChunkSpace(eo->list);
4343
}
4444

45-
/* If item pointers are not ordered, they will need to be sorted later */
45+
/*
46+
* If item pointers are not ordered, they will need to be sorted later
47+
* Note: if useAlternativeOrder == true then shouldSort should be true
48+
* because anyway list isn't right ordered and code below could not check it
49+
* correctly
50+
*/
4651
if (eo->shouldSort== FALSE)
4752
{
4853
intres;
4954

55+
/* FIXME RumKey */
5056
res=rumCompareItemPointers(&eo->list[eo->count-1].iptr,
5157
&en->list->iptr);
5258
Assert(res!=0);
@@ -172,7 +178,13 @@ rumInsertBAEntry(BuildAccumulator *accum,
172178
ea->key=getDatumCopy(accum,attnum,key);
173179
ea->maxcount=DEF_NPTR;
174180
ea->count=1;
175-
ea->shouldSort= FALSE;
181+
182+
/*
183+
* if useAlternativeOrder = true then anyway we need to sort list,
184+
* but by setting shouldSort we prevent incorrect comparison in
185+
* rumCombineData()
186+
*/
187+
ea->shouldSort=accum->rumstate->useAlternativeOrder;
176188
ea->list=
177189
(RumEntryAccumulatorItem*)palloc(sizeof(RumEntryAccumulatorItem)*DEF_NPTR);
178190
ea->list[0].iptr=*heapptr;
@@ -250,6 +262,12 @@ qsortCompareItemPointers(const void *a, const void *b)
250262
returnres;
251263
}
252264

265+
staticint
266+
qsortCompareRumKey(constvoid*a,constvoid*b,void*arg)
267+
{
268+
returncompareRumKey(arg,a,b);
269+
}
270+
253271
/* Prepare to read out the rbtree contents using rumGetBAEntry */
254272
void
255273
rumBeginBAScan(BuildAccumulator*accum)
@@ -283,9 +301,15 @@ rumGetBAEntry(BuildAccumulator *accum,
283301

284302
Assert(list!=NULL&&entry->count>0);
285303

286-
if (entry->shouldSort&&entry->count>1)
287-
qsort(list,entry->count,sizeof(RumEntryAccumulatorItem),
288-
qsortCompareItemPointers);
304+
if (entry->count>1)
305+
{
306+
if (accum->rumstate->useAlternativeOrder)
307+
qsort_arg(list,entry->count,sizeof(RumEntryAccumulatorItem),
308+
qsortCompareRumKey,accum->rumstate);
309+
elseif (entry->shouldSort)
310+
qsort(list,entry->count,sizeof(RumEntryAccumulatorItem),
311+
qsortCompareItemPointers);
312+
}
289313

290314
returnlist;
291315
}

‎rumdatapage.c

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ rumCheckPlaceToDataPageLeaf(OffsetNumber attnum,
281281
}
282282

283283
int
284-
rumCompareItemPointers(ItemPointera,ItemPointerb)
284+
rumCompareItemPointers(constItemPointerData*a,constItemPointerData*b)
285285
{
286286
BlockNumberba=RumItemPointerGetBlockNumber(a);
287287
BlockNumberbb=RumItemPointerGetBlockNumber(b);
@@ -300,39 +300,36 @@ rumCompareItemPointers(ItemPointer a, ItemPointer b)
300300
}
301301

302302
int
303-
compareRumKey(RumState*state,RumKey*a,RumKey*b)
303+
compareRumKey(RumState*state,constRumKey*a,constRumKey*b)
304304
{
305305

306306
/* assume NULL is greate than any real value */
307-
if (state->useAlternativeOrder)
307+
if (a->addInfoIsNull== false&&b->addInfoIsNull== false)
308308
{
309-
if (a->isNull== false&&b->isNull== false)
310-
{
311-
intres;
312-
AttrNumberattnum=state->attrnOrderByColumn;
313-
314-
res=DatumGetInt32(FunctionCall2Coll(
315-
&state->compareFn[attnum-1],
316-
state->supportCollation[attnum-1],
317-
a->addToCompare,b->addToCompare));
318-
if (res!=0)
319-
returnres;
320-
/* fallback to ItemPointerCompare */
321-
}
322-
elseif (a->isNull== true)
323-
{
324-
if (b->isNull== false)
325-
return1;
326-
/* fallback to ItemPointerCompare */
327-
}
328-
else
329-
{
330-
Assert(b->isNull== true);
331-
return-1;
332-
}
309+
intres;
310+
AttrNumberattnum=state->attrnOrderByColumn;
311+
312+
res=DatumGetInt32(FunctionCall2Coll(
313+
&state->compareFn[attnum-1],
314+
state->supportCollation[attnum-1],
315+
a->addInfo,b->addInfo));
316+
if (res!=0)
317+
returnres;
318+
/* fallback to ItemPointerCompare */
319+
}
320+
elseif (a->addInfoIsNull== true)
321+
{
322+
if (b->addInfoIsNull== false)
323+
return1;
324+
/* fallback to ItemPointerCompare */
325+
}
326+
else
327+
{
328+
Assert(b->addInfoIsNull== true);
329+
return-1;
333330
}
334331

335-
returnrumCompareItemPointers(&a->ipd,&b->ipd);
332+
returnrumCompareItemPointers(&a->iptr,&b->iptr);
336333
}
337334

338335
/*
@@ -341,7 +338,8 @@ compareRumKey(RumState *state, RumKey *a, RumKey *b)
341338
* Caller is responsible that there is enough space at *dst.
342339
*/
343340
uint32
344-
rumMergeItemPointers(ItemPointerData*dst,Datum*dstAddInfo,bool*dstAddInfoIsNull,
341+
rumMergeItemPointers(RumState*rumstate,
342+
ItemPointerData*dst,Datum*dstAddInfo,bool*dstAddInfoIsNull,
345343
ItemPointerData*a,Datum*aAddInfo,bool*aAddInfoIsNull,uint32na,
346344
ItemPointerData*b,Datum*bAddInfo,bool*bAddInfoIsNull,uint32nb)
347345
{
@@ -351,7 +349,25 @@ rumMergeItemPointers(ItemPointerData *dst, Datum *dstAddInfo, bool *dstAddInfoIs
351349

352350
while (aptr-a<na&&bptr-b<nb)
353351
{
354-
intcmp=rumCompareItemPointers(aptr,bptr);
352+
intcmp;
353+
354+
if (rumstate->useAlternativeOrder)
355+
{
356+
RumKeya,b;
357+
358+
a.iptr=*aptr;
359+
a.addInfoIsNull=*aAddInfoIsNull;
360+
a.addInfo=*aAddInfo;
361+
b.iptr=*bptr;
362+
b.addInfoIsNull=*bAddInfoIsNull;
363+
b.addInfo=*bAddInfo;
364+
365+
cmp=compareRumKey(rumstate,&a,&b);
366+
}
367+
else
368+
{
369+
cmp=rumCompareItemPointers(aptr,bptr);
370+
}
355371

356372
if (cmp>0)
357373
{

‎ruminsert.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,10 @@ addItemPointersToLeafTuple(RumState *rumstate,
259259

260260
rumReadTuple(rumstate,attnum,old,oldItems,oldAddInfo,oldAddInfoIsNull);
261261

262-
newNPosting=rumMergeItemPointers(newItems,newAddInfo,newAddInfoIsNull,
263-
items,addInfo,addInfoIsNull,nitem,
264-
oldItems,oldAddInfo,oldAddInfoIsNull,oldNPosting);
262+
newNPosting=rumMergeItemPointers(rumstate,
263+
newItems,newAddInfo,newAddInfoIsNull,
264+
items,addInfo,addInfoIsNull,nitem,
265+
oldItems,oldAddInfo,oldAddInfoIsNull,oldNPosting);
265266

266267

267268
/* try to build tuple with room for all the items */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp