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

Commit7d58f23

Browse files
committed
REALLOCATE_BITMAPSETS manual compile-time option
This option forces each bitmapset modification to reallocate bitmapset. Thisis useful for debugging hangling pointers to bitmapset's.Discussion:https://postgr.es/m/CAMbWs4_wJthNtYBL%2BSsebpgF-5L2r5zFFk6xYbS0A78GKOTFHw%40mail.gmail.comReviewed-by: Richard Guo, Andres Freund, Ashutosh Bapat, Andrei Lepikhov
1 parent71a3e8c commit7d58f23

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

‎src/backend/nodes/bitmapset.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ bms_intersect(const Bitmapset *a, const Bitmapset *b)
263263
/* Handle cases where either input is NULL */
264264
if (a==NULL||b==NULL)
265265
returnNULL;
266+
266267
/* Identify shorter and longer input; copy the shorter one */
267268
if (a->nwords <=b->nwords)
268269
{
@@ -798,8 +799,15 @@ bms_add_member(Bitmapset *a, int x)
798799
{
799800
intoldnwords=a->nwords;
800801
inti;
802+
#ifdefREALLOCATE_BITMAPSETS
803+
Bitmapset*tmp=a;
801804

805+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(wordnum+1));
806+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
807+
pfree(tmp);
808+
#else
802809
a= (Bitmapset*)repalloc(a,BITMAPSET_SIZE(wordnum+1));
810+
#endif
803811
a->nwords=wordnum+1;
804812
/* zero out the enlarged portion */
805813
i=oldnwords;
@@ -808,6 +816,16 @@ bms_add_member(Bitmapset *a, int x)
808816
a->words[i]=0;
809817
}while (++i<a->nwords);
810818
}
819+
#ifdefREALLOCATE_BITMAPSETS
820+
else
821+
{
822+
Bitmapset*tmp=a;
823+
824+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
825+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
826+
pfree(tmp);
827+
}
828+
#endif
811829

812830
a->words[wordnum] |= ((bitmapword)1 <<bitnum);
813831
returna;
@@ -825,6 +843,9 @@ bms_del_member(Bitmapset *a, int x)
825843
{
826844
intwordnum,
827845
bitnum;
846+
#ifdefREALLOCATE_BITMAPSETS
847+
Bitmapset*tmp=a;
848+
#endif
828849

829850
if (x<0)
830851
elog(ERROR,"negative bitmapset member not allowed");
@@ -836,6 +857,12 @@ bms_del_member(Bitmapset *a, int x)
836857
wordnum=WORDNUM(x);
837858
bitnum=BITNUM(x);
838859

860+
#ifdefREALLOCATE_BITMAPSETS
861+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
862+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
863+
pfree(tmp);
864+
#endif
865+
839866
/* member can't exist. Return 'a' unmodified */
840867
if (unlikely(wordnum >=a->nwords))
841868
returna;
@@ -889,6 +916,13 @@ bms_add_members(Bitmapset *a, const Bitmapset *b)
889916
}
890917
else
891918
{
919+
#ifdefREALLOCATE_BITMAPSETS
920+
Bitmapset*tmp=a;
921+
922+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
923+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
924+
pfree(tmp);
925+
#endif
892926
result=a;
893927
other=b;
894928
}
@@ -941,9 +975,16 @@ bms_add_range(Bitmapset *a, int lower, int upper)
941975
{
942976
intoldnwords=a->nwords;
943977
inti;
978+
#ifdefREALLOCATE_BITMAPSETS
979+
Bitmapset*tmp=a;
944980

981+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(uwordnum+1));
982+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
983+
pfree(tmp);
984+
#else
945985
/* ensure we have enough words to store the upper bit */
946986
a= (Bitmapset*)repalloc(a,BITMAPSET_SIZE(uwordnum+1));
987+
#endif
947988
a->nwords=uwordnum+1;
948989
/* zero out the enlarged portion */
949990
i=oldnwords;
@@ -992,6 +1033,12 @@ bms_int_members(Bitmapset *a, const Bitmapset *b)
9921033
intlastnonzero;
9931034
intshortlen;
9941035
inti;
1036+
#ifdefREALLOCATE_BITMAPSETS
1037+
Bitmapset*tmp=a;
1038+
#endif
1039+
1040+
Assert(a==NULL||IsA(a,Bitmapset));
1041+
Assert(b==NULL||IsA(b,Bitmapset));
9951042

