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 2088 of file functions.c.

2092{

2093 List *queryTreeList;

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107 if (queryTreeLists != NIL)

2109 else

2110 queryTreeList = NIL;

2111

2113 rettype, rettupdesc,

2114 prokind, insertDroppedCols);

2115}

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 2589 of file functions.c.

2590{

2592

2598

2599

2600

2602}

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 1554 of file functions.c.

1555{

1559 bool randomAccess;

1560 bool lazyEvalOK;

1561 bool pushed_snapshot;

1565

1566

1567 if (fcinfo->flinfo->fn_retset)

1568 {

1570

1571

1572

1573

1574

1575

1576

1581 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

1582 errmsg("set-valued function called in context that cannot accept a set")));

1585

1587 }

1588 else

1589 {

1590 randomAccess = false;

1591 lazyEvalOK = true;

1592

1593 tscontext = NULL;

1594 }

1595

1596

1597

1598

1600

1601

1604

1605

1606

1607

1609 sqlerrcontext.arg = fcache;

1612

1613

1614

1615

1616

1617 do

1618 {

1619 es = fcache->eslist;

1621 es = es->next;

1622 if (es)

1623 break;

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644 pushed_snapshot = false;

1645 while (es)

1646 {

1647 bool completed;

1648

1650 {

1651

1652

1653

1654

1655

1656

1658 {

1660 if (!pushed_snapshot)

1661 {

1663 pushed_snapshot = true;

1664 }

1665 else

1667 }

1668

1670 }

1672 {

1673

1675 pushed_snapshot = true;

1676 }

1677

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1702 break;

1703

1704

1705

1706

1707 es = es->next;

1708 while (!es)

1709 {

1710

1711

1712

1713

1714

1715

1716 if (pushed_snapshot)

1717 {

1719 pushed_snapshot = false;

1720 }

1721

1723 break;

1724

1725 es = fcache->eslist;

1726 }

1727 }

1728

1729

1730

1731

1732

1734 {

1736

1737 if (es)

1738 {

1739

1740

1741

1742

1744

1748

1750

1751

1752

1753

1755

1756

1757

1758

1759

1761 {

1766 }

1767 }

1769 {

1770

1771

1772

1773

1775

1776 fcinfo->isnull = true;

1777 result = (Datum) 0;

1778

1779

1781 {

1786 }

1787 }

1788 else

1789 {

1790

1791

1792

1793

1794

1795

1796

1797

1798

1802 fcache->tstore = NULL;

1803

1806

1807 fcinfo->isnull = true;

1808 result = (Datum) 0;

1809

1810

1812 {

1817 }

1818 }

1819 }

1820 else

1821 {

1822

1823

1824

1826 {

1827

1831 else

1832 {

1833 fcinfo->isnull = true;

1834 result = (Datum) 0;

1835 }

1836 }

1837 else

1838 {

1839

1841 fcinfo->isnull = true;

1842 result = (Datum) 0;

1843 }

1844 }

1845

1846

1847 if (pushed_snapshot)

1849

1850

1851

1852

1853

1854 if (es == NULL)

1855 fcache->eslist = NULL;

1856

1858

1859 return result;

1860}

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 249 of file functions.c.

252{

255 int nargs;

256

258

259

261

262

263 pinfo->collation = inputCollation;

264

265

266

267

268

269 pinfo->nargs = nargs = procedureStruct->pronargs;

270 if (nargs > 0)

271 {

272 Oid *argOidVect;

273 int argnum;

274

275 argOidVect = (Oid *) palloc(nargs * sizeof(Oid));

276 memcpy(argOidVect,

277 procedureStruct->proargtypes.values,

278 nargs * sizeof(Oid));

279

280 for (argnum = 0; argnum < nargs; argnum++)

281 {

282 Oid argtype = argOidVect[argnum];

283

284 if (IsPolymorphicType(argtype))

285 {

289 (errcode(ERRCODE_DATATYPE_MISMATCH),

290 errmsg("could not determine actual type of argument declared %s",

292 argOidVect[argnum] = argtype;

293 }

294 }

295

296 pinfo->argtypes = argOidVect;

297 }

298

299

300

301

302 if (nargs > 0)

303 {

304 Datum proargnames;

305 Datum proargmodes;

306 int n_arg_names;

307 bool isNull;

308

309 proargnames = SysCacheGetAttr(PROCNAMEARGSNSP, procedureTuple,

310 Anum_pg_proc_proargnames,

311 &isNull);

312 if (isNull)

313 proargnames = PointerGetDatum(NULL);

314

315 proargmodes = SysCacheGetAttr(PROCNAMEARGSNSP, procedureTuple,

316 Anum_pg_proc_proargmodes,

317 &isNull);

318 if (isNull)

319 proargmodes = PointerGetDatum(NULL);

320

323

324

325 if (n_arg_names < nargs)

327 }

328 else

330

331 return pinfo;

332}

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 338 of file functions.c.

339{

343

345}

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().