From 7fdb5fbe2939a95357298a64ee1873b3f8308af2 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Fri, 5 Aug 2016 14:07:42 -0700 Subject: [PATCH] Skip over unreferenced parameters when router executing prepared statement. When an unreferenced prepared statement parameter does not explicitly have a type assigned, we cannot deserialize it, to send to the remote side. That commonly happens inside plpgsql functions, where local variables are passed in as unused prepared statement parameters. --- src/backend/distributed/executor/multi_router_executor.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/executor/multi_router_executor.c b/src/backend/distributed/executor/multi_router_executor.c index 8038feb18..ab8c239b6 100644 --- a/src/backend/distributed/executor/multi_router_executor.c +++ b/src/backend/distributed/executor/multi_router_executor.c @@ -821,7 +821,12 @@ ExtractParametersFromParamListInfo(ParamListInfo paramListInfo, Oid **parameterT (*parameterTypes)[parameterIndex] = parameterData->ptype; } - if (parameterData->isnull) + /* + * If the parameter is NULL, or is not referenced / used (ptype == 0 + * would otherwise have errored out inside standard_planner()), + * don't pass a value to the remote side. + */ + if (parameterData->isnull || parameterData->ptype == 0) { (*parameterValues)[parameterIndex] = NULL; continue;