diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index 505ae0a..a04ad6e 100644
*** a/src/backend/optimizer/util/clauses.c
--- b/src/backend/optimizer/util/clauses.c
*************** eval_const_expressions_mutator(Node *nod
*** 2567,2573 ****
  					else
  						prm = &paramLI->params[param->paramid - 1];
  
! 					if (OidIsValid(prm->ptype))
  					{
  						/* OK to substitute parameter value? */
  						if (context->estimate ||
--- 2567,2580 ----
  					else
  						prm = &paramLI->params[param->paramid - 1];
  
! 					/*
! 					 * We don't just check OidIsValid, but insist that the
! 					 * fetched type match the Param, just in case the hook did
! 					 * something unexpected.  No need to throw an error here
! 					 * though; leave that for runtime.
! 					 */
! 					if (OidIsValid(prm->ptype) &&
! 						prm->ptype == param->paramtype)
  					{
  						/* OK to substitute parameter value? */
  						if (context->estimate ||
*************** eval_const_expressions_mutator(Node *nod
*** 2583,2589 ****
  							bool		typByVal;
  							Datum		pval;
  
- 							Assert(prm->ptype == param->paramtype);
  							get_typlenbyval(param->paramtype,
  											&typLen, &typByVal);
  							if (prm->isnull || typByVal)
--- 2590,2595 ----
diff --git a/src/pl/plpgsql/src/expected/plpgsql_record.out b/src/pl/plpgsql/src/expected/plpgsql_record.out
index 6ea88b3..b5129b3 100644
*** a/src/pl/plpgsql/src/expected/plpgsql_record.out
--- b/src/pl/plpgsql/src/expected/plpgsql_record.out
*************** alter table mutable drop column f3;
*** 459,464 ****
--- 459,487 ----
  select getf3(null::mutable);  -- fails again
  ERROR:  record "x" has no field "f3"
  \set SHOW_CONTEXT errors
+ -- check behavior with changes in a record rowtype
+ create function show_result_type(text) returns text language plpgsql as
+ $$
+     declare
+         r record;
+         t text;
+     begin
+         execute $1 into r;
+         select pg_typeof(r.a) into t;
+         return format('type %s value %s', t, r.a::text);
+     end;
+ $$;
+ select show_result_type('select 1 as a');
+    show_result_type   
+ ----------------------
+  type integer value 1
+ (1 row)
+ 
+ -- currently this fails, perhaps someday we can make it succeed
+ select show_result_type('select 2.0 as a');
+ ERROR:  type of parameter 5 (numeric) does not match that when preparing the plan (integer)
+ CONTEXT:  SQL statement "select pg_typeof(r.a)"
+ PL/pgSQL function show_result_type(text) line 7 at SQL statement
  -- check access to system columns in a record variable
  create function sillytrig() returns trigger language plpgsql as
  $$begin
diff --git a/src/pl/plpgsql/src/sql/plpgsql_record.sql b/src/pl/plpgsql/src/sql/plpgsql_record.sql
index aba6887..6f638d6 100644
*** a/src/pl/plpgsql/src/sql/plpgsql_record.sql
--- b/src/pl/plpgsql/src/sql/plpgsql_record.sql
*************** alter table mutable drop column f3;
*** 297,302 ****
--- 297,319 ----
  select getf3(null::mutable);  -- fails again
  \set SHOW_CONTEXT errors
  
+ -- check behavior with changes in a record rowtype
+ create function show_result_type(text) returns text language plpgsql as
+ $$
+     declare
+         r record;
+         t text;
+     begin
+         execute $1 into r;
+         select pg_typeof(r.a) into t;
+         return format('type %s value %s', t, r.a::text);
+     end;
+ $$;
+ 
+ select show_result_type('select 1 as a');
+ -- currently this fails, perhaps someday we can make it succeed
+ select show_result_type('select 2.0 as a');
+ 
  -- check access to system columns in a record variable
  
  create function sillytrig() returns trigger language plpgsql as
