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

Appearance settings

Commit 476045a

Browse filesBrowse files
committed
Remove QueryOperand->istrue flag, it was used only in cover ranking
(ts_rank_cd). Use palloc'ed array in ranking instead of flag.
1 parent 13553cb commit 476045a
Copy full SHA for 476045a

File tree

Expand file treeCollapse file tree

3 files changed

+49
-48
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+49
-48
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/tsquery.c
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.6 2007/09/10 12:36:40 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery.c,v 1.7 2007/09/11 16:01:40 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -784,8 +784,6 @@ tsquerysend(PG_FUNCTION_ARGS)
784784
case QI_VAL:
785785
pq_sendint(&buf, item->operand.weight, sizeof(uint8));
786786
pq_sendstring(&buf, GETOPERAND(query) + item->operand.distance);
787-
/* istrue flag is just for temporary use in tsrank.c/Cover,
788-
* so we don't need to transfer that */
789787
break;
790788
case QI_OPR:
791789
pq_sendint(&buf, item->operator.oper, sizeof(item->operator.oper));

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

Copy file name to clipboardExpand all lines: src/backend/utils/adt/tsrank.c
+46-42Lines changed: 46 additions & 42 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.5 2007/09/11 08:46:29 teodor Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/tsrank.c,v 1.6 2007/09/11 16:01:40 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -476,25 +476,20 @@ compareDocR(const void *va, const void *vb)
476476
return (a->pos > b->pos) ? 1 : -1;
477477
}
478478

479-
static bool
480-
checkcondition_QueryOperand(void *checkval, QueryOperand *val)
479+
typedef struct
481480
{
482-
return (bool) (val->istrue);
483-
}
481+
TSQuery query;
482+
bool *operandexist;
483+
} QueryRepresentation;
484484

