diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2008-03-07 14:30:20 +0000 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2008-03-07 14:30:20 +0000 |
commit | 3b8bca335d3f86e74aae7923164877a694b5049a (patch) | |
tree | a4388f3cd82cb657777cd08721f8c865738c3a1e /src | |
parent | 588d213a929164e25d8a4fcf146a88e0edc173ae (diff) | |
download | postgresql-3b8bca335d3f86e74aae7923164877a694b5049a.tar.gz postgresql-3b8bca335d3f86e74aae7923164877a694b5049a.zip |
Fix memory arrangement of tsquery after removing stop words. It causes
a unused memory holes in tsquery.
Per report by Richard Huxton <dev@archonet.com>.
It was working well because in fact tsquery->size is not used for any
kind of operation except comparing tsqueries. So, in HEAD it's enough to
fix to_tsquery function, but for previous version it's needed to
remove optimization in CompareTSQ to prevent requirement of renew all
stored tsquery.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/tsearch/to_tsany.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/tsearch/to_tsany.c b/src/backend/tsearch/to_tsany.c index 17b86ec03e2..5e1f82ba59c 100644 --- a/src/backend/tsearch/to_tsany.c +++ b/src/backend/tsearch/to_tsany.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.9 2008/03/05 15:50:37 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.10 2008/03/07 14:30:20 teodor Exp $ * *------------------------------------------------------------------------- */ @@ -350,6 +350,18 @@ to_tsquery_byid(PG_FUNCTION_ARGS) PG_RETURN_POINTER(query); } memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem)); + + if ( len != query->size ) { + char *oldoperand = GETOPERAND(query); + int4 lenoperand = VARSIZE(query) - (oldoperand - (char*)query); + + Assert( len < query->size ); + + query->size = len; + memcpy((void *) GETOPERAND(query), oldoperand, VARSIZE(query) - (oldoperand - (char*)query) ); + SET_VARSIZE(query, COMPUTESIZE( len, lenoperand )); + } + pfree(res); PG_RETURN_TSQUERY(query); } @@ -388,6 +400,18 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS) PG_RETURN_POINTER(query); } memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem)); + + if ( len != query->size ) { + char *oldoperand = GETOPERAND(query); + int4 lenoperand = VARSIZE(query) - (oldoperand - (char*)query); + + Assert( len < query->size ); + + query->size = len; + memcpy((void *) GETOPERAND(query), oldoperand, lenoperand ); + SET_VARSIZE(query, COMPUTESIZE( len, lenoperand )); + } + pfree(res); PG_RETURN_POINTER(query); } |