diff -cr pgsql/src/pl/plpgsql/src/gram.y pgsql-plpgsqlfldnum/src/pl/plpgsql/src/gram.y
*** pgsql/src/pl/plpgsql/src/gram.y	Tue Sep  9 21:09:45 2008
--- pgsql-plpgsqlfldnum/src/pl/plpgsql/src/gram.y	Tue Nov  4 17:56:18 2008
***************
*** 430,436 ****
  						if ($5 == NULL)
  							new->cursor_explicit_argrow = -1;
  						else
! 							new->cursor_explicit_argrow = $5->rowno;
  						new->cursor_options = CURSOR_OPT_FAST_PLAN | $2;
  					}
  				;
--- 430,436 ----
  						if ($5 == NULL)
  							new->cursor_explicit_argrow = -1;
  						else
! 							new->cursor_explicit_argrow = $5->dno;
  						new->cursor_options = CURSOR_OPT_FAST_PLAN | $2;
  					}
  				;
***************
*** 764,775 ****
  				| T_ROW
  					{
  						check_assignable((PLpgSQL_datum *) yylval.row);
! 						$$ = yylval.row->rowno;
  					}
  				| T_RECORD
  					{
  						check_assignable((PLpgSQL_datum *) yylval.rec);
! 						$$ = yylval.rec->recno;
  					}
  				| assign_var '[' expr_until_rightbracket
  					{
--- 764,775 ----
  				| T_ROW
  					{
  						check_assignable((PLpgSQL_datum *) yylval.row);
! 						$$ = yylval.row->dno;
  					}
  				| T_RECORD
  					{
  						check_assignable((PLpgSQL_datum *) yylval.rec);
! 						$$ = yylval.rec->dno;
  					}
  				| assign_var '[' expr_until_rightbracket
  					{
***************
*** 1036,1042 ****
  							new->cmd_type = PLPGSQL_STMT_FORC;
  							new->lineno = $1;
  
! 							new->curvar = cursor->varno;
  
  							/* Should have had a single variable name */
  							plpgsql_error_lineno = $2.lineno;
--- 1036,1042 ----
  							new->cmd_type = PLPGSQL_STMT_FORC;
  							new->lineno = $1;
  
! 							new->curvar = cursor->dno;
  
  							/* Should have had a single variable name */
  							plpgsql_error_lineno = $2.lineno;
***************
*** 1557,1563 ****
  						new = palloc0(sizeof(PLpgSQL_stmt_open));
  						new->cmd_type = PLPGSQL_STMT_OPEN;
  						new->lineno = $2;
! 						new->curvar = $3->varno;
  						new->cursor_options = CURSOR_OPT_FAST_PLAN;
  
  						if ($3->cursor_explicit_expr == NULL)
--- 1557,1563 ----
  						new = palloc0(sizeof(PLpgSQL_stmt_open));
  						new->cmd_type = PLPGSQL_STMT_OPEN;
  						new->lineno = $2;
! 						new->curvar = $3->dno;
  						new->cursor_options = CURSOR_OPT_FAST_PLAN;
  
  						if ($3->cursor_explicit_expr == NULL)
***************
*** 1621,1627 ****
  						fetch->lineno = $2;
  						fetch->rec		= rec;
  						fetch->row		= row;
! 						fetch->curvar	= $4->varno;
  						fetch->is_move	= false;
  
  						$$ = (PLpgSQL_stmt *)fetch;
--- 1621,1627 ----
  						fetch->lineno = $2;
  						fetch->rec		= rec;
  						fetch->row		= row;
! 						fetch->curvar	= $4->dno;
  						fetch->is_move	= false;
  
  						$$ = (PLpgSQL_stmt *)fetch;
***************
*** 1633,1639 ****
  						PLpgSQL_stmt_fetch *fetch = $3;
  
  						fetch->lineno = $2;
! 						fetch->curvar	= $4->varno;
  						fetch->is_move	= true;
  
  						$$ = (PLpgSQL_stmt *)fetch;
--- 1633,1639 ----
  						PLpgSQL_stmt_fetch *fetch = $3;
  
  						fetch->lineno = $2;
! 						fetch->curvar	= $4->dno;
  						fetch->is_move	= true;
  
  						$$ = (PLpgSQL_stmt *)fetch;
***************
*** 1653,1659 ****
  						new = palloc(sizeof(PLpgSQL_stmt_close));
  						new->cmd_type = PLPGSQL_STMT_CLOSE;
  						new->lineno = $2;
! 						new->curvar = $3->varno;
  
  						$$ = (PLpgSQL_stmt *)new;
  					}
--- 1653,1659 ----
  						new = palloc(sizeof(PLpgSQL_stmt_close));
  						new->cmd_type = PLPGSQL_STMT_CLOSE;
  						new->lineno = $2;
! 						new->curvar = $3->dno;
  
  						$$ = (PLpgSQL_stmt *)new;
  					}