485-
static void
486-
reset_istrue_flag(TSQuery query)
487-
{
488-
QueryItem *item = GETQUERY(query);
489-
int i;
485+
#define QR_GET_OPERAND_EXISTS(q, v) ( (q)->operandexist[ ((QueryItem*)(v)) - GETQUERY((q)->query) ] )
486+
#define QR_SET_OPERAND_EXISTS(q, v) QR_GET_OPERAND_EXISTS(q,v) = true
490487

491-
/* reset istrue flag */
492-
for (i = 0; i < query->size; i++)
493-
{
494-
if (item->type == QI_VAL)
495-
item->operand.istrue = 0;
496-
item++;
497-
}
488+
static bool
489+
checkcondition_QueryOperand(void *checkval, QueryOperand *val)
490+
{
491+
QueryRepresentation *qr = (QueryRepresentation*)checkval;
492+
return QR_GET_OPERAND_EXISTS(qr, val);
498493
}
499494

500495
typedef struct
@@ -508,7 +503,7 @@ typedef struct
508503

509504

510505
static bool
511-
Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
506+
Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, Extention *ext)
512507
{
513508
DocRepresentation *ptr;
514509
int lastpos = ext->pos;
@@ -519,7 +514,7 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
519514
* (though any decent compiler will optimize away the tail-recursion. */
520515
check_stack_depth();
521516

522-
reset_istrue_flag(query);
517+
memset( qr->operandexist, 0, sizeof(bool)*qr->query->size );
523518

524519
ext->p = 0x7fffffff;
525520
ext->q = 0;
@@ -531,9 +526,9 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
531526
for (i = 0; i < ptr->nitem; i++)
532527
{
533528
if(ptr->item[i]->type == QI_VAL)
534-
ptr->item[i]->operand.istrue = 1;
529+
QR_SET_OPERAND_EXISTS(qr, ptr->item[i]);
535530
}
536-
if (TS_execute(GETQUERY(query), NULL, false, checkcondition_QueryOperand))
531+
if (TS_execute(GETQUERY(qr->query), (void*)qr, false, checkcondition_QueryOperand))
537532
{
538533
if (ptr->pos > ext->q)
539534
{
@@ -550,7 +545,7 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
550545
if (!found)
551546
return false;
552547

553-
reset_istrue_flag(query);
548+
memset( qr->operandexist, 0, sizeof(bool)*qr->query->size );
554549

555550
ptr = doc + lastpos;
556551

@@ -559,8 +554,8 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
559554
{
560555
for (i = 0; i < ptr->nitem; i++)
561556
if(ptr->item[i]->type == QI_VAL)
562-
ptr->item[i]->operand.istrue = 1;
563-
if (TS_execute(GETQUERY(query), NULL, true, checkcondition_QueryOperand))
557+
QR_SET_OPERAND_EXISTS(qr, ptr->item[i]);
558+
if (TS_execute(GETQUERY(qr->query), (void*)qr, true, checkcondition_QueryOperand))
564559
{
565560
if (ptr->pos < ext->p)
566561
{
@@ -583,28 +578,27 @@ Cover(DocRepresentation *doc, int len, TSQuery query, Extention *ext)
583578
}
584579

585580
ext->pos++;
586-
return Cover(doc, len, query, ext);
581+
return Cover(doc, len, qr, ext);
587582
}
588583

589584
static DocRepresentation *
590-
get_docrep(TSVector txt, TSQuery query, int *doclen)
585+
get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
591586
{
592-
QueryItem *item = GETQUERY(query);
587+
QueryItem *item = GETQUERY(qr->query);
593588
WordEntry *entry;
594589
WordEntryPos *post;
595590
int4 dimt,
596591
j,
597592
i;
598-
int len = query->size * 4,
593+
int len = qr->query->size * 4,
599594
cur = 0;
600595
DocRepresentation *doc;
601596
char *operand;
602597

603598
doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len);
604-
operand = GETOPERAND(query);
605-
reset_istrue_flag(query);
599+
operand = GETOPERAND(qr->query);
606600

607-
for (i = 0; i < query->size; i++)
601+
for (i = 0; i < qr->query->size; i++)
608602
{
609603
QueryOperand *curoperand;
610604

@@ -613,10 +607,10 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
613607

614608
curoperand = &item[i].operand;
615609

616-
if(item[i].operand.istrue)
610+
if(QR_GET_OPERAND_EXISTS(qr, &item[i]))
617611
continue;
618612

619-
entry = find_wordentry(txt, query, curoperand);
613+
entry = find_wordentry(txt, qr->query, curoperand);
620614
if (!entry)
621615
continue;
622616

@@ -644,9 +638,9 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
644638
int k;
645639

646640
doc[cur].nitem = 0;
647-
doc[cur].item = (QueryItem **) palloc(sizeof(QueryItem *) * query->size);
641+
doc[cur].item = (QueryItem **) palloc(sizeof(QueryItem *) * qr->query->size);
648642

649-
for (k = 0; k < query->size; k++)
643+
for (k = 0; k < qr->query->size; k++)
650644
{
651645
QueryOperand *kptr = &item[k].operand;
652646
QueryOperand *iptr = &item[i].operand;
@@ -658,7 +652,7 @@ get_docrep(TSVector txt, TSQuery query, int *doclen)
658652
/* if k == i, we've already checked above that it's type == Q_VAL */
659653
doc[cur].item[doc[cur].nitem] = item + k;
660654
doc[cur].nitem++;
661-
item[k].operand.istrue = 1;
655+
QR_SET_OPERAND_EXISTS( qr, item+k );
662656
}
663657
}
664658
}
@@ -699,6 +693,8 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
699693
PrevExtPos = 0.0,
700694
CurExtPos = 0.0;
701695
int NExtent = 0;
696+
QueryRepresentation qr;
697+
702698

703699
for (i = 0; i < lengthof(weights); i++)
704700
{
@@ -710,12 +706,18 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
710706
invws[i] = 1.0 / invws[i];
711707
}
712708

713-
doc = get_docrep(txt, query, &doclen);
709+
qr.query = query;
710+
qr.operandexist = (int*)palloc0(sizeof(bool) * query->size);
711+
712+
doc = get_docrep(txt, &qr, &doclen);
714713
if (!doc)
714+
{
715+
pfree( qr.operandexist );
715716
return 0.0;
717+
}
716718

717719
MemSet(&ext, 0, sizeof(Extention));
718-
while (Cover(doc, doclen, query, &ext))
720+
while (Cover(doc, doclen, &qr, &ext))
719721
{
720722
double Cpos = 0.0;
721723
double InvSum = 0.0;
@@ -771,6 +773,8 @@ calc_rank_cd(float4 *arrdata, TSVector txt, TSQuery query, int method)
771773

772774
pfree(doc);
773775

776+
pfree( qr.operandexist );
777+
774778
return (float4) Wdoc;
775779
}
776780

@@ -779,7 +783,7 @@ ts_rankcd_wttf(PG_FUNCTION_ARGS)
779783
{
780784
ArrayType *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
781785
TSVector txt = PG_GETARG_TSVECTOR(1);
782-
TSQuery query = PG_GETARG_TSQUERY_COPY(2); /* copy because we modify the istrue-flag */
786+
TSQuery query = PG_GETARG_TSQUERY(2);
783787
int method = PG_GETARG_INT32(3);
784788
float res;
785789

@@ -796,7 +800,7 @@ ts_rankcd_wtt(PG_FUNCTION_ARGS)
796800
{
797801
ArrayType *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
798802
TSVector txt = PG_GETARG_TSVECTOR(1);
799-
TSQuery query = PG_GETARG_TSQUERY_COPY(2); /* copy because we modify the istrue-flag */
803+
TSQuery query = PG_GETARG_TSQUERY(2);
800804
float res;
801805

802806
res = calc_rank_cd(getWeights(win), txt, query, DEF_NORM_METHOD);
@@ -811,7 +815,7 @@ Datum
811815
ts_rankcd_ttf(PG_FUNCTION_ARGS)
812816
{
813817
TSVector txt = PG_GETARG_TSVECTOR(0);
814-
TSQuery query = PG_GETARG_TSQUERY_COPY(1); /* copy because we modify the istrue-flag */
818+
TSQuery query = PG_GETARG_TSQUERY(1);
815819
int method = PG_GETARG_INT32(2);
816820
float res;
817821

@@ -826,7 +830,7 @@ Datum
826830
ts_rankcd_tt(PG_FUNCTION_ARGS)
827831
{
828832
TSVector txt = PG_GETARG_TSVECTOR(0);
829-
TSQuery query = PG_GETARG_TSQUERY_COPY(1); /* copy because we modify the istrue-flag */
833+
TSQuery query = PG_GETARG_TSQUERY(1);
830834
float res;
831835

832836
res = calc_rank_cd(getWeights(NULL), txt, query, DEF_NORM_METHOD);

‎src/include/tsearch/ts_type.h

Copy file name to clipboardExpand all lines: src/include/tsearch/ts_type.h
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
77
*
8-
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.5 2007/09/11 08:46:29 teodor Exp $
8+
* $PostgreSQL: pgsql/src/include/tsearch/ts_type.h,v 1.6 2007/09/11 16:01:40 teodor Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -187,8 +187,7 @@ typedef struct
187187

188188
/* pointer to text value of operand, must correlate with WordEntry */
189189
uint32
190-
istrue:1, /* use for ranking in Cover */
191-
length:11,
190+
length:12,
192191
distance:20;
193192
} QueryOperand;
194193

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.