]> granicus.if.org Git - postgresql/blobdiff - src/backend/executor/nodeFunctionscan.c
Support domains over composite types.
[postgresql] / src / backend / executor / nodeFunctionscan.c
index 464170810862ab8074f16f51240f64a07b2898e4..de476ac75c4695253ff56b7f0fb762496887aadb 100644 (file)
@@ -3,7 +3,7 @@
  * nodeFunctionscan.c
  *       Support routines for scanning RangeFunctions (functions in rangetable).
  *
- * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -35,7 +35,7 @@
  */
 typedef struct FunctionScanPerFuncState
 {
-       ExprState  *funcexpr;           /* state of the expression being evaluated */
+       SetExprState *setexpr;          /* state of the expression being evaluated */
        TupleDesc       tupdesc;                /* desc of the function result type */
        int                     colcount;               /* expected number of result columns */
        Tuplestorestate *tstore;        /* holds the function result set */
@@ -92,11 +92,11 @@ FunctionNext(FunctionScanState *node)
                if (tstore == NULL)
                {
                        node->funcstates[0].tstore = tstore =
-                               ExecMakeTableFunctionResult(node->funcstates[0].funcexpr,
+                               ExecMakeTableFunctionResult(node->funcstates[0].setexpr,
                                                                                        node->ss.ps.ps_ExprContext,
                                                                                        node->argcontext,
                                                                                        node->funcstates[0].tupdesc,
-                                                                                 node->eflags & EXEC_FLAG_BACKWARD);
+                                                                                       node->eflags & EXEC_FLAG_BACKWARD);
 
                        /*
                         * paranoia - cope if the function, which may have constructed the
@@ -151,11 +151,11 @@ FunctionNext(FunctionScanState *node)
                if (fs->tstore == NULL)
                {
                        fs->tstore =
-                               ExecMakeTableFunctionResult(fs->funcexpr,
+                               ExecMakeTableFunctionResult(fs->setexpr,
                                                                                        node->ss.ps.ps_ExprContext,
                                                                                        node->argcontext,
                                                                                        fs->tupdesc,
-                                                                                 node->eflags & EXEC_FLAG_BACKWARD);
+                                                                                       node->eflags & EXEC_FLAG_BACKWARD);
 
                        /*
                         * paranoia - cope if the function, which may have constructed the
@@ -262,9 +262,11 @@ FunctionRecheck(FunctionScanState *node, TupleTableSlot *slot)
  *             access method functions.
  * ----------------------------------------------------------------
  */
-TupleTableSlot *
-ExecFunctionScan(FunctionScanState *node)
+static TupleTableSlot *
+ExecFunctionScan(PlanState *pstate)
 {
+       FunctionScanState *node = castNode(FunctionScanState, pstate);
+
        return ExecScan(&node->ss,
                                        (ExecScanAccessMtd) FunctionNext,
                                        (ExecScanRecheckMtd) FunctionRecheck);
@@ -299,6 +301,7 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
        scanstate = makeNode(FunctionScanState);
        scanstate->ss.ps.plan = (Plan *) node;
        scanstate->ss.ps.state = estate;
+       scanstate->ss.ps.ExecProcNode = ExecFunctionScan;
        scanstate->eflags = eflags;
 
        /*
@@ -331,8 +334,6 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
         */
        ExecAssignExprContext(estate, &scanstate->ss.ps);
 
-       scanstate->ss.ps.ps_TupFromTlist = false;
-
        /*
         * tuple table initialization
         */
@@ -342,12 +343,8 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
        /*
         * initialize child expressions
         */
-       scanstate->ss.ps.targetlist = (List *)
-               ExecInitExpr((Expr *) node->scan.plan.targetlist,
-                                        (PlanState *) scanstate);
-       scanstate->ss.ps.qual = (List *)
-               ExecInitExpr((Expr *) node->scan.plan.qual,
-                                        (PlanState *) scanstate);
+       scanstate->ss.ps.qual =
+               ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
 
        scanstate->funcstates = palloc(nfuncs * sizeof(FunctionScanPerFuncState));
 
@@ -363,7 +360,10 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
                Oid                     funcrettype;
                TupleDesc       tupdesc;
 
-               fs->funcexpr = ExecInitExpr((Expr *) funcexpr, (PlanState *) scanstate);
+               fs->setexpr =
+                       ExecInitTableFunctionResult((Expr *) funcexpr,
+                                                                               scanstate->ss.ps.ps_ExprContext,
+                                                                               &scanstate->ss.ps);
 
                /*
                 * Don't allocate the tuplestores; the actual calls to the functions
@@ -383,7 +383,8 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
                                                                                        &funcrettype,
                                                                                        &tupdesc);
 
-               if (functypclass == TYPEFUNC_COMPOSITE)
+               if (functypclass == TYPEFUNC_COMPOSITE ||
+                       functypclass == TYPEFUNC_COMPOSITE_DOMAIN)
                {
                        /* Composite data type, e.g. a table's row type */
                        Assert(tupdesc);
@@ -508,9 +509,7 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
         */
        scanstate->argcontext = AllocSetContextCreate(CurrentMemoryContext,
                                                                                                  "Table function arguments",
-                                                                                                 ALLOCSET_DEFAULT_MINSIZE,
-                                                                                                 ALLOCSET_DEFAULT_INITSIZE,
-                                                                                                 ALLOCSET_DEFAULT_MAXSIZE);
+                                                                                                 ALLOCSET_DEFAULT_SIZES);
 
        return scanstate;
 }