mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	I discovered that TupleDescGetAttInMetadata and BuildTupleFromCStrings
don't deal well with tuples having dropped columns. The attached fixes the issue. Please apply. Joe Conway
This commit is contained in:
		@@ -15,7 +15,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * 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,17 +674,21 @@ TupleDescGetAttInMetadata(TupleDesc tupdesc)
 | 
				
			|||||||
	 * Gather info needed later to call the "in" function for each
 | 
						 * Gather info needed later to call the "in" function for each
 | 
				
			||||||
	 * attribute
 | 
						 * attribute
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	attinfuncinfo = (FmgrInfo *) palloc(natts * sizeof(FmgrInfo));
 | 
						attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
 | 
				
			||||||
	attelems = (Oid *) palloc(natts * sizeof(Oid));
 | 
						attelems = (Oid *) palloc0(natts * sizeof(Oid));
 | 
				
			||||||
	atttypmods = (int32 *) palloc(natts * sizeof(int32));
 | 
						atttypmods = (int32 *) palloc0(natts * sizeof(int32));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < natts; i++)
 | 
						for (i = 0; i < natts; i++)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/* Ignore dropped attributes */
 | 
				
			||||||
 | 
							if (!tupdesc->attrs[i]->attisdropped)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			atttypeid = tupdesc->attrs[i]->atttypid;
 | 
								atttypeid = tupdesc->attrs[i]->atttypid;
 | 
				
			||||||
			getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]);
 | 
								getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]);
 | 
				
			||||||
			fmgr_info(attinfuncid, &attinfuncinfo[i]);
 | 
								fmgr_info(attinfuncid, &attinfuncinfo[i]);
 | 
				
			||||||
			atttypmods[i] = tupdesc->attrs[i]->atttypmod;
 | 
								atttypmods[i] = tupdesc->attrs[i]->atttypmod;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	attinmeta->tupdesc = tupdesc;
 | 
						attinmeta->tupdesc = tupdesc;
 | 
				
			||||||
	attinmeta->attinfuncs = attinfuncinfo;
 | 
						attinmeta->attinfuncs = attinfuncinfo;
 | 
				
			||||||
	attinmeta->attelems = attelems;
 | 
						attinmeta->attelems = attelems;
 | 
				
			||||||
@@ -712,9 +716,12 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
 | 
				
			|||||||
	dvalues = (Datum *) palloc(natts * sizeof(Datum));
 | 
						dvalues = (Datum *) palloc(natts * sizeof(Datum));
 | 
				
			||||||
	nulls = (char *) palloc(natts * sizeof(char));
 | 
						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++)
 | 
						for (i = 0; i < natts; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							if (!tupdesc->attrs[i]->attisdropped)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								/* Non-dropped attributes */
 | 
				
			||||||
			if (values[i] != NULL)
 | 
								if (values[i] != NULL)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				attelem = attinmeta->attelems[i];
 | 
									attelem = attinmeta->attelems[i];
 | 
				
			||||||
@@ -732,6 +739,13 @@ BuildTupleFromCStrings(AttInMetadata *attinmeta, char **values)
 | 
				
			|||||||
				nulls[i] = 'n';
 | 
									nulls[i] = 'n';
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								/* Handle dropped attributes by setting to NULL */
 | 
				
			||||||
 | 
								dvalues[i] = (Datum) 0;
 | 
				
			||||||
 | 
								nulls[i] = 'n';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Form a tuple
 | 
						 * Form a tuple
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user