Skip to content

Commit 3b8bca3

Browse files
committed
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.
1 parent 588d213 commit 3b8bca3

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/backend/tsearch/to_tsany.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.9 2008/03/05 15:50:37 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.10 2008/03/07 14:30:20 teodor Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -350,6 +350,18 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
350350
PG_RETURN_POINTER(query);
351351
}
352352
memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem));
353+
354+
if ( len != query->size ) {
355+
char *oldoperand = GETOPERAND(query);
356+
int4 lenoperand = VARSIZE(query) - (oldoperand - (char*)query);
357+
358+
Assert( len < query->size );
359+
360+
query->size = len;
361+
memcpy((void *) GETOPERAND(query), oldoperand, VARSIZE(query) - (oldoperand - (char*)query) );
362+
SET_VARSIZE(query, COMPUTESIZE( len, lenoperand ));
363+
}
364+
353365
pfree(res);
354366
PG_RETURN_TSQUERY(query);
355367
}
@@ -388,6 +400,18 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
388400
PG_RETURN_POINTER(query);
389401
}
390402
memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(QueryItem));
403+
404+
if ( len != query->size ) {
405+
char *oldoperand = GETOPERAND(query);
406+
int4 lenoperand = VARSIZE(query) - (oldoperand - (char*)query);
407+
408+
Assert( len < query->size );
409+
410+
query->size = len;
411+
memcpy((void *) GETOPERAND(query), oldoperand, lenoperand );
412+
SET_VARSIZE(query, COMPUTESIZE( len, lenoperand ));
413+
}
414+
391415
pfree(res);
392416
PG_RETURN_POINTER(query);
393417
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy