Commit 902d1cb3, made in 2008, established that the functions heap_formtuple(), heap_modifytuple(), and heap_deformtuple() were deprecated. The commit also actually removed those routines, replacing them with simple wrappers around their real replacements, which are spelled slightly differently and have a slightly different interface (their real replacements are heap_deform_tuple() and friends). The wrappers fulfilled the old, legacy interface, and were added for compatibility with third party code -- the old char 'n'/' ' convention for indicating nulls was bolted on top of calls to the new variants. Bolting that on to the new variants involves a new palloc() + pfree(), which isn't cheap.
Attached patch actually removes heap_formtuple() and friends. Does this seem worthwhile? Does this seem like something that there should be a compatibility release note item for if we proceed? I have not added one yet. I think that enough time has passed that these wrappers are clearly 100% deadwood. If any external extensions are still using heap_formtuple(), they ought to be updated to work with Postgres 9.5 by using the new variants -- a straight switch-over of callers in the style of 902d1cb3 should now work against all supported versions of PostgreSQL, and without macro hacks. Affected external code building against the removed legacy interface will reliably fail to build, forcing the third party code to conform in a non-surprising way. Removing the code seems very low risk. -- Peter Geoghegan
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index 09aea79..045e0a7 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -777,39 +777,6 @@ heap_form_tuple(TupleDesc tupleDescriptor, } /* - * heap_formtuple - * - * construct a tuple from the given values[] and nulls[] arrays - * - * Null attributes are indicated by a 'n' in the appropriate byte - * of nulls[]. Non-null attributes are indicated by a ' ' (space). - * - * OLD API with char 'n'/' ' convention for indicating nulls. - * This is deprecated and should not be used in new code, but we keep it - * around for use by old add-on modules. - */ -HeapTuple -heap_formtuple(TupleDesc tupleDescriptor, - Datum *values, - char *nulls) -{ - HeapTuple tuple; /* return tuple */ - int numberOfAttributes = tupleDescriptor->natts; - bool *boolNulls = (bool *) palloc(numberOfAttributes * sizeof(bool)); - int i; - - for (i = 0; i < numberOfAttributes; i++) - boolNulls[i] = (nulls[i] == 'n'); - - tuple = heap_form_tuple(tupleDescriptor, values, boolNulls); - - pfree(boolNulls); - - return tuple; -} - - -/* * heap_modify_tuple * form a new tuple from an old tuple and a set of replacement values. * @@ -880,44 +847,6 @@ heap_modify_tuple(HeapTuple tuple, } /* - * heap_modifytuple - * - * forms a new tuple from an old tuple and a set of replacement values. - * returns a new palloc'ed tuple. - * - * OLD API with char 'n'/' ' convention for indicating nulls, and - * char 'r'/' ' convention for indicating whether to replace columns. - * This is deprecated and should not be used in new code, but we keep it - * around for use by old add-on modules. - */ -HeapTuple -heap_modifytuple(HeapTuple tuple, - TupleDesc tupleDesc, - Datum *replValues, - char *replNulls, - char *replActions) -{ - HeapTuple result; - int numberOfAttributes = tupleDesc->natts; - bool *boolNulls = (bool *) palloc(numberOfAttributes * sizeof(bool)); - bool *boolActions = (bool *) palloc(numberOfAttributes * sizeof(bool)); - int attnum; - - for (attnum = 0; attnum < numberOfAttributes; attnum++) - { - boolNulls[attnum] = (replNulls[attnum] == 'n'); - boolActions[attnum] = (replActions[attnum] == 'r'); - } - - result = heap_modify_tuple(tuple, tupleDesc, replValues, boolNulls, boolActions); - - pfree(boolNulls); - pfree(boolActions); - - return result; -} - -/* * heap_deform_tuple * Given a tuple, extract data into values/isnull arrays; this is * the inverse of heap_form_tuple. @@ -1025,46 +954,6 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, } /* - * heap_deformtuple - * - * Given a tuple, extract data into values/nulls arrays; this is - * the inverse of heap_formtuple. - * - * Storage for the values/nulls arrays is provided by the caller; - * it should be sized according to tupleDesc->natts not - * HeapTupleHeaderGetNatts(tuple->t_data). - * - * Note that for pass-by-reference datatypes, the pointer placed - * in the Datum will point into the given tuple. - * - * When all or most of a tuple's fields need to be extracted, - * this routine will be significantly quicker than a loop around - * heap_getattr; the loop will become O(N^2) as soon as any - * noncacheable attribute offsets are involved. - * - * OLD API with char 'n'/' ' convention for indicating nulls. - * This is deprecated and should not be used in new code, but we keep it - * around for use by old add-on modules. - */ -void -heap_deformtuple(HeapTuple tuple, - TupleDesc tupleDesc, - Datum *values, - char *nulls) -{ - int natts = tupleDesc->natts; - bool *boolNulls = (bool *) palloc(natts * sizeof(bool)); - int attnum; - - heap_deform_tuple(tuple, tupleDesc, values, boolNulls); - - for (attnum = 0; attnum < natts; attnum++) - nulls[attnum] = (boolNulls[attnum] ? 'n' : ' '); - - pfree(boolNulls); -} - -/* * slot_deform_tuple * Given a TupleTableSlot, extract data from the slot's physical tuple * into its Datum/isnull arrays. Data is extracted up through the diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h index 55d483d..8dd530bd 100644 --- a/src/include/access/htup_details.h +++ b/src/include/access/htup_details.h @@ -782,17 +782,6 @@ extern HeapTuple heap_modify_tuple(HeapTuple tuple, bool *doReplace); extern void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull); - -/* these three are deprecated versions of the three above: */ -extern HeapTuple heap_formtuple(TupleDesc tupleDescriptor, - Datum *values, char *nulls); -extern HeapTuple heap_modifytuple(HeapTuple tuple, - TupleDesc tupleDesc, - Datum *replValues, - char *replNulls, - char *replActions); -extern void heap_deformtuple(HeapTuple tuple, TupleDesc tupleDesc, - Datum *values, char *nulls); extern void heap_freetuple(HeapTuple htup); extern MinimalTuple heap_form_minimal_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers