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

Commite33dac2

Browse files
committed
prepare to alternative ordering. No-op yet
1 parent993994b commite33dac2

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

‎rum.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ typedef struct RumOptions
287287
{
288288
int32vl_len_;/* varlena header (do not touch directly!) */
289289
booluseFastUpdate;/* use fast updates? */
290+
booluseAlternativeOrder;
290291
intorderByColumn;
291292
intaddToColumn;
292293
}RumOptions;
@@ -302,6 +303,11 @@ typedef struct RumOptions
302303
#defineRUM_SHAREBUFFER_LOCK_SHARE
303304
#defineRUM_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE
304305

306+
typedefstructRumKey {
307+
ItemPointerDataipd;
308+
boolisNull;
309+
DatumaddToCompare;
310+
}RumKey;
305311

306312
/*
307313
* RumState: working data structure describing the index being worked on
@@ -310,6 +316,7 @@ typedef struct RumState
310316
{
311317
Relationindex;
312318
booloneCol;/* true if single-column index */
319+
booluseAlternativeOrder;
313320
AttrNumberattrnOrderByColumn;
314321
AttrNumberattrnAddToColumn;
315322

@@ -486,6 +493,7 @@ extern void checkLeafDataPage(RumState *rumstate, AttrNumber attrnum, Page page)
486493

487494
/* rumdatapage.c */
488495
externintrumCompareItemPointers(ItemPointera,ItemPointerb);
496+
externintcompareRumKey(RumState*state,RumKey*a,RumKey*b);
489497
externchar*rumDataPageLeafWriteItemPointer(char*ptr,ItemPointeriptr,ItemPointerprev,booladdInfoIsNull);
490498
externPointerrumPlaceToDataPageLeaf(Pointerptr,OffsetNumberattnum,
491499
ItemPointeriptr,DatumaddInfo,booladdInfoIsNull,ItemPointerprev,

‎rumdatapage.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,42 @@ rumCompareItemPointers(ItemPointer a, ItemPointer b)
267267
return (ba>bb) ?1 :-1;
268268
}
269269

270+
int
271+
compareRumKey(RumState*state,RumKey*a,RumKey*b)
272+
{
273+
274+
/* assume NULL is greate than any real value */
275+
if (state->useAlternativeOrder)
276+
{
277+
if (a->isNull== false&&b->isNull== false)
278+
{
279+
intres;
280+
AttrNumberattnum=state->attrnOrderByColumn;
281+
282+
res=DatumGetInt32(FunctionCall2Coll(
283+
&state->compareFn[attnum-1],
284+
state->supportCollation[attnum-1],
285+
a->addToCompare,b->addToCompare));
286+
if (res!=0)
287+
returnres;
288+
/* fallback to ItemPointerCompare */
289+
}
290+
elseif (a->isNull== true)
291+
{
292+
if (b->isNull== false)
293+
return1;
294+
/* fallback to ItemPointerCompare */
295+
}
296+
else
297+
{
298+
Assert(b->isNull== true);
299+
return-1;
300+
}
301+
}
302+
303+
returnrumCompareItemPointers(&a->ipd,&b->ipd);
304+
}
305+
270306
/*
271307
* Merge two ordered arrays of itempointers, eliminating any duplicates.
272308
* Returns the number of items in the result.

‎rumutil.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ _PG_init(void)
5555
add_string_reloption(rum_relopt_kind,"addto",
5656
"Column name to add a order by column",
5757
NULL,NULL);
58+
add_bool_reloption(rum_relopt_kind,"use_alternative_order",
59+
"Use (addinfo, itempointer) order instead of just itempointer",
60+
false);
5861
}
5962

6063
/*
@@ -158,7 +161,16 @@ initRumState(RumState *state, Relation index)
158161

159162
if (!(AttributeNumberIsValid(state->attrnOrderByColumn)&&
160163
AttributeNumberIsValid(state->attrnAddToColumn)))
161-
elog(ERROR,"AddTo and OrderBy colums should be defined both");
164+
elog(ERROR,"AddTo and OrderBy columns should be defined both");
165+
166+
if (options->useAlternativeOrder)
167+
{
168+
if (!(AttributeNumberIsValid(state->attrnOrderByColumn)&&
169+
AttributeNumberIsValid(state->attrnAddToColumn)))
170+
elog(ERROR,"to use alternative ordering AddTo and OrderBy should be defined");
171+
172+
state->useAlternativeOrder= true;
173+
}
162174
}
163175

164176
for (i=0;i<origTupdesc->natts;i++)
@@ -766,7 +778,8 @@ rumoptions(Datum reloptions, bool validate)
766778
staticconstrelopt_parse_elttab[]= {
767779
{"fastupdate",RELOPT_TYPE_BOOL, offsetof(RumOptions,useFastUpdate)},
768780
{"orderby",RELOPT_TYPE_STRING, offsetof(RumOptions,orderByColumn)},
769-
{"addto",RELOPT_TYPE_STRING, offsetof(RumOptions,addToColumn)}
781+
{"addto",RELOPT_TYPE_STRING, offsetof(RumOptions,addToColumn)},
782+
{"use_alternative_order",RELOPT_TYPE_BOOL, offsetof(RumOptions,useAlternativeOrder)}
770783
};
771784

772785
options=parseRelOptions(reloptions,validate,rum_relopt_kind,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp