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

Commit57cafe7

Browse files
committed
Refactor from Heikki Linnakangas <heikki@enterprisedb.com>:
* Defined new struct WordEntryPosVector that holds a uint16 length and avariable size array of WordEntries. This replaces the previousconvention of a variable size uint16 array, with the first elementimplying the length. WordEntryPosVector has the same layout in memory,but is more readable in source code. The POSDATAPTR and POSDATALENmacros are still used, though it would now be more readable to accessthe fields in WordEntryPosVector directly.* Removed needfree field from DocRepresentation. It was always set to false.* Miscellaneous other commenting and refactoring
1 parentef4d38c commit57cafe7

File tree

5 files changed

+109
-58
lines changed

5 files changed

+109
-58
lines changed

‎src/backend/utils/adt/tsginidx.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.3 2007/09/07 16:03:40 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsginidx.c,v 1.4 2007/09/11 08:46:29 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -25,13 +25,12 @@ gin_extract_tsvector(PG_FUNCTION_ARGS)
2525
int32*nentries= (int32*)PG_GETARG_POINTER(1);
2626
Datum*entries=NULL;
2727

28-
*nentries=0;
28+
*nentries=vector->size;
2929
if (vector->size>0)
3030
{
3131
inti;
3232
WordEntry*we=ARRPTR(vector);
3333

34-
*nentries= (uint32)vector->size;
3534
entries= (Datum*)palloc(sizeof(Datum)*vector->size);
3635

3736
for (i=0;i<vector->size;i++)
@@ -134,11 +133,19 @@ gin_ts_consistent(PG_FUNCTION_ARGS)
134133

135134
if (query->size>0)
136135
{
137-
int4i,
136+
inti,
138137
j=0;
139138
QueryItem*item;
140139
GinChkValgcv;
141140

141+
/*
142+
* check-parameter array has one entry for each value (operand) in the
143+
* query. We expand that array into mapped_check, so that there's one
144+
* entry in mapped_check for every node in the query, including
145+
* operators, to allow quick lookups in checkcondition_gin. Only the
146+
* entries corresponding operands are actually used.
147+
*/
148+
142149
gcv.frst=item=GETQUERY(query);
143150
gcv.mapped_check= (bool*)palloc(sizeof(bool)*query->size);
144151

‎src/backend/utils/adt/tsgistidx.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsgistidx.c,v 1.3 2007/09/07 15:09:56 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsgistidx.c,v 1.4 2007/09/11 08:46:29 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -133,20 +133,27 @@ gtsvectorout(PG_FUNCTION_ARGS)
133133
}
134134

135135
staticint
136-
compareint(constvoid*a,constvoid*b)
136+
compareint(constvoid*va,constvoid*vb)
137137
{
138-
if (*((int4*)a)==*((int4*)b))
138+
int4a=*((int4*)va);
139+
int4b=*((int4*)vb);
140+
141+
if (a==b)
139142
return0;
140-
return (*((int4*)a)>*((int4*)b)) ?1 :-1;
143+
return (a>b) ?1 :-1;
141144
}
142145

146+
/*
147+
* Removes duplicates from an array of int4. 'l' is
148+
* size of the input array. Returns the new size of the array.
149+
*/
143150
staticint
144151
uniqueint(int4*a,int4l)
145152
{
146153
int4*ptr,
147154
*res;
148155

149-
if (l==1)
156+
if (l<=1)
150157
returnl;
151158

152159
ptr=res=a;
@@ -570,12 +577,15 @@ typedef struct
570577
}SPLITCOST;
571578

572579
staticint
573-
comparecost(constvoid*a,constvoid*b)
580+
comparecost(constvoid*va,constvoid*vb)
574581
{
575-
if (((SPLITCOST*)a)->cost== ((SPLITCOST*)b)->cost)
582+
SPLITCOST*a= (SPLITCOST*)va;
583+
SPLITCOST*b= (SPLITCOST*)vb;
584+
585+
if (a->cost==b->cost)
576586
return0;
577587
else
578-
return (((SPLITCOST*)a)->cost>((SPLITCOST*)b)->cost) ?1 :-1;
588+
return (a->cost>b->cost) ?1 :-1;
579589
}
580590

581591

‎src/backend/utils/adt/tsrank.c

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.4 2007/09/07 16:03:40 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.5 2007/09/11 08:46:29 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -53,22 +53,24 @@ cnt_length(TSVector t)
5353
{
5454
WordEntry*ptr=ARRPTR(t),
5555
*end= (WordEntry*)STRPTR(t);
56-
intlen=0,
57-
clen;
56+
intlen=0;
5857

5958
while (ptr<end)
6059
{
61-
if ((clen=POSDATALEN(t,ptr))==0)
60+
intclen=POSDATALEN(t,ptr);
61+
62+
if (clen==0)
6263
len+=1;
6364
else
6465
len+=clen;
66+
6567
ptr++;
6668
}
6769

6870
returnlen;
6971
}
7072

71-
staticint4
73+
staticint
7274
WordECompareQueryItem(char*eval,char*qval,WordEntry*ptr,QueryOperand*item)
7375
{
7476
if (ptr->len==item->length)
@@ -80,6 +82,10 @@ WordECompareQueryItem(char *eval, char *qval, WordEntry *ptr, QueryOperand *item
8082
return (ptr->len>item->length) ?1 :-1;
8183
}
8284

85+
/*
86+
* Returns a pointer to a WordEntry corresponding 'item' from tsvector 't'. 'q'
87+
* is the TSQuery containing 'item'. Returns NULL if not found.
88+
*/
8389
staticWordEntry*
8490
find_wordentry(TSVectort,TSQueryq,QueryOperand*item)
8591
{
@@ -178,15 +184,15 @@ SortAndUniqItems(TSQuery q, int *size)
178184
}
179185

180186
/* A dummy WordEntryPos array to use when haspos is false */
181-
staticWordEntryPosPOSNULL[]= {
187+
staticWordEntryPosVectorPOSNULL= {
182188
1,/* Number of elements that follow */
183-
0
189+
{0 }
184190
};
185191

186192
staticfloat
187193
calc_rank_and(float*w,TSVectort,TSQueryq)
188194
{
189-
uint16**pos;
195+
WordEntryPosVector**pos;
190196
inti,
191197
k,
192198
l,
@@ -207,9 +213,8 @@ calc_rank_and(float *w, TSVector t, TSQuery q)
207213
pfree(item);
208214
returncalc_rank_or(w,t,q);
209215
}
210-
pos= (uint16**)palloc(sizeof(uint16*)*q->size);
211-
memset(pos,0,sizeof(uint16*)*q->size);
212-
WEP_SETPOS(POSNULL[1],MAXENTRYPOS-1);
216+
pos= (WordEntryPosVector**)palloc0(sizeof(WordEntryPosVector*)*q->size);
217+
WEP_SETPOS(POSNULL.pos[0],MAXENTRYPOS-1);
213218

214219
for (i=0;i<size;i++)
215220
{
@@ -218,25 +223,25 @@ calc_rank_and(float *w, TSVector t, TSQuery q)
218223
continue;
219224

220225
if (entry->haspos)
221-
pos[i]=(uint16*)_POSDATAPTR(t,entry);
226+
pos[i]=_POSVECPTR(t,entry);
222227
else
223-
pos[i]=(uint16*)POSNULL;
228+
pos[i]=&POSNULL;
224229

225230

226-
dimt=*(uint16*) (pos[i]);
227-
post=(WordEntryPos*) (pos[i]+1);
231+
dimt=pos[i]->npos;
232+
post=pos[i]->pos;
228233
for (k=0;k<i;k++)
229234
{
230235
if (!pos[k])
231236
continue;
232-
lenct=*(uint16*) (pos[k]);
233-
ct=(WordEntryPos*) (pos[k]+1);
237+
lenct=pos[k]->npos;
238+
ct=pos[k]->pos;
234239
for (l=0;l<dimt;l++)
235240
{
236241
for (p=0;p<lenct;p++)
237242
{
238243
dist=Abs((int)WEP_GETPOS(post[l])- (int)WEP_GETPOS(ct[p]));
239-
if (dist|| (dist==0&& (pos[i]==(uint16*)POSNULL||pos[k]==(uint16*)POSNULL)))
244+
if (dist|| (dist==0&& (pos[i]==&POSNULL||pos[k]==&POSNULL)))
240245
{
241246
floatcurw;
242247

@@ -285,8 +290,8 @@ calc_rank_or(float *w, TSVector t, TSQuery q)
285290
}
286291
else
287292
{
288-
dimt=*(uint16*)POSNULL;
289-
post=POSNULL+1;
293+
dimt=POSNULL.npos;
294+
post=POSNULL.pos;
290295
}
291296

292297
resj=0.0;
@@ -456,17 +461,19 @@ typedef struct
456461
{
457462
QueryItem**item;
458463
int16nitem;
459-
boolneedfree;
460464
uint8wclass;
461465
int32pos;
462466
}DocRepresentation;
463467

464468
staticint
465-
compareDocR(constvoid*a,constvoid*b)
469+
compareDocR(constvoid*va,constvoid*vb)
466470
{
467-
if (((DocRepresentation*)a)->pos== ((DocRepresentation*)b)->pos)
471+
DocRepresentation*a= (DocRepresentation*)va;
472+
DocRepresentation*b= (DocRepresentation*)vb;
473+
474+
if (a->pos==b->pos)
468475
return0;
469-
return (((DocRepresentation*)a)->pos>((DocRepresentation*)b)->pos) ?1 :-1;
476+
return (a->pos>b->pos) ?1 :-1;
470477
}
471478

472479
staticbool
@@ -547,11 +554,11 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
547554

548555
ptr=doc+lastpos;
549556

550-
/* find lower bound of cover fromfounded upper bound, move down */
557+
/* find lower bound of cover fromfound upper bound, move down */
551558
while (ptr >=doc+ext->pos)
552559
{
553560
for (i=0;i<ptr->nitem;i++)
554-
if(ptr->item[i]->type==QI_VAL)/* XXX */
561+
if(ptr->item[i]->type==QI_VAL)
555562
ptr->item[i]->operand.istrue=1;
556563
if (TS_execute(GETQUERY(query),NULL, true,checkcondition_QueryOperand))
557564
{
@@ -620,8 +627,8 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
620627
}
621628
else
622629
{
623-
dimt=*(uint16*)POSNULL;
624-
post=POSNULL+1;
630+
dimt=POSNULL.npos;
631+
post=POSNULL.pos;
625632
}
626633

627634
while (cur+dimt >=len)
@@ -636,7 +643,6 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
636643
{
637644
intk;
638645

639-
doc[cur].needfree= false;
640646
doc[cur].nitem=0;
641647
doc[cur].item= (QueryItem**)palloc(sizeof(QueryItem*)*query->size);
642648

@@ -658,7 +664,6 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
658664
}
659665
else
660666
{
661-
doc[cur].needfree= false;
662667
doc[cur].nitem=doc[cur-1].nitem;
663668
doc[cur].item=doc[cur-1].item;
664669
}
@@ -764,9 +769,6 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
764769
if ((method&RANK_NORM_LOGUNIQ)&&txt->size>0)
765770
Wdoc /=log((double) (txt->size+1)) /log(2.0);
766771

767-
for (i=0;i<doclen;i++)
768-
if (doc[i].needfree)
769-
pfree(doc[i].item);
770772
pfree(doc);
771773

772774
return (float4)Wdoc;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp