Fix oversight in my recent patch to allow ExecMakeFunctionResult to handle
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Dec 2008 19:38:22 +0000 (19:38 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Dec 2008 19:38:22 +0000 (19:38 +0000)
materialize-mode set results.  Since it now uses the ReturnSetInfo node
to hold internal state, we need to be sure to set up the node even when
the immediately called function doesn't return set (but does have a set-valued
argument).  Per report from Anupama Aherrao.

src/backend/executor/execQual.c

index 8df00ed94a5e9b319a2700702d5ab8697c58107d..9755713dc3af76e2bfdce5d2762a2c7a17d5d3ff 100644 (file)
@@ -1433,23 +1433,6 @@ restart:
                fcache->setArgsValid = false;
        }
 
-       /*
-        * If function returns set, prepare a resultinfo node for communication
-        */
-       if (fcache->func.fn_retset)
-       {
-               fcinfo->resultinfo = (Node *) &rsinfo;
-               rsinfo.type = T_ReturnSetInfo;
-               rsinfo.econtext = econtext;
-               rsinfo.expectedDesc = fcache->funcResultDesc;
-               rsinfo.allowedModes = (int) (SFRM_ValuePerCall | SFRM_Materialize);
-               /* note we do not set SFRM_Materialize_Random or _Preferred */
-               rsinfo.returnMode = SFRM_ValuePerCall;
-               /* isDone is filled below */
-               rsinfo.setResult = NULL;
-               rsinfo.setDesc = NULL;
-       }
-
        /*
         * Now call the function, passing the evaluated parameter values.
         */
@@ -1464,6 +1447,23 @@ restart:
                                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                         errmsg("set-valued function called in context that cannot accept a set")));
 
+               /*
+                * Prepare a resultinfo node for communication.  If the function
+                * doesn't itself return set, we don't pass the resultinfo to the
+                * function, but we need to fill it in anyway for internal use.
+                */
+               if (fcache->func.fn_retset)
+                       fcinfo->resultinfo = (Node *) &rsinfo;
+               rsinfo.type = T_ReturnSetInfo;
+               rsinfo.econtext = econtext;
+               rsinfo.expectedDesc = fcache->funcResultDesc;
+               rsinfo.allowedModes = (int) (SFRM_ValuePerCall | SFRM_Materialize);
+               /* note we do not set SFRM_Materialize_Random or _Preferred */
+               rsinfo.returnMode = SFRM_ValuePerCall;
+               /* isDone is filled below */
+               rsinfo.setResult = NULL;
+               rsinfo.setDesc = NULL;
+
                /*
                 * This loop handles the situation where we have both a set argument
                 * and a set-valued function.  Once we have exhausted the function's