***************
*** 2039,2052 ****
  
  			case T_ROW:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.row->rowno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
  
  			case T_RECORD:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.rec->recno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
--- 2039,2052 ----
  
  			case T_ROW:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.row->dno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
  
  			case T_RECORD:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.rec->dno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
***************
*** 2190,2203 ****
  
  			case T_ROW:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.row->rowno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
  
  			case T_RECORD:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.rec->recno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
--- 2190,2203 ----
  
  			case T_ROW:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.row->dno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
  
  			case T_RECORD:
  				snprintf(buf, sizeof(buf), " $%d ",
! 						 assign_expr_param(yylval.rec->dno,
  										   params, &nparams));
  				plpgsql_dstring_append(&ds, buf);
  				break;
***************
*** 2363,2373 ****
  				break;
  
  			case T_ROW:
! 				new->retvarno = yylval.row->rowno;
  				break;
  
  			case T_RECORD:
! 				new->retvarno = yylval.rec->recno;
  				break;
  
  			default:
--- 2363,2373 ----
  				break;
  
  			case T_ROW:
! 				new->retvarno = yylval.row->dno;
  				break;
  
  			case T_RECORD:
! 				new->retvarno = yylval.rec->dno;
  				break;
  
  			default:
***************
*** 2416,2426 ****
  		switch (yylex())
  		{
  			case T_ROW:
! 				new->retvarno = yylval.row->rowno;
  				break;
  
  			case T_RECORD:
! 				new->retvarno = yylval.rec->recno;
  				break;
  
  			default:
--- 2416,2426 ----
  		switch (yylex())
  		{
  			case T_ROW:
! 				new->retvarno = yylval.row->dno;
  				break;
  
  			case T_RECORD:
! 				new->retvarno = yylval.rec->dno;
  				break;
  
  			default:
***************
*** 2953,2959 ****
  			plpgsql_build_variable("*case*", lineno,
  								   plpgsql_build_datatype(INT4OID, -1),
  								   false);
! 		t_varno = t_var->varno;
  		new->t_varno = t_varno;
  
  		foreach(l, case_when_list)
--- 2953,2959 ----
  			plpgsql_build_variable("*case*", lineno,
  								   plpgsql_build_datatype(INT4OID, -1),
  								   false);
! 		t_varno = t_var->dno;
  		new->t_varno = t_varno;
  
  		foreach(l, case_when_list)
diff -cr pgsql/src/pl/plpgsql/src/pl_comp.c pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_comp.c
*** pgsql/src/pl/plpgsql/src/pl_comp.c	Thu Oct  9 12:35:07 2008
--- pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_comp.c	Tue Nov  4 17:57:07 2008
***************
*** 468,474 ****
  													   num_out_args);
  
  				plpgsql_adddatum((PLpgSQL_datum *) row);
! 				function->out_param_varno = row->rowno;
  			}
  
  			/*
--- 468,474 ----
  													   num_out_args);
  
  				plpgsql_adddatum((PLpgSQL_datum *) row);
! 				function->out_param_varno = row->dno;
  			}
  
  			/*
***************
*** 580,590 ****
  
  			/* Add the record for referencing NEW */
  			rec = plpgsql_build_record("new", 0, true);
! 			function->new_varno = rec->recno;
  
  			/* Add the record for referencing OLD */
  			rec = plpgsql_build_record("old", 0, true);
