mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Resurrect heap_deformtuple(), this time implemented as a singly nested
loop over the fields instead of a loop around heap_getattr. This is considerably faster (O(N) instead of O(N^2)) when there are nulls or varlena fields, since those prevent use of attcacheoff. Replace loops over heap_getattr with heap_deformtuple in situations where all or most of the fields have to be fetched, such as printtup and tuptoaster. Profiling done more than a year ago shows that this should be a nice win for situations involving many-column tables.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.115 2004/05/30 23:40:26 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.116 2004/06/04 20:35:21 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -427,7 +427,6 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
|
||||
int numberOfAttributes;
|
||||
Datum *v;
|
||||
char *n;
|
||||
bool isnull;
|
||||
int i;
|
||||
|
||||
if (rel == NULL || tuple == NULL || natts < 0 || attnum == NULL || Values == NULL)
|
||||
@ -448,11 +447,7 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
|
||||
n = (char *) palloc(numberOfAttributes * sizeof(char));
|
||||
|
||||
/* fetch old values and nulls */
|
||||
for (i = 0; i < numberOfAttributes; i++)
|
||||
{
|
||||
v[i] = heap_getattr(tuple, i + 1, rel->rd_att, &isnull);
|
||||
n[i] = (isnull) ? 'n' : ' ';
|
||||
}
|
||||
heap_deformtuple(tuple, rel->rd_att, v, n);
|
||||
|
||||
/* replace values and nulls */
|
||||
for (i = 0; i < natts; i++)
|
||||
@ -474,7 +469,7 @@ SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum,
|
||||
mtuple->t_data->t_ctid = tuple->t_data->t_ctid;
|
||||
mtuple->t_self = tuple->t_self;
|
||||
mtuple->t_tableOid = tuple->t_tableOid;
|
||||
if (rel->rd_rel->relhasoids)
|
||||
if (rel->rd_att->tdhasoid)
|
||||
HeapTupleSetOid(mtuple, HeapTupleGetOid(tuple));
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user