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

Commit8494064

Browse files
committed
New C function: bms_add_range
This will be used by pending patches to improve partition pruning.Amit Langote and Kyotaro Horiguchi, per a suggestion from DavidRowley. Review and testing of the larger patch set of which this is apart by Ashutosh Bapat, David Rowley, Dilip Kumar, Jesper Pedersen,Rajkumar Raghuwanshi, Beena Emerson, Amul Sul, and Kyotaro Horiguchi.Discussion:http://postgr.es/m/098b9c71-1915-1a2a-8d52-1a7a50ce79e8@lab.ntt.co.jp
1 parent8d4e70a commit8494064

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

‎src/backend/nodes/bitmapset.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,78 @@ bms_add_members(Bitmapset *a, const Bitmapset *b)
784784
returnresult;
785785
}
786786

787+
/*
788+
* bms_add_range
789+
*Add members in the range of 'lower' to 'upper' to the set.
790+
*
791+
* Note this could also be done by calling bms_add_member in a loop, however,
792+
* using this function will be faster when the range is large as we work with
793+
* at the bitmapword level rather than at bit level.
794+
*/
795+
Bitmapset*
796+
bms_add_range(Bitmapset*a,intlower,intupper)
797+
{
798+
intlwordnum,
799+
lbitnum,
800+
uwordnum,
801+
ushiftbits,
802+
wordnum;
803+
804+
if (lower<0||upper<0)
805+
elog(ERROR,"negative bitmapset member not allowed");
806+
if (lower>upper)
807+
elog(ERROR,"lower range must not be above upper range");
808+
uwordnum=WORDNUM(upper);
809+
810+
if (a==NULL)
811+
{
812+
a= (Bitmapset*)palloc0(BITMAPSET_SIZE(uwordnum+1));
813+
a->nwords=uwordnum+1;
814+
}
815+
816+
/* ensure we have enough words to store the upper bit */
817+
elseif (uwordnum >=a->nwords)
818+
{
819+
intoldnwords=a->nwords;
820+
inti;
821+
822+
a= (Bitmapset*)repalloc(a,BITMAPSET_SIZE(uwordnum+1));
823+
a->nwords=uwordnum+1;
824+
/* zero out the enlarged portion */
825+
for (i=oldnwords;i<a->nwords;i++)
826+
a->words[i]=0;
827+
}
828+
829+
wordnum=lwordnum=WORDNUM(lower);
830+
831+
lbitnum=BITNUM(lower);
832+
ushiftbits=BITS_PER_BITMAPWORD- (BITNUM(upper)+1);
833+
834+
/*
835+
* Special case when lwordnum is the same as uwordnum we must perform the
836+
* upper and lower masking on the word.
837+
*/
838+
if (lwordnum==uwordnum)
839+
{
840+
a->words[lwordnum] |= ~(bitmapword) (((bitmapword)1 <<lbitnum)-1)
841+
& (~(bitmapword)0) >>ushiftbits;
842+
}
843+
else
844+
{
845+
/* turn on lbitnum and all bits left of it */
846+
a->words[wordnum++] |= ~(bitmapword) (((bitmapword)1 <<lbitnum)-1);
847+
848+
/* turn on all bits for any intermediate words */
849+
while (wordnum<uwordnum)
850+
a->words[wordnum++]= ~(bitmapword)0;
851+
852+
/* turn on upper's bit and all bits right of it. */
853+
a->words[uwordnum] |= (~(bitmapword)0) >>ushiftbits;
854+
}
855+
856+
returna;
857+
}
858+
787859
/*
788860
* bms_int_members - like bms_intersect, but left input is recycled
789861
*/

‎src/include/nodes/bitmapset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ extern bool bms_is_empty(const Bitmapset *a);
9090
externBitmapset*bms_add_member(Bitmapset*a,intx);
9191
externBitmapset*bms_del_member(Bitmapset*a,intx);
9292
externBitmapset*bms_add_members(Bitmapset*a,constBitmapset*b);
93+
externBitmapset*bms_add_range(Bitmapset*a,intlower,intupper);
9394
externBitmapset*bms_int_members(Bitmapset*a,constBitmapset*b);
9495
externBitmapset*bms_del_members(Bitmapset*a,constBitmapset*b);
9596
externBitmapset*bms_join(Bitmapset*a,Bitmapset*b);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp