Skip site navigation (1) Skip section navigation (2)

Re: Latest on CITEXT 2.0

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Latest on CITEXT 2.0
Date: 2008-06-26 16:38:21
Message-ID: 7BDE8C80-B9FC-459A-902C-2EDF99A5C8EF@kineticode.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Jun 26, 2008, at 09:19, Alvaro Herrera wrote:

> PG_GETARG_TEXT_P can detoast the datum, which creates a copy.

Thanks. I've just completely refactored things to look more like the  
approach taken by varlena.c, both in terms of when stuff gets freed  
and in terms of coding style. It's more verbose, but I feel much more  
comfortable with memory management now that I'm following a known  
implementation more closely. :-)

So now I've changed citextcmp to this:

static int
citextcmp (text * left, text * right)
{
     char * lcstr, * rcstr;
     int    result;

     lcstr = cilower( left  );
     rcstr = cilower( right );

     result = varstr_cmp(
         cilower( left ),
         VARSIZE_ANY_EXHDR(left),
         cilower( right ),
         VARSIZE_ANY_EXHDR(right)
     );

     pfree( lcstr );
     pfree( rcstr );
     return result;
}

And now all of the operator functions are freeing memory using  
PG_FREE_IF_COPY() like this:

Datum
citext_cmp(PG_FUNCTION_ARGS)
{
	text * left  = PG_GETARG_TEXT_PP(0);
	text * right = PG_GETARG_TEXT_PP(1);
	int32  result;

	result = citextcmp(left, right);

	PG_FREE_IF_COPY(left, 0);
	PG_FREE_IF_COPY(right, 1);

         PG_RETURN_INT32( result );
}


The only functions that don't do that are citext_smaller() and  
citext_larger():

Datum
citext_smaller(PG_FUNCTION_ARGS)
{
	text * left  = PG_GETARG_TEXT_PP(0);
	text * right = PG_GETARG_TEXT_PP(1);
	text * result;

	result = citextcmp(left, right) < 0 ? left : right;
	PG_RETURN_TEXT_P(result);
}

This is just how varlena.c does it, but I am wondering if something  
*should* be freed there.

Thanks a bunch!

Best,

David


In response to

Responses

pgsql-hackers by date

Next:From: Hiroshi SaitoDate: 2008-06-26 16:42:29
Subject: Re: MSVC 2003 compile error with pg8.3.3
Previous:From: Robert HaasDate: 2008-06-26 16:36:15
Subject: Re: Planner creating ineffective plans on LEFT OUTER joins

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group