! 			function->old_varno = rec->recno;
  
  			/* Add the variable tg_name */
  			var = plpgsql_build_variable("tg_name", 0,
--- 580,590 ----
  
  			/* Add the record for referencing NEW */
  			rec = plpgsql_build_record("new", 0, true);
! 			function->new_varno = rec->dno;
  
  			/* Add the record for referencing OLD */
  			rec = plpgsql_build_record("old", 0, true);
! 			function->old_varno = rec->dno;
  
  			/* Add the variable tg_name */
  			var = plpgsql_build_variable("tg_name", 0,
***************
*** 1445,1451 ****
  				plpgsql_adddatum((PLpgSQL_datum *) var);
  				if (add2namespace)
  					plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR,
! 									   var->varno,
  									   refname);
  				result = (PLpgSQL_variable *) var;
  				break;
--- 1445,1451 ----
  				plpgsql_adddatum((PLpgSQL_datum *) var);
  				if (add2namespace)
  					plpgsql_ns_additem(PLPGSQL_NSTYPE_VAR,
! 									   var->dno,
  									   refname);
  				result = (PLpgSQL_variable *) var;
  				break;
***************
*** 1464,1470 ****
  				plpgsql_adddatum((PLpgSQL_datum *) row);
  				if (add2namespace)
  					plpgsql_ns_additem(PLPGSQL_NSTYPE_ROW,
! 									   row->rowno,
  									   refname);
  				result = (PLpgSQL_variable *) row;
  				break;
--- 1464,1470 ----
  				plpgsql_adddatum((PLpgSQL_datum *) row);
  				if (add2namespace)
  					plpgsql_ns_additem(PLPGSQL_NSTYPE_ROW,
! 									   row->dno,
  									   refname);
  				result = (PLpgSQL_variable *) row;
  				break;
***************
*** 1511,1517 ****
  	rec->freetup = false;
  	plpgsql_adddatum((PLpgSQL_datum *) rec);
  	if (add2namespace)
! 		plpgsql_ns_additem(PLPGSQL_NSTYPE_REC, rec->recno, rec->refname);
  
  	return rec;
  }
--- 1511,1517 ----
  	rec->freetup = false;
  	plpgsql_adddatum((PLpgSQL_datum *) rec);
  	if (add2namespace)
! 		plpgsql_ns_additem(PLPGSQL_NSTYPE_REC, rec->dno, rec->refname);
  
  	return rec;
  }
diff -cr pgsql/src/pl/plpgsql/src/pl_exec.c pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_exec.c
*** pgsql/src/pl/plpgsql/src/pl_exec.c	Wed Sep 24 10:40:00 2008
--- pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_exec.c	Tue Nov  4 17:57:38 2008
***************
*** 1665,1671 ****
  	bool		found = false;
  	int			rc = PLPGSQL_RC_OK;
  
! 	var = (PLpgSQL_var *) (estate->datums[stmt->var->varno]);
  
  	/*
  	 * Get the value of the lower bound
--- 1665,1671 ----
  	bool		found = false;
  	int			rc = PLPGSQL_RC_OK;
  
! 	var = (PLpgSQL_var *) (estate->datums[stmt->var->dno]);
  
  	/*
  	 * Get the value of the lower bound
***************
*** 2829,2837 ****
  
  		/* Determine if we assign to a record or a row */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
  		else
  			elog(ERROR, "unsupported target");
  
--- 2829,2837 ----
  
  		/* Determine if we assign to a record or a row */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->dno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->dno]);
  		else
  			elog(ERROR, "unsupported target");
  
***************
*** 3007,3015 ****
  
  		/* Determine if we assign to a record or a row */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
  		else
  			elog(ERROR, "unsupported target");
  
--- 3007,3015 ----
  
  		/* Determine if we assign to a record or a row */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->dno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->dno]);
  		else
  			elog(ERROR, "unsupported target");
  
***************
*** 3318,3326 ****
  		 * ----------
  		 */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
  		else
  			elog(ERROR, "unsupported target");
  
--- 3318,3326 ----
  		 * ----------
  		 */
  		if (stmt->rec != NULL)
! 			rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->dno]);
  		else if (stmt->row != NULL)
! 			row = (PLpgSQL_row *) (estate->datums[stmt->row->dno]);
  		else
  			elog(ERROR, "unsupported target");
  
***************
*** 4180,4188 ****
  	 * Determine if we assign to a record or a row
  	 */
  	if (stmt->rec != NULL)
! 		rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->recno]);
  	else if (stmt->row != NULL)
! 		row = (PLpgSQL_row *) (estate->datums[stmt->row->rowno]);
  	else
  		elog(ERROR, "unsupported target");
  
--- 4180,4188 ----
  	 * Determine if we assign to a record or a row
  	 */
  	if (stmt->rec != NULL)
! 		rec = (PLpgSQL_rec *) (estate->datums[stmt->rec->dno]);
  	else if (stmt->row != NULL)
! 		row = (PLpgSQL_row *) (estate->datums[stmt->row->dno]);
  	else
  		elog(ERROR, "unsupported target");
  
