PostgreSQL Source Code: src/include/executor/functions.h File Reference (original) (raw)
Go to the source code of this file.
Datum | fmgr_sql (PG_FUNCTION_ARGS) |
---|---|
SQLFunctionParseInfoPtr | prepare_sql_fn_parse_info (HeapTuple procedureTuple, Node *call_expr, Oid inputCollation) |
void | sql_fn_parser_setup (struct ParseState *pstate, SQLFunctionParseInfoPtr pinfo) |
void | check_sql_fn_statements (List *queryTreeLists) |
bool | check_sql_fn_retval (List *queryTreeLists, Oid rettype, TupleDesc rettupdesc, char prokind, bool insertDroppedCols) |
DestReceiver * | CreateSQLFunctionDestReceiver (void) |
◆ SQLFunctionParseInfo
◆ SQLFunctionParseInfoPtr
◆ check_sql_fn_retval()
bool check_sql_fn_retval | ( | List * | queryTreeLists, |
---|---|---|---|
Oid | rettype, | ||
TupleDesc | rettupdesc, | ||
char | prokind, | ||
bool | insertDroppedCols | ||
) |
Definition at line 2087 of file functions.c.
2091{
2092 List *queryTreeList;
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106 if (queryTreeLists != NIL)
2108 else
2109 queryTreeList = NIL;
2110
2112 rettype, rettupdesc,
2113 prokind, insertDroppedCols);
2114}
static bool check_sql_stmt_retval(List *queryTreeList, Oid rettype, TupleDesc rettupdesc, char prokind, bool insertDroppedCols)
#define llast_node(type, l)
References check_sql_stmt_retval(), llast_node, and NIL.
Referenced by fmgr_sql_validator(), inline_function(), and inline_set_returning_function().
◆ check_sql_fn_statements()
void check_sql_fn_statements | ( | List * | queryTreeLists | ) |
---|
◆ CreateSQLFunctionDestReceiver()
Definition at line 2588 of file functions.c.
2589{
2591
2597
2598
2599
2601}
static void sqlfunction_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
static bool sqlfunction_receive(TupleTableSlot *slot, DestReceiver *self)
static void sqlfunction_destroy(DestReceiver *self)
static void sqlfunction_shutdown(DestReceiver *self)
void * palloc0(Size size)
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
void(* rShutdown)(DestReceiver *self)
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
void(* rDestroy)(DestReceiver *self)
References DestSQLFunction, _DestReceiver::mydest, palloc0(), DR_sqlfunction::pub, _DestReceiver::rDestroy, _DestReceiver::receiveSlot, _DestReceiver::rShutdown, _DestReceiver::rStartup, sqlfunction_destroy(), sqlfunction_receive(), sqlfunction_shutdown(), and sqlfunction_startup().
Referenced by CreateDestReceiver().
◆ fmgr_sql()
Definition at line 1553 of file functions.c.
1554{
1558 bool randomAccess;
1559 bool lazyEvalOK;
1560 bool pushed_snapshot;
1564
1565
1566 if (fcinfo->flinfo->fn_retset)
1567 {
1569
1570
1571
1572
1573
1574
1575
1580 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1581 errmsg("set-valued function called in context that cannot accept a set")));
1584
1586 }
1587 else
1588 {
1589 randomAccess = false;
1590 lazyEvalOK = true;
1591
1592 tscontext = NULL;
1593 }
1594
1595
1596
1597
1599
1600
1603
1604
1605
1606
1608 sqlerrcontext.arg = fcache;
1611
1612
1613
1614
1615
1616 do
1617 {
1618 es = fcache->eslist;
1620 es = es->next;
1621 if (es)
1622 break;
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643 pushed_snapshot = false;
1644 while (es)
1645 {
1646 bool completed;
1647
1649 {
1650
1651
1652
1653
1654
1655
1657 {
1659 if (!pushed_snapshot)
1660 {
1662 pushed_snapshot = true;
1663 }
1664 else
1666 }
1667
1669 }
1671 {
1672
1674 pushed_snapshot = true;
1675 }
1676
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1701 break;
1702
1703
1704
1705
1706 es = es->next;
1707 while (!es)
1708 {
1709
1710
1711
1712
1713
1714
1715 if (pushed_snapshot)
1716 {
1718 pushed_snapshot = false;
1719 }
1720
1722 break;
1723
1724 es = fcache->eslist;
1725 }
1726 }
1727
1728
1729
1730
1731
1733 {
1735
1736 if (es)
1737 {
1738
1739
1740
1741
1743
1747
1749
1750
1751
1752
1754
1755
1756
1757
1758
1760 {
1765 }
1766 }
1768 {
1769
1770
1771
1772
1774
1775 fcinfo->isnull = true;
1776 result = (Datum) 0;
1777
1778
1780 {
1785 }
1786 }
1787 else
1788 {
1789
1790
1791
1792
1793
1794
1795
1796
1797
1801 fcache->tstore = NULL;
1802
1805
1806 fcinfo->isnull = true;
1807 result = (Datum) 0;
1808
1809
1811 {
1816 }
1817 }
1818 }
1819 else
1820 {
1821
1822
1823
1825 {
1826
1830 else
1831 {
1832 fcinfo->isnull = true;
1833 result = (Datum) 0;
1834 }
1835 }
1836 else
1837 {
1838
1840 fcinfo->isnull = true;
1841 result = (Datum) 0;
1842 }
1843 }
1844
1845
1846 if (pushed_snapshot)
1848
1849
1850
1851
1852
1853 if (es == NULL)
1854 fcache->eslist = NULL;
1855
1857
1858 return result;
1859}
ErrorContextCallback * error_context_stack
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void UnregisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
@ SFRM_Materialize_Preferred
@ SFRM_Materialize_Random
static Datum postquel_get_single_result(TupleTableSlot *slot, FunctionCallInfo fcinfo, SQLFunctionCachePtr fcache)
static bool postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache)
static void postquel_start(execution_state *es, SQLFunctionCachePtr fcache)
static bool init_execution_state(SQLFunctionCachePtr fcache)
static void postquel_end(execution_state *es, SQLFunctionCachePtr fcache)
static void sql_exec_error_callback(void *arg)
static void ShutdownSQLFunction(Datum arg)
static SQLFunctionCache * init_sql_fcache(FunctionCallInfo fcinfo, bool lazyEvalOK)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
#define IsA(nodeptr, _type_)
static Datum PointerGetDatum(const void *X)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void UpdateActiveSnapshotCommandId(void)
void PopActiveSnapshot(void)
struct ErrorContextCallback * previous
void(* callback)(void *arg)
MemoryContext ecxt_per_query_memory
TupleDesc jf_cleanTupType
TupleTableSlot * jf_resultSlot
SetFunctionReturnMode returnMode
Tuplestorestate * setResult
SQLFunctionHashEntry * func
struct execution_state * next
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
void CommandCounterIncrement(void)
References ReturnSetInfo::allowedModes, ErrorContextCallback::arg, Assert(), ErrorContextCallback::callback, CommandCounterIncrement(), CreateTupleDescCopy(), ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, ereport, errcode(), errmsg(), ERROR, error_context_stack, SQLFunctionCache::eslist, ExprEndResult, ExprMultipleResult, F_EXEC_DONE, F_EXEC_START, SQLFunctionCache::func, GetTransactionSnapshot(), if(), init_execution_state(), init_sql_fcache(), IsA, ReturnSetInfo::isDone, JunkFilter::jf_cleanTupType, JunkFilter::jf_resultSlot, SQLFunctionCache::junkFilter, execution_state::lazyEval, SQLFunctionCache::lazyEval, execution_state::next, PointerGetDatum(), PopActiveSnapshot(), postquel_end(), postquel_get_single_result(), postquel_getnext(), postquel_start(), ErrorContextCallback::previous, PushActiveSnapshot(), execution_state::qd, SQLFunctionCache::randomAccess, SQLFunctionHashEntry::readonly_func, RegisterExprContextCallback(), SQLFunctionHashEntry::rettype, ReturnSetInfo::returnMode, SQLFunctionHashEntry::returnsSet, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, SFRM_Materialize_Preferred, SFRM_Materialize_Random, SFRM_ValuePerCall, SQLFunctionCache::shutdown_reg, ShutdownSQLFunction(), QueryDesc::snapshot, sql_exec_error_callback(), execution_state::status, SQLFunctionCache::tscontext, SQLFunctionCache::tstore, TTS_EMPTY, UnregisterExprContextCallback(), and UpdateActiveSnapshotCommandId().
Referenced by fmgr_info_cxt_security().
◆ prepare_sql_fn_parse_info()
Definition at line 250 of file functions.c.
253{
256 int nargs;
257
259
260
262
263
264 pinfo->collation = inputCollation;
265
266
267
268
269
270 pinfo->nargs = nargs = procedureStruct->pronargs;
271 if (nargs > 0)
272 {
273 Oid *argOidVect;
274 int argnum;
275
276 argOidVect = (Oid *) palloc(nargs * sizeof(Oid));
277 memcpy(argOidVect,
278 procedureStruct->proargtypes.values,
279 nargs * sizeof(Oid));
280
281 for (argnum = 0; argnum < nargs; argnum++)
282 {
283 Oid argtype = argOidVect[argnum];
284
285 if (IsPolymorphicType(argtype))
286 {
290 (errcode(ERRCODE_DATATYPE_MISMATCH),
291 errmsg("could not determine actual type of argument declared %s",
293 argOidVect[argnum] = argtype;
294 }
295 }
296
297 pinfo->argtypes = argOidVect;
298 }
299
300
301
302
303 if (nargs > 0)
304 {
305 Datum proargnames;
306 Datum proargmodes;
307 int n_arg_names;
308 bool isNull;
309
310 proargnames = SysCacheGetAttr(PROCNAMEARGSNSP, procedureTuple,
311 Anum_pg_proc_proargnames,
312 &isNull);
313 if (isNull)
314 proargnames = PointerGetDatum(NULL);
315
316 proargmodes = SysCacheGetAttr(PROCNAMEARGSNSP, procedureTuple,
317 Anum_pg_proc_proargmodes,
318 &isNull);
319 if (isNull)
320 proargmodes = PointerGetDatum(NULL);
321
324
325
326 if (n_arg_names < nargs)
328 }
329 else
331
332 return pinfo;
333}
Oid get_call_expr_argtype(Node *expr, int argnum)
char * format_type_be(Oid type_oid)
int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char ***arg_names)
SQLFunctionParseInfo * SQLFunctionParseInfoPtr
static void * GETSTRUCT(const HeapTupleData *tuple)
char * pstrdup(const char *in)
FormData_pg_proc * Form_pg_proc
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
References SQLFunctionParseInfo::argnames, SQLFunctionParseInfo::argtypes, SQLFunctionParseInfo::collation, ereport, errcode(), errmsg(), ERROR, SQLFunctionParseInfo::fname, format_type_be(), get_call_expr_argtype(), get_func_input_arg_names(), GETSTRUCT(), InvalidOid, NameStr, SQLFunctionParseInfo::nargs, palloc(), palloc0(), PointerGetDatum(), pstrdup(), and SysCacheGetAttr().
Referenced by fmgr_sql_validator(), inline_function(), inline_set_returning_function(), and sql_compile_callback().
◆ sql_fn_parser_setup()
Definition at line 339 of file functions.c.
340{
344
346}
static Node * sql_fn_param_ref(ParseState *pstate, ParamRef *pref)
static Node * sql_fn_post_column_ref(ParseState *pstate, ColumnRef *cref, Node *var)
ParseParamRefHook p_paramref_hook
PreParseColumnRefHook p_pre_columnref_hook
PostParseColumnRefHook p_post_columnref_hook
References ParseState::p_paramref_hook, ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseState::p_ref_hook_state, sql_fn_param_ref(), and sql_fn_post_column_ref().
Referenced by fmgr_sql_validator(), inline_function(), inline_set_returning_function(), interpret_AS_clause(), and prepare_next_query().