9961043
Assert(a==NULL||IsA(a,Bitmapset));
9971044
Assert(b==NULL||IsA(b,Bitmapset));
@@ -1004,6 +1051,13 @@ bms_int_members(Bitmapset *a, const Bitmapset *b)
10041051
pfree(a);
10051052
returnNULL;
10061053
}
1054+
1055+
#ifdefREALLOCATE_BITMAPSETS
1056+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
1057+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
1058+
pfree(tmp);
1059+
#endif
1060+
10071061
/* Intersect b into a; we need never copy */
10081062
shortlen=Min(a->nwords,b->nwords);
10091063
lastnonzero=-1;
@@ -1035,6 +1089,9 @@ Bitmapset *
10351089
bms_del_members(Bitmapset*a,constBitmapset*b)
10361090
{
10371091
inti;
1092+
#ifdefREALLOCATE_BITMAPSETS
1093+
Bitmapset*tmp=a;
1094+
#endif
10381095

10391096
Assert(a==NULL|| (IsA(a,Bitmapset)&&a->words[a->nwords-1]!=0));
10401097
Assert(b==NULL|| (IsA(b,Bitmapset)&&b->words[b->nwords-1]!=0));
@@ -1044,6 +1101,13 @@ bms_del_members(Bitmapset *a, const Bitmapset *b)
10441101
returnNULL;
10451102
if (b==NULL)
10461103
returna;
1104+
1105+
#ifdefREALLOCATE_BITMAPSETS
1106+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
1107+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
1108+
pfree(tmp);
1109+
#endif
1110+
10471111
/* Remove b's bits from a; we need never copy */
10481112
if (a->nwords>b->nwords)
10491113
{
@@ -1096,6 +1160,12 @@ bms_join(Bitmapset *a, Bitmapset *b)
10961160
Bitmapset*other;
10971161
intotherlen;
10981162
inti;
1163+
#ifdefREALLOCATE_BITMAPSETS
1164+
Bitmapset*tmp=a;
1165+
#endif
1166+
1167+
Assert(a==NULL||IsA(a,Bitmapset));
1168+
Assert(b==NULL||IsA(b,Bitmapset));
10991169

11001170
Assert(a==NULL||IsA(a,Bitmapset));
11011171
Assert(b==NULL||IsA(b,Bitmapset));
@@ -1105,6 +1175,13 @@ bms_join(Bitmapset *a, Bitmapset *b)
11051175
returnb;
11061176
if (b==NULL)
11071177
returna;
1178+
1179+
#ifdefREALLOCATE_BITMAPSETS
1180+
a= (Bitmapset*)palloc(BITMAPSET_SIZE(tmp->nwords));
1181+
memcpy(a,tmp,BITMAPSET_SIZE(tmp->nwords));
1182+
pfree(tmp);
1183+
#endif
1184+
11081185
/* Identify shorter and longer input; use longer one as result */
11091186
if (a->nwords<b->nwords)
11101187
{

‎src/include/pg_config_manual.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@
335335
*/
336336
/* #define COPY_PARSE_PLAN_TREES */
337337

338+
/*
339+
* Define this to force Bitmapset reallocation on each modification. Helps
340+
* to find hangling pointers to Bitmapset's.
341+
*/
342+
/* #define REALLOCATE_BITMAPSETS */
343+
338344
/*
339345
* Define this to force all parse and plan trees to be passed through
340346
* outfuncs.c/readfuncs.c, to facilitate catching errors and omissions in

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp