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

Re: bug fix: TupleDescGetAttInMetadata/BuildTupleFromCStrings

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: bug fix: TupleDescGetAttInMetadata/BuildTupleFromCStrings
Date: 2003-09-29 18:22:53
Message-ID: 200309291822.h8TIMrr24381@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-patches
Patch applied.  Thanks.

---------------------------------------------------------------------------


Joe Conway wrote:
> I discovered that TupleDescGetAttInMetadata and BuildTupleFromCStrings 
> don't deal well with tuples having dropped columns. The attached fixes 
> the issue. Please apply.
> 
> Thanks,
> 
> Joe

> Index: src/backend/executor/execTuples.c
> ===================================================================
> RCS file: /opt/src/cvs/pgsql-server/src/backend/executor/execTuples.c,v
> retrieving revision 1.71
> diff -c -r1.71 execTuples.c
> *** src/backend/executor/execTuples.c	8 Aug 2003 21:41:40 -0000	1.71
> --- src/backend/executor/execTuples.c	21 Sep 2003 23:23:02 -0000
> ***************
> *** 674,689 ****
>   	 * 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));
>   
>   	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;
>   	}
>   	attinmeta->tupdesc = tupdesc;
>   	attinmeta->attinfuncs = attinfuncinfo;
> --- 674,693 ----
>   	 * Gather info needed later to call the "in" function for each
>   	 * attribute
>   	 */
> ! 	attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
> ! 	attelems = (Oid *) palloc0(natts * sizeof(Oid));
> ! 	atttypmods = (int32 *) palloc0(natts * sizeof(int32));
>   
>   	for (i = 0; i < natts; i++)
>   	{
> ! 		/* 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,733 ****
>   	dvalues = (Datum *) palloc(natts * sizeof(Datum));
>   	nulls = (char *) palloc(natts * sizeof(char));
>   
> ! 	/* Call the "in" function for each non-null attribute */
>   	for (i = 0; i < natts; i++)
>   	{
> ! 		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';
>   		}
> --- 716,747 ----
>   	dvalues = (Datum *) palloc(natts * sizeof(Datum));
>   	nulls = (char *) palloc(natts * sizeof(char));
>   
> ! 	/* Call the "in" function for each non-null, non-dropped attribute */
>   	for (i = 0; i < natts; i++)
>   	{
> ! 		if (!tupdesc->attrs[i]->attisdropped)
>   		{
> ! 			/* 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';
>   		}

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>       message can get through to the mailing list cleanly

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

pgsql-patches by date

Next:From: Bruce MomjianDate: 2003-09-29 18:51:40
Subject: Re: fix log_min_duration_statement logic error
Previous:From: Bruce MomjianDate: 2003-09-29 18:22:16
Subject: Re: patches for WIN32_CONSOLE problem

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