mirror of
https://github.com/postgres/postgres.git
synced 2025-05-15 19:15:29 +03:00
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. To prevent requirement of renew all stored tsquery optimization in CompareTSQ is removed.
This commit is contained in:
parent
ffeae03742
commit
b7a2ab5b6e
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.8 2008/01/01 19:45:52 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/tsearch/to_tsany.c,v 1.8.2.1 2008/03/07 15:29:27 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);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.3 2008/01/01 19:45:53 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/tsquery_op.c,v 1.3.2.1 2008/03/07 15:29:27 teodor Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -141,27 +141,14 @@ tsquery_not(PG_FUNCTION_ARGS)
|
||||
static int
|
||||
CompareTSQ(TSQuery a, TSQuery b)
|
||||
{
|
||||
if (a->size != b->size)
|
||||
{
|
||||
return (a->size < b->size) ? -1 : 1;
|
||||
}
|
||||
else if (VARSIZE(a) != VARSIZE(b))
|
||||
{
|
||||
return (VARSIZE(a) < VARSIZE(b)) ? -1 : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a));
|
||||
QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b));
|
||||
int res = QTNodeCompare(an, bn);
|
||||
QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a));
|
||||
QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b));
|
||||
int res = QTNodeCompare(an, bn);
|
||||
|
||||
QTNFree(an);
|
||||
QTNFree(bn);
|
||||
QTNFree(an);
|
||||
QTNFree(bn);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
Datum
|
||||
|
Loading…
x
Reference in New Issue
Block a user