diff -cr pgsql/src/pl/plpgsql/src/pl_funcs.c pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_funcs.c
*** pgsql/src/pl/plpgsql/src/pl_funcs.c	Fri Aug 29 09:02:33 2008
--- pgsql-plpgsqlfldnum/src/pl/plpgsql/src/pl_funcs.c	Tue Nov  4 18:02:31 2008
***************
*** 893,904 ****
  		if (stmt->rec != NULL)
  		{
  			dump_ind();
! 			printf("    target = %d %s\n", stmt->rec->recno, stmt->rec->refname);
  		}
  		if (stmt->row != NULL)
  		{
  			dump_ind();
! 			printf("    target = %d %s\n", stmt->row->rowno, stmt->row->refname);
  		}
  		dump_indent -= 2;
  	}
--- 893,904 ----
  		if (stmt->rec != NULL)
  		{
  			dump_ind();
! 			printf("    target = %d %s\n", stmt->rec->dno, stmt->rec->refname);
  		}
  		if (stmt->row != NULL)
  		{
  			dump_ind();
! 			printf("    target = %d %s\n", stmt->row->dno, stmt->row->refname);
  		}
  		dump_indent -= 2;
  	}
***************
*** 1107,1120 ****
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->rec->recno, stmt->rec->refname);
  	}
  	if (stmt->row != NULL)
  	{
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->row->rowno, stmt->row->refname);
  	}
  	dump_indent -= 2;
  }
--- 1107,1120 ----
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->rec->dno, stmt->rec->refname);
  	}
  	if (stmt->row != NULL)
  	{
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->row->dno, stmt->row->refname);
  	}
  	dump_indent -= 2;
  }
***************
*** 1133,1146 ****
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->rec->recno, stmt->rec->refname);
  	}
  	if (stmt->row != NULL)
  	{
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->row->rowno, stmt->row->refname);
  	}
  	if (stmt->params != NIL)
  	{
--- 1133,1146 ----
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->rec->dno, stmt->rec->refname);
  	}
  	if (stmt->row != NULL)
  	{
  		dump_ind();
  		printf("    INTO%s target = %d %s\n",
  			   stmt->strict ? " STRICT" : "",
! 			   stmt->row->dno, stmt->row->refname);
  	}
  	if (stmt->params != NIL)
  	{
diff -cr pgsql/src/pl/plpgsql/src/plpgsql.h pgsql-plpgsqlfldnum/src/pl/plpgsql/src/plpgsql.h
*** pgsql/src/pl/plpgsql/src/plpgsql.h	Thu Oct  9 13:24:05 2008
--- pgsql-plpgsqlfldnum/src/pl/plpgsql/src/plpgsql.h	Tue Nov  4 17:55:44 2008
***************
*** 191,197 ****
  typedef struct PLpgSQL_expr
  {								/* SQL Query to plan and execute	*/
  	int			dtype;
! 	int			exprno;
  	char	   *query;
  	SPIPlanPtr	plan;
  	Oid		   *plan_argtypes;
--- 191,197 ----
  typedef struct PLpgSQL_expr
  {								/* SQL Query to plan and execute	*/
  	int			dtype;
! 	int			dno;
  	char	   *query;
  	SPIPlanPtr	plan;
  	Oid		   *plan_argtypes;
***************
*** 217,223 ****
  typedef struct
  {								/* Scalar variable */
  	int			dtype;
! 	int			varno;
  	char	   *refname;
  	int			lineno;
  
--- 217,223 ----
  typedef struct
  {								/* Scalar variable */
  	int			dtype;
! 	int			dno;
  	char	   *refname;
  	int			lineno;
  
***************
*** 238,244 ****
  typedef struct
  {								/* Row variable */
  	int			dtype;
! 	int			rowno;
  	char	   *refname;
  	int			lineno;
  
--- 238,244 ----
  typedef struct
  {								/* Row variable */
  	int			dtype;
! 	int			dno;
  	char	   *refname;
  	int			lineno;
  
***************
*** 260,266 ****
  typedef struct
  {								/* Record variable (non-fixed structure) */
  	int			dtype;
! 	int			recno;
  	char	   *refname;
  	int			lineno;
  
--- 260,266 ----
  typedef struct
  {								/* Record variable (non-fixed structure) */
  	int			dtype;
! 	int			dno;
  	char	   *refname;
  	int			lineno;
  
***************
*** 274,280 ****
  typedef struct
  {								/* Field in record */
  	int			dtype;
! 	int			rfno;
  	char	   *fieldname;
  	int			recparentno;	/* dno of parent record */
  } PLpgSQL_recfield;
--- 274,280 ----
  typedef struct
  {								/* Field in record */
  	int			dtype;
! 	int			dno;
  	char	   *fieldname;
  	int			recparentno;	/* dno of parent record */
  } PLpgSQL_recfield;