From: Bruce Momjian Date: Mon, 29 Sep 2003 18:22:48 +0000 (+0000) Subject: I discovered that TupleDescGetAttInMetadata and BuildTupleFromCStrings X-Git-Tag: REL7_4_BETA4~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc7a2affabfa62be840338153ccc11b67f7d4441;p=postgresql I discovered that TupleDescGetAttInMetadata and BuildTupleFromCStrings don't deal well with tuples having dropped columns. The attached fixes the issue. Please apply. Joe Conway --- diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index bef10bc635..9df614efbf 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.71 2003/08/08 21:41:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.72 2003/09/29 18:22:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -674,16 +674,20 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc) * Gather info needed later to call the "in" function for each * attribute */ - attinfuncinfo = (FmgrInfo *) palloc(natts * sizeof(FmgrInfo)); - attelems = (Oid *) palloc(natts * sizeof(Oid)); - atttypmods = (int32 *) palloc(natts * sizeof(int32)); + attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo)); + attelems = (Oid *) palloc0(natts * sizeof(Oid)); + atttypmods = (int32 *) palloc0(natts * sizeof(int32)); for (i = 0; i < natts; i++) { - atttypeid = tupdesc->attrs[i]->atttypid; - getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]); - fmgr_info(attinfuncid, &attinfuncinfo[i]); - atttypmods[i] = tupdesc->attrs[i]->atttypmod; + /* Ignore dropped attributes */ + if (!tupdesc->attrs[i]->attisdropped) + { + atttypeid = tupdesc->attrs[i]->atttypid; + getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]); + fmgr_info(attinfuncid, &attinfuncinfo[i]); + atttypmods[i] = tupdesc->attrs[i]->atttypmod; + } } attinmeta->tupdesc = tupdesc; attinmeta->attinfuncs = attinfuncinfo; @@ -712,22 +716,32 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values) dvalues = (Datum *) palloc(natts * sizeof(Datum)); nulls = (char *) palloc(natts * sizeof(char)); - /* Call the "in" function for each non-null attribute */ + /* Call the "in" function for each non-null, non-dropped attribute */ for (i = 0; i < natts; i++) { - if (values[i] != NULL) + if (!tupdesc->attrs[i]->attisdropped) { - attelem = attinmeta->attelems[i]; - atttypmod = attinmeta->atttypmods[i]; - - dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i], - CStringGetDatum(values[i]), - ObjectIdGetDatum(attelem), - Int32GetDatum(atttypmod)); - nulls[i] = ' '; + /* Non-dropped attributes */ + if (values[i] != NULL) + { + attelem = attinmeta->attelems[i]; + atttypmod = attinmeta->atttypmods[i]; + + dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i], + CStringGetDatum(values[i]), + ObjectIdGetDatum(attelem), + Int32GetDatum(atttypmod)); + nulls[i] = ' '; + } + else + { + dvalues[i] = (Datum) 0; + nulls[i] = 'n'; + } } else { + /* Handle dropped attributes by setting to NULL */ dvalues[i] = (Datum) 0; nulls[i] = 'n'; }