PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/functions.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "parser/parse_coerce.h"
#include "parser/parse_collate.h"
#include "parser/parse_func.h"
#include "rewrite/rewriteHandler.h"
#include "storage/proc.h"
#include "tcop/utility.h"
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | DR_sqlfunction |
struct | execution_state |
struct | SQLFunctionCache |
Typedefs | |
typedef struct execution_state | execution_state |
typedef SQLFunctionCache * | SQLFunctionCachePtr |
Enumerations | |
enum | ExecStatus { F_EXEC_START , F_EXEC_RUN , F_EXEC_DONE } |
typedef struct execution_state execution_state |
typedef SQLFunctionCache* SQLFunctionCachePtr |
Definition at line 130 of file functions.c.
enum ExecStatus |
bool check_sql_fn_retval | ( | List * | queryTreeLists, |
Oid | rettype, | ||
TupleDesc | rettupdesc, | ||
char | prokind, | ||
bool | insertDroppedCols, | ||
List ** | resultTargetList | ||
) |
Definition at line 1609 of file functions.c.
References Assert, CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, coerce_fn_result_column(), Query::commandType, ereport, errcode(), errdetail(), errmsg(), ERROR, ExecCleanTargetListLength(), TargetEntry::expr, exprType(), format_type_be(), get_typtype(), RangeTblEntry::inh, InvalidOid, Query::jointree, lappend(), lfirst, lfirst_node, linitial, list_length(), list_make1, makeAlias(), makeConst(), makeFromExpr(), makeNode, makeString(), makeTargetEntry(), TupleDescData::natts, NIL, parse(), Query::rtable, RTE_SUBQUERY, RangeTblEntry::rtekind, RangeTblRef::rtindex, RangeTblEntry::subquery, Query::targetList, and TupleDescAttr.
Referenced by fmgr_sql_validator(), init_sql_fcache(), inline_function(), and inline_set_returning_function().
void check_sql_fn_statements | ( | List * | queryTreeLists | ) |
Definition at line 1534 of file functions.c.
References CMD_UTILITY, Query::commandType, ereport, errcode(), errmsg(), ERROR, if(), IsA, lfirst_node, NIL, stmt, and Query::utilityStmt.
Referenced by fmgr_sql_validator(), and init_sql_fcache().
|
static |
Definition at line 1997 of file functions.c.
References assign_expr_collations(), COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, TargetEntry::expr, exprType(), lappend(), list_length(), makeTargetEntry(), makeVarFromTargetEntry(), and TargetEntry::ressortgroupref.
Referenced by check_sql_fn_retval().
DestReceiver* CreateSQLFunctionDestReceiver | ( | void | ) |
Definition at line 2063 of file functions.c.
References DestSQLFunction, palloc0(), sqlfunction_destroy(), sqlfunction_receive(), sqlfunction_shutdown(), and sqlfunction_startup().
Referenced by CreateDestReceiver().
Datum fmgr_sql | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1029 of file functions.c.
References ReturnSetInfo::allowedModes, ErrorContextCallback::arg, Assert, ErrorContextCallback::callback, CommandCounterIncrement(), CreateTupleDescCopy(), ReturnSetInfo::econtext, elog, ereport, errcode(), errmsg(), ERROR, error_context_stack, ExprEndResult, ExprMultipleResult, F_EXEC_DONE, F_EXEC_START, SQLFunctionCache::fcontext, SQLFunctionCache::func_state, GetTransactionSnapshot(), if(), init_sql_fcache(), IsA, ReturnSetInfo::isDone, JunkFilter::jf_cleanTupType, JunkFilter::jf_resultSlot, SQLFunctionCache::junkFilter, execution_state::lazyEval, SQLFunctionCache::lazyEval, lfirst, lnext(), SQLFunctionCache::lxid, PGPROC::lxid, MemoryContextDelete(), MemoryContextSwitchTo(), MyProc, execution_state::next, PG_GET_COLLATION, PointerGetDatum(), PopActiveSnapshot(), postquel_end(), postquel_get_single_result(), postquel_getnext(), postquel_start(), postquel_sub_params(), ErrorContextCallback::previous, PushActiveSnapshot(), execution_state::qd, SQLFunctionCache::readonly_func, RegisterExprContextCallback(), SQLFunctionCache::rettype, ReturnSetInfo::returnMode, SQLFunctionCache::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, SubTransactionIsActive(), SQLFunctionCache::subxid, SQLFunctionCache::tstore, tuplestore_begin_heap(), tuplestore_clear(), tuplestore_gettupleslot(), UnregisterExprContextCallback(), UpdateActiveSnapshotCommandId(), PGPROC::vxid, and work_mem.
Referenced by fmgr_info_cxt_security().
|
static |
Definition at line 464 of file functions.c.
References CMD_SELECT, CMD_UTILITY, CommandIsReadOnly(), Query::commandType, PlannedStmt::commandType, CreateCommandName(), CURSOR_OPT_PARALLEL_OK, ereport, errcode(), errmsg(), ERROR, F_EXEC_START, PlannedStmt::hasModifyingCTE, IsA, SQLFunctionCache::junkFilter, lappend(), execution_state::lazyEval, SQLFunctionCache::lazyEval, lfirst_node, makeNode, execution_state::next, NIL, palloc(), pg_plan_query(), execution_state::qd, SQLFunctionCache::readonly_func, execution_state::setsResult, SQLFunctionCache::src, execution_state::status, execution_state::stmt, stmt, Query::stmt_location, and Query::utilityStmt.
Referenced by init_sql_fcache().
|
static |
Definition at line 583 of file functions.c.
References AcquireRewriteLocks(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, BlessTupleDesc(), castNode, check_sql_fn_retval(), check_sql_fn_statements(), elog, ERROR, ExecInitJunkFilter(), ExecInitJunkFilterConversion(), SQLFunctionCache::fcontext, FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FmgrInfo::fn_oid, SQLFunctionCache::fname, SQLFunctionCache::func_state, get_call_result_type(), get_typlenbyval(), GetCurrentSubTransactionId(), GETSTRUCT, HeapTupleIsValid, init_execution_state(), IsA, JunkFilter::jf_resultSlot, SQLFunctionCache::junkFilter, lappend(), lfirst_node, linitial_node, list_make1, SQLFunctionCache::lxid, PGPROC::lxid, MakeSingleTupleTableSlot(), MemoryContextSetIdentifier(), MemoryContextSwitchTo(), MyProc, NameStr, NIL, ObjectIdGetDatum(), palloc0(), pg_analyze_and_rewrite_withcb(), pg_parse_query(), pg_rewrite_query(), SQLFunctionCache::pinfo, prepare_sql_fn_parse_info(), pstrdup(), SQLFunctionCache::readonly_func, ReleaseSysCache(), SQLFunctionCache::rettype, SQLFunctionCache::returnsSet, SQLFunctionCache::returnsTuple, SearchSysCache1(), sql_fn_parser_setup(), SQLFunctionCache::src, stringToNode(), SQLFunctionCache::subxid, SysCacheGetAttr(), SysCacheGetAttrNotNull(), TextDatumGetCString, TupleTableSlot::tts_tupleDescriptor, TTSOpsMinimalTuple, SQLFunctionCache::typbyval, type_is_rowtype(), SQLFunctionCache::typlen, and PGPROC::vxid.
Referenced by fmgr_sql().
|
static |
Definition at line 911 of file functions.c.
References CMD_UTILITY, QueryDesc::dest, ExecutorEnd(), ExecutorFinish(), F_EXEC_DONE, FreeQueryDesc(), QueryDesc::operation, execution_state::qd, _DestReceiver::rDestroy, and execution_state::status.
Referenced by fmgr_sql(), and ShutdownSQLFunction().
|
static |
Definition at line 986 of file functions.c.
References datumCopy(), ExecFetchSlotHeapTupleDatum(), FunctionCallInfoBaseData::isnull, MemoryContextSwitchTo(), SQLFunctionCache::returnsTuple, slot_getattr(), SQLFunctionCache::typbyval, SQLFunctionCache::typlen, and value.
Referenced by fmgr_sql().
|
static |
Definition at line 876 of file functions.c.
References CMD_UTILITY, QueryDesc::dest, EState::es_processed, QueryDesc::estate, ExecutorRun(), ForwardScanDirection, execution_state::lazyEval, QueryDesc::operation, QueryDesc::params, QueryDesc::plannedstmt, PROCESS_UTILITY_QUERY, ProcessUtility(), execution_state::qd, QueryDesc::queryEnv, SQLFunctionCache::returnsSet, and SQLFunctionCache::src.
Referenced by fmgr_sql().
|
static |
Definition at line 814 of file functions.c.
References ActiveSnapshotSet(), Assert, CMD_UTILITY, CreateDestReceiver(), CreateQueryDesc(), CurrentMemoryContext, DR_sqlfunction::cxt, generate_unaccent_rules::dest, DestSQLFunction, EXEC_FLAG_SKIP_TRIGGERS, ExecutorStart(), F_EXEC_RUN, DR_sqlfunction::filter, GetActiveSnapshot(), InvalidSnapshot, SQLFunctionCache::junkFilter, execution_state::lazyEval, _DestReceiver::mydest, None_Receiver, QueryDesc::operation, SQLFunctionCache::paramLI, DR_sqlfunction::pub, execution_state::qd, QueryDesc::queryEnv, execution_state::setsResult, SQLFunctionCache::src, execution_state::status, execution_state::stmt, DR_sqlfunction::tstore, and SQLFunctionCache::tstore.
Referenced by fmgr_sql().
|
static |
Definition at line 931 of file functions.c.
References FunctionCallInfoBaseData::args, SQLFunctionParseInfo::argtypes, Assert, get_typlen(), i, ParamExternData::isnull, NullableDatum::isnull, MakeExpandedObjectReadOnly, makeParamList(), FunctionCallInfoBaseData::nargs, ParamListInfoData::numParams, SQLFunctionCache::paramLI, ParamListInfoData::params, ParamExternData::pflags, SQLFunctionCache::pinfo, ParamExternData::ptype, ParamExternData::value, and NullableDatum::value.
Referenced by fmgr_sql().
SQLFunctionParseInfoPtr prepare_sql_fn_parse_info | ( | HeapTuple | procedureTuple, |
Node * | call_expr, | ||
Oid | inputCollation | ||
) |
Definition at line 176 of file functions.c.
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(), init_sql_fcache(), inline_function(), and inline_set_returning_function().
|
static |
Definition at line 1488 of file functions.c.
References arg, DatumGetPointer(), F_EXEC_RUN, F_EXEC_START, SQLFunctionCache::func_state, lfirst, execution_state::next, PopActiveSnapshot(), postquel_end(), PushActiveSnapshot(), execution_state::qd, SQLFunctionCache::readonly_func, SQLFunctionCache::shutdown_reg, QueryDesc::snapshot, execution_state::status, SQLFunctionCache::tstore, and tuplestore_end().
Referenced by fmgr_sql().
|
static |
Definition at line 1406 of file functions.c.
References arg, errcontext, errposition(), FmgrInfo::fn_extra, SQLFunctionCache::fname, SQLFunctionCache::func_state, geterrposition(), if(), internalerrposition(), internalerrquery(), lfirst, execution_state::next, execution_state::qd, and SQLFunctionCache::src.
Referenced by fmgr_sql().
|
static |
Definition at line 410 of file functions.c.
References SQLFunctionParseInfo::argtypes, SQLFunctionParseInfo::collation, get_typcollation(), Param::location, makeNode, OidIsValid, PARAM_EXTERN, Param::paramid, Param::paramkind, and Param::paramtype.
Referenced by sql_fn_param_ref(), and sql_fn_resolve_param_name().
|
static |
Definition at line 394 of file functions.c.
References if(), ParamRef::location, SQLFunctionParseInfo::nargs, ParamRef::number, ParseState::p_ref_hook_state, and sql_fn_make_param().
Referenced by sql_fn_parser_setup().
void sql_fn_parser_setup | ( | struct ParseState * | pstate, |
SQLFunctionParseInfoPtr | pinfo | ||
) |
Definition at line 265 of file functions.c.
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(), init_sql_fcache(), inline_function(), inline_set_returning_function(), and interpret_AS_clause().
|
static |
Definition at line 278 of file functions.c.
References Assert, ColumnRef::fields, SQLFunctionParseInfo::fname, if(), IsA, linitial, list_length(), list_make1, llast, ColumnRef::location, lsecond, lthird, ParseState::p_last_srf, ParseState::p_ref_hook_state, ParseFuncOrColumn(), sql_fn_resolve_param_name(), and strVal.
Referenced by sql_fn_parser_setup().
|
static |
Definition at line 440 of file functions.c.
References SQLFunctionParseInfo::argnames, i, SQLFunctionParseInfo::nargs, and sql_fn_make_param().
Referenced by sql_fn_post_column_ref().
|
static |
Definition at line 2117 of file functions.c.
References pfree().
Referenced by CreateSQLFunctionDestReceiver().
|
static |
Definition at line 2091 of file functions.c.
References ExecFilterJunk(), DR_sqlfunction::filter, DR_sqlfunction::tstore, and tuplestore_puttupleslot().
Referenced by CreateSQLFunctionDestReceiver().
|
static |
Definition at line 2108 of file functions.c.
Referenced by CreateSQLFunctionDestReceiver().
|
static |
Definition at line 2082 of file functions.c.
Referenced by CreateSQLFunctionDestReceiver().