diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2007-09-11 08:46:29 +0000 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2007-09-11 08:46:29 +0000 |
commit | 57cafe79823dcd3653cf5e19cbdf58300cb1576c (patch) | |
tree | 8616fa0d0c77fd151cf874184fa5f21f56717aef /src/backend/utils/adt/tsvector_op.c | |
parent | ef4d38c86c1b1f834bd70115fd19f03431573c2d (diff) | |
download | postgresql-57cafe79823dcd3653cf5e19cbdf58300cb1576c.tar.gz |
Refactor from Heikki Linnakangas <heikki@enterprisedb.com>:
* Defined new struct WordEntryPosVector that holds a uint16 length and a
variable size array of WordEntries. This replaces the previous
convention of a variable size uint16 array, with the first element
implying the length. WordEntryPosVector has the same layout in memory,
but is more readable in source code. The POSDATAPTR and POSDATALEN
macros are still used, though it would now be more readable to access
the fields in WordEntryPosVector directly.
* Removed needfree field from DocRepresentation. It was always set to false.
* Miscellaneous other commenting and refactoring
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r-- | src/backend/utils/adt/tsvector_op.c | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 8e7593513f..e150f9a267 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.4 2007/09/07 16:03:40 teodor Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.5 2007/09/11 08:46:29 teodor Exp $ * *------------------------------------------------------------------------- */ @@ -269,7 +269,7 @@ compareEntry(char *ptra, WordEntry * a, char *ptrb, WordEntry * b) static int4 add_pos(TSVector src, WordEntry * srcptr, TSVector dest, WordEntry * destptr, int4 maxpos) { - uint16 *clen = (uint16 *) _POSDATAPTR(dest, destptr); + uint16 *clen = &_POSVECPTR(dest, destptr)->npos; int i; uint16 slen = POSDATALEN(src, srcptr), startlen; @@ -354,7 +354,7 @@ tsvector_concat(PG_FUNCTION_ARGS) if (ptr->haspos) { cur += SHORTALIGN(ptr1->len); - memcpy(cur, _POSDATAPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); + memcpy(cur, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); cur += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16); } else @@ -399,7 +399,7 @@ tsvector_concat(PG_FUNCTION_ARGS) cur += SHORTALIGN(ptr1->len); if (ptr1->haspos) { - memcpy(cur, _POSDATAPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); + memcpy(cur, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); cur += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16); if (ptr2->haspos) cur += add_pos(in2, ptr2, out, ptr, maxpos) * sizeof(WordEntryPos); @@ -434,7 +434,7 @@ tsvector_concat(PG_FUNCTION_ARGS) if (ptr->haspos) { cur += SHORTALIGN(ptr1->len); - memcpy(cur, _POSDATAPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); + memcpy(cur, _POSVECPTR(in1, ptr1), POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16)); cur += POSDATALEN(in1, ptr1) * sizeof(WordEntryPos) + sizeof(uint16); } else @@ -499,10 +499,17 @@ ValCompare(CHKVAL * chkval, WordEntry * ptr, QueryOperand * item) * check weight info */ static bool -checkclass_str(CHKVAL * chkval, WordEntry * val, QueryOperand * item) +checkclass_str(CHKVAL *chkval, WordEntry *val, QueryOperand *item) { - WordEntryPos *ptr = (WordEntryPos *) (chkval->values + SHORTALIGN(val->pos + val->len) + sizeof(uint16)); - uint16 len = *((uint16 *) (chkval->values + SHORTALIGN(val->pos + val->len))); + WordEntryPosVector *posvec; + WordEntryPos *ptr; + uint16 len; + + posvec = (WordEntryPosVector *) + (chkval->values + SHORTALIGN(val->pos + val->len)); + + len = posvec->npos; + ptr = posvec->pos; while (len--) { @@ -674,7 +681,13 @@ ts_match_tq(PG_FUNCTION_ARGS) } /* - * Statistics of tsvector + * ts_stat statistic function support + */ + + +/* + * Returns the number of positions in value 'wptr' within tsvector 'txt', + * that have a weight equal to one of the weights in 'weight' bitmask. */ static int check_weight(TSVector txt, WordEntry * wptr, int8 weight) @@ -824,6 +837,18 @@ formstat(tsstat * stat, TSVector txt, WordEntry ** entry, uint32 len) return newstat; } +/* + * This is written like a custom aggregate function, because the + * original plan was to do just that. Unfortunately, an aggregate function + * can't return a set, so that plan was abandoned. If that limitation is + * lifted in the future, ts_stat could be a real aggregate function so that + * you could use it like this: + * + * SELECT ts_stat(vector_column) FROM vector_table; + * + * where vector_column is a tsvector-type column in vector_table. + */ + static tsstat * ts_accum(tsstat * stat, Datum data) { |