PostgreSQL Source Code  git master
fmgr.c File Reference
#include "postgres.h"
#include "access/detoast.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "executor/functions.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "pgstat.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgrtab.h"
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Include dependency graph for fmgr.c:

Go to the source code of this file.

Data Structures

struct  CFuncHashTabEntry
 
struct  fmgr_security_definer_cache
 

Functions

static void fmgr_info_cxt_security (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
 
static void fmgr_info_C_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static void fmgr_info_other_lang (Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
 
static CFuncHashTabEntrylookup_C_func (HeapTuple procedureTuple)
 
static void record_C_func (HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
 
Datum fmgr_security_definer (PG_FUNCTION_ARGS)
 
static const FmgrBuiltinfmgr_isbuiltin (Oid id)
 
static const FmgrBuiltinfmgr_lookupByName (const char *name)
 
void fmgr_info (Oid functionId, FmgrInfo *finfo)
 
void fmgr_info_cxt (Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
 
void fmgr_symbol (Oid functionId, char **mod, char **fn)
 
const Pg_finfo_recordfetch_finfo_record (void *filehandle, const char *funcname)
 
void clear_external_function_hash (void *filehandle)
 
void fmgr_info_copy (FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
 
Oid fmgr_internal_function (const char *proname)
 
Datum DirectFunctionCall1Coll (PGFunction func, Oid collation, Datum arg1)
 
Datum DirectFunctionCall2Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2)
 
Datum DirectFunctionCall3Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum DirectFunctionCall4Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum DirectFunctionCall5Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum DirectFunctionCall6Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum DirectFunctionCall7Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum DirectFunctionCall8Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum DirectFunctionCall9Coll (PGFunction func, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum CallerFInfoFunctionCall1 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum CallerFInfoFunctionCall2 (PGFunction func, FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall0Coll (FmgrInfo *flinfo, Oid collation)
 
Datum FunctionCall1Coll (FmgrInfo *flinfo, Oid collation, Datum arg1)
 
Datum FunctionCall2Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
 
Datum FunctionCall3Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum FunctionCall4Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum FunctionCall5Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum FunctionCall6Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum FunctionCall7Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum FunctionCall8Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum FunctionCall9Coll (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum OidFunctionCall0Coll (Oid functionId, Oid collation)
 
Datum OidFunctionCall1Coll (Oid functionId, Oid collation, Datum arg1)
 
Datum OidFunctionCall2Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2)
 
Datum OidFunctionCall3Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3)
 
Datum OidFunctionCall4Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
 
Datum OidFunctionCall5Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
 
Datum OidFunctionCall6Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
 
Datum OidFunctionCall7Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
 
Datum OidFunctionCall8Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
 
Datum OidFunctionCall9Coll (Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
 
Datum InputFunctionCall (FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
 
char * OutputFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum ReceiveFunctionCall (FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaSendFunctionCall (FmgrInfo *flinfo, Datum val)
 
Datum OidInputFunctionCall (Oid functionId, char *str, Oid typioparam, int32 typmod)
 
char * OidOutputFunctionCall (Oid functionId, Datum val)
 
Datum OidReceiveFunctionCall (Oid functionId, StringInfo buf, Oid typioparam, int32 typmod)
 
byteaOidSendFunctionCall (Oid functionId, Datum val)
 
Datum Int64GetDatum (int64 X)
 
Datum Float8GetDatum (float8 X)
 
struct varlenapg_detoast_datum (struct varlena *datum)
 
struct varlenapg_detoast_datum_copy (struct varlena *datum)
 
struct varlenapg_detoast_datum_slice (struct varlena *datum, int32 first, int32 count)
 
struct varlenapg_detoast_datum_packed (struct varlena *datum)
 
Oid get_fn_expr_rettype (FmgrInfo *flinfo)
 
Oid get_fn_expr_argtype (FmgrInfo *flinfo, int argnum)
 
Oid get_call_expr_argtype (Node *expr, int argnum)
 
bool get_fn_expr_arg_stable (FmgrInfo *flinfo, int argnum)
 
bool get_call_expr_arg_stable (Node *expr, int argnum)
 
bool get_fn_expr_variadic (FmgrInfo *flinfo)
 
void set_fn_opclass_options (FmgrInfo *flinfo, bytea *options)
 
bool has_fn_opclass_options (FmgrInfo *flinfo)
 
byteaget_fn_opclass_options (FmgrInfo *flinfo)
 
bool CheckFunctionValidatorAccess (Oid validatorOid, Oid functionOid)
 

Variables

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL
 
PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL
 
static HTABCFuncHash = NULL
 

Function Documentation

◆ CallerFInfoFunctionCall1()

Datum CallerFInfoFunctionCall1 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1068 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

1069 {
1070  LOCAL_FCINFO(fcinfo, 1);
1071  Datum result;
1072 
1073  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1074 
1075  fcinfo->args[0].value = arg1;
1076  fcinfo->args[0].isnull = false;
1077 
1078  result = (*func) (fcinfo);
1079 
1080  /* Check for null result, since caller is clearly not expecting one */
1081  if (fcinfo->isnull)
1082  elog(ERROR, "function %p returned NULL", (void *) func);
1083 
1084  return result;
1085 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ CallerFInfoFunctionCall2()

Datum CallerFInfoFunctionCall2 ( PGFunction  func,
FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1088 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_enumge(), gbt_enumgt(), gbt_enumkey_cmp(), gbt_enumle(), gbt_enumlt(), gin_btree_compare_prefix(), and gin_enum_cmp().

1089 {
1090  LOCAL_FCINFO(fcinfo, 2);
1091  Datum result;
1092 
1093  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1094 
1095  fcinfo->args[0].value = arg1;
1096  fcinfo->args[0].isnull = false;
1097  fcinfo->args[1].value = arg2;
1098  fcinfo->args[1].isnull = false;
1099 
1100  result = (*func) (fcinfo);
1101 
1102  /* Check for null result, since caller is clearly not expecting one */
1103  if (fcinfo->isnull)
1104  elog(ERROR, "function %p returned NULL", (void *) func);
1105 
1106  return result;
1107 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ CheckFunctionValidatorAccess()

bool CheckFunctionValidatorAccess ( Oid  validatorOid,
Oid  functionOid 
)

Definition at line 2039 of file fmgr.c.

References ACL_EXECUTE, ACL_USAGE, aclcheck_error(), ACLCHECK_OK, elog, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, GetUserId(), HeapTupleIsValid, LANGOID, NameStr, OBJECT_FUNCTION, OBJECT_LANGUAGE, ObjectIdGetDatum, pg_language_aclcheck(), pg_proc_aclcheck(), PROCOID, ReleaseSysCache(), and SearchSysCache1().

Referenced by fmgr_c_validator(), fmgr_internal_validator(), fmgr_sql_validator(), plperl_validator(), plpgsql_validator(), and plpython_validator().

2040 {
2041  HeapTuple procTup;
2042  HeapTuple langTup;
2043  Form_pg_proc procStruct;
2044  Form_pg_language langStruct;
2045  AclResult aclresult;
2046 
2047  /*
2048  * Get the function's pg_proc entry. Throw a user-facing error for bad
2049  * OID, because validators can be called with user-specified OIDs.
2050  */
2051  procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid));
2052  if (!HeapTupleIsValid(procTup))
2053  ereport(ERROR,
2054  (errcode(ERRCODE_UNDEFINED_FUNCTION),
2055  errmsg("function with OID %u does not exist", functionOid)));
2056  procStruct = (Form_pg_proc) GETSTRUCT(procTup);
2057 
2058  /*
2059  * Fetch pg_language entry to know if this is the correct validation
2060  * function for that pg_proc entry.
2061  */
2062  langTup = SearchSysCache1(LANGOID, ObjectIdGetDatum(procStruct->prolang));
2063  if (!HeapTupleIsValid(langTup))
2064  elog(ERROR, "cache lookup failed for language %u", procStruct->prolang);
2065  langStruct = (Form_pg_language) GETSTRUCT(langTup);
2066 
2067  if (langStruct->lanvalidator != validatorOid)
2068  ereport(ERROR,
2069  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2070  errmsg("language validation function %u called for language %u instead of %u",
2071  validatorOid, procStruct->prolang,
2072  langStruct->lanvalidator)));
2073 
2074  /* first validate that we have permissions to use the language */
2075  aclresult = pg_language_aclcheck(procStruct->prolang, GetUserId(),
2076  ACL_USAGE);
2077  if (aclresult != ACLCHECK_OK)
2078  aclcheck_error(aclresult, OBJECT_LANGUAGE,
2079  NameStr(langStruct->lanname));
2080 
2081  /*
2082  * Check whether we are allowed to execute the function itself. If we can
2083  * execute it, there should be no possible side-effect of
2084  * compiling/validation that execution can't have.
2085  */
2086  aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
2087  if (aclresult != ACLCHECK_OK)
2088  aclcheck_error(aclresult, OBJECT_FUNCTION, NameStr(procStruct->proname));
2089 
2090  ReleaseSysCache(procTup);
2091  ReleaseSysCache(langTup);
2092 
2093  return true;
2094 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Oid GetUserId(void)
Definition: miscinit.c:450
int errcode(int sqlerrcode)
Definition: elog.c:610
AclResult pg_language_aclcheck(Oid lang_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4599
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define ACL_USAGE
Definition: parsenodes.h:82
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
AclResult
Definition: acl.h:177
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define ACL_EXECUTE
Definition: parsenodes.h:81
#define elog(elevel,...)
Definition: elog.h:214
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4587
#define NameStr(name)
Definition: c.h:622

◆ clear_external_function_hash()

void clear_external_function_hash ( void *  filehandle)

Definition at line 596 of file fmgr.c.

References hash_destroy().

Referenced by internal_unload_library().

597 {
598  if (CFuncHash)
600  CFuncHash = NULL;
601 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:835
static HTAB * CFuncHash
Definition: fmgr.c:54

◆ DirectFunctionCall1Coll()

Datum DirectFunctionCall1Coll ( PGFunction  func,
Oid  collation,
Datum  arg1 
)

Definition at line 795 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by Generic_Text_IC_like(), libpqrcv_create_slot(), and texthashfast().

796 {
797  LOCAL_FCINFO(fcinfo, 1);
798  Datum result;
799 
800  InitFunctionCallInfoData(*fcinfo, NULL, 1, collation, NULL, NULL);
801 
802  fcinfo->args[0].value = arg1;
803  fcinfo->args[0].isnull = false;
804 
805  result = (*func) (fcinfo);
806 
807  /* Check for null result, since caller is clearly not expecting one */
808  if (fcinfo->isnull)
809  elog(ERROR, "function %p returned NULL", (void *) func);
810 
811  return result;
812 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall2Coll()

Datum DirectFunctionCall2Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 815 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gbt_textcmp(), gbt_texteq(), gbt_textge(), gbt_textgt(), gbt_textle(), gbt_textlt(), spg_text_leaf_consistent(), text_isequal(), and texteqfast().

816 {
817  LOCAL_FCINFO(fcinfo, 2);
818  Datum result;
819 
820  InitFunctionCallInfoData(*fcinfo, NULL, 2, collation, NULL, NULL);
821 
822  fcinfo->args[0].value = arg1;
823  fcinfo->args[0].isnull = false;
824  fcinfo->args[1].value = arg2;
825  fcinfo->args[1].isnull = false;
826 
827  result = (*func) (fcinfo);
828 
829  /* Check for null result, since caller is clearly not expecting one */
830  if (fcinfo->isnull)
831  elog(ERROR, "function %p returned NULL", (void *) func);
832 
833  return result;
834 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall3Coll()

Datum DirectFunctionCall3Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 837 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

839 {
840  LOCAL_FCINFO(fcinfo, 3);
841  Datum result;
842 
843  InitFunctionCallInfoData(*fcinfo, NULL, 3, collation, NULL, NULL);
844 
845  fcinfo->args[0].value = arg1;
846  fcinfo->args[0].isnull = false;
847  fcinfo->args[1].value = arg2;
848  fcinfo->args[1].isnull = false;
849  fcinfo->args[2].value = arg3;
850  fcinfo->args[2].isnull = false;
851 
852  result = (*func) (fcinfo);
853 
854  /* Check for null result, since caller is clearly not expecting one */
855  if (fcinfo->isnull)
856  elog(ERROR, "function %p returned NULL", (void *) func);
857 
858  return result;
859 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall4Coll()

Datum DirectFunctionCall4Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 862 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by execute_extension_script().

864 {
865  LOCAL_FCINFO(fcinfo, 4);
866  Datum result;
867 
868  InitFunctionCallInfoData(*fcinfo, NULL, 4, collation, NULL, NULL);
869 
870  fcinfo->args[0].value = arg1;
871  fcinfo->args[0].isnull = false;
872  fcinfo->args[1].value = arg2;
873  fcinfo->args[1].isnull = false;
874  fcinfo->args[2].value = arg3;
875  fcinfo->args[2].isnull = false;
876  fcinfo->args[3].value = arg4;
877  fcinfo->args[3].isnull = false;
878 
879  result = (*func) (fcinfo);
880 
881  /* Check for null result, since caller is clearly not expecting one */
882  if (fcinfo->isnull)
883  elog(ERROR, "function %p returned NULL", (void *) func);
884 
885  return result;
886 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall5Coll()

Datum DirectFunctionCall5Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 889 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by neqjoinsel().

891 {
892  LOCAL_FCINFO(fcinfo, 5);
893  Datum result;
894 
895  InitFunctionCallInfoData(*fcinfo, NULL, 5, collation, NULL, NULL);
896 
897  fcinfo->args[0].value = arg1;
898  fcinfo->args[0].isnull = false;
899  fcinfo->args[1].value = arg2;
900  fcinfo->args[1].isnull = false;
901  fcinfo->args[2].value = arg3;
902  fcinfo->args[2].isnull = false;
903  fcinfo->args[3].value = arg4;
904  fcinfo->args[3].isnull = false;
905  fcinfo->args[4].value = arg5;
906  fcinfo->args[4].isnull = false;
907 
908  result = (*func) (fcinfo);
909 
910  /* Check for null result, since caller is clearly not expecting one */
911  if (fcinfo->isnull)
912  elog(ERROR, "function %p returned NULL", (void *) func);
913 
914  return result;
915 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall6Coll()

Datum DirectFunctionCall6Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 918 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

921 {
922  LOCAL_FCINFO(fcinfo, 6);
923  Datum result;
924 
925  InitFunctionCallInfoData(*fcinfo, NULL, 6, collation, NULL, NULL);
926 
927  fcinfo->args[0].value = arg1;
928  fcinfo->args[0].isnull = false;
929  fcinfo->args[1].value = arg2;
930  fcinfo->args[1].isnull = false;
931  fcinfo->args[2].value = arg3;
932  fcinfo->args[2].isnull = false;
933  fcinfo->args[3].value = arg4;
934  fcinfo->args[3].isnull = false;
935  fcinfo->args[4].value = arg5;
936  fcinfo->args[4].isnull = false;
937  fcinfo->args[5].value = arg6;
938  fcinfo->args[5].isnull = false;
939 
940  result = (*func) (fcinfo);
941 
942  /* Check for null result, since caller is clearly not expecting one */
943  if (fcinfo->isnull)
944  elog(ERROR, "function %p returned NULL", (void *) func);
945 
946  return result;
947 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall7Coll()

Datum DirectFunctionCall7Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 950 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

953 {
954  LOCAL_FCINFO(fcinfo, 7);
955  Datum result;
956 
957  InitFunctionCallInfoData(*fcinfo, NULL, 7, collation, NULL, NULL);
958 
959  fcinfo->args[0].value = arg1;
960  fcinfo->args[0].isnull = false;
961  fcinfo->args[1].value = arg2;
962  fcinfo->args[1].isnull = false;
963  fcinfo->args[2].value = arg3;
964  fcinfo->args[2].isnull = false;
965  fcinfo->args[3].value = arg4;
966  fcinfo->args[3].isnull = false;
967  fcinfo->args[4].value = arg5;
968  fcinfo->args[4].isnull = false;
969  fcinfo->args[5].value = arg6;
970  fcinfo->args[5].isnull = false;
971  fcinfo->args[6].value = arg7;
972  fcinfo->args[6].isnull = false;
973 
974  result = (*func) (fcinfo);
975 
976  /* Check for null result, since caller is clearly not expecting one */
977  if (fcinfo->isnull)
978  elog(ERROR, "function %p returned NULL", (void *) func);
979 
980  return result;
981 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall8Coll()

Datum DirectFunctionCall8Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 984 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

987 {
988  LOCAL_FCINFO(fcinfo, 8);
989  Datum result;
990 
991  InitFunctionCallInfoData(*fcinfo, NULL, 8, collation, NULL, NULL);
992 
993  fcinfo->args[0].value = arg1;
994  fcinfo->args[0].isnull = false;
995  fcinfo->args[1].value = arg2;
996  fcinfo->args[1].isnull = false;
997  fcinfo->args[2].value = arg3;
998  fcinfo->args[2].isnull = false;
999  fcinfo->args[3].value = arg4;
1000  fcinfo->args[3].isnull = false;
1001  fcinfo->args[4].value = arg5;
1002  fcinfo->args[4].isnull = false;
1003  fcinfo->args[5].value = arg6;
1004  fcinfo->args[5].isnull = false;
1005  fcinfo->args[6].value = arg7;
1006  fcinfo->args[6].isnull = false;
1007  fcinfo->args[7].value = arg8;
1008  fcinfo->args[7].isnull = false;
1009 
1010  result = (*func) (fcinfo);
1011 
1012  /* Check for null result, since caller is clearly not expecting one */
1013  if (fcinfo->isnull)
1014  elog(ERROR, "function %p returned NULL", (void *) func);
1015 
1016  return result;
1017 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ DirectFunctionCall9Coll()

Datum DirectFunctionCall9Coll ( PGFunction  func,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1020 of file fmgr.c.

References elog, ERROR, InitFunctionCallInfoData, and LOCAL_FCINFO.

1024 {
1025  LOCAL_FCINFO(fcinfo, 9);
1026  Datum result;
1027 
1028  InitFunctionCallInfoData(*fcinfo, NULL, 9, collation, NULL, NULL);
1029 
1030  fcinfo->args[0].value = arg1;
1031  fcinfo->args[0].isnull = false;
1032  fcinfo->args[1].value = arg2;
1033  fcinfo->args[1].isnull = false;
1034  fcinfo->args[2].value = arg3;
1035  fcinfo->args[2].isnull = false;
1036  fcinfo->args[3].value = arg4;
1037  fcinfo->args[3].isnull = false;
1038  fcinfo->args[4].value = arg5;
1039  fcinfo->args[4].isnull = false;
1040  fcinfo->args[5].value = arg6;
1041  fcinfo->args[5].isnull = false;
1042  fcinfo->args[6].value = arg7;
1043  fcinfo->args[6].isnull = false;
1044  fcinfo->args[7].value = arg8;
1045  fcinfo->args[7].isnull = false;
1046  fcinfo->args[8].value = arg9;
1047  fcinfo->args[8].isnull = false;
1048 
1049  result = (*func) (fcinfo);
1050 
1051  /* Check for null result, since caller is clearly not expecting one */
1052  if (fcinfo->isnull)
1053  elog(ERROR, "function %p returned NULL", (void *) func);
1054 
1055  return result;
1056 }
#define ERROR
Definition: elog.h:43
uintptr_t Datum
Definition: postgres.h:367
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ fetch_finfo_record()

const Pg_finfo_record* fetch_finfo_record ( void *  filehandle,
const char *  funcname 
)

Definition at line 472 of file fmgr.c.

References Pg_finfo_record::api_version, elog, ereport, errcode(), errhint(), errmsg(), ERROR, lookup_external_function(), pfree(), and psprintf().

Referenced by fmgr_c_validator(), and fmgr_info_C_lang().

473 {
474  char *infofuncname;
475  PGFInfoFunction infofunc;
476  const Pg_finfo_record *inforec;
477 
478  infofuncname = psprintf("pg_finfo_%s", funcname);
479 
480  /* Try to look up the info function */
481  infofunc = (PGFInfoFunction) lookup_external_function(filehandle,
482  infofuncname);
483  if (infofunc == NULL)
484  {
485  ereport(ERROR,
486  (errcode(ERRCODE_UNDEFINED_FUNCTION),
487  errmsg("could not find function information for function \"%s\"",
488  funcname),
489  errhint("SQL-callable functions need an accompanying PG_FUNCTION_INFO_V1(funcname).")));
490  return NULL; /* silence compiler */
491  }
492 
493  /* Found, so call it */
494  inforec = (*infofunc) ();
495 
496  /* Validate result as best we can */
497  if (inforec == NULL)
498  elog(ERROR, "null result from info function \"%s\"", infofuncname);
499  switch (inforec->api_version)
500  {
501  case 1:
502  /* OK, no additional fields to validate */
503  break;
504  default:
505  ereport(ERROR,
506  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
507  errmsg("unrecognized API version %d reported by info function \"%s\"",
508  inforec->api_version, infofuncname)));
509  break;
510  }
511 
512  pfree(infofuncname);
513  return inforec;
514 }
int errhint(const char *fmt,...)
Definition: elog.c:1071
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
int errcode(int sqlerrcode)
Definition: elog.c:610
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
void * lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:171
const Pg_finfo_record *(* PGFInfoFunction)(void)
Definition: fmgr.h:399
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
int api_version
Definition: fmgr.h:394

◆ Float8GetDatum()

◆ fmgr_info()

void fmgr_info ( Oid  functionId,
FmgrInfo finfo 
)

Definition at line 126 of file fmgr.c.

References CurrentMemoryContext, and fmgr_info_cxt_security().

Referenced by _bt_find_extreme_element(), _bt_sort_array_elements(), _sv_to_datum_finfo(), BeginCopyFrom(), brin_page_items(), build_pertrans_for_aggref(), call_pltcl_start_proc(), compute_distinct_stats(), CopyTo(), create_foreign_modify(), eqjoinsel_inner(), eqjoinsel_semi(), EventTriggerInvoke(), ExecBuildGroupingEqual(), ExecCallTriggerFunc(), ExecHashTableCreate(), ExecInitAgg(), ExecInitExprRec(), ExecInitFunc(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitWindowAgg(), execTuplesHashPrepare(), ExecuteCallStmt(), fetch_fp_info(), generic_restriction_selectivity(), get_stats_slot_range(), gincost_pattern(), inet_mcv_join_sel(), initialize_peragg(), match_pattern_prefix(), mcv_get_match_bitmap(), networkjoinsel_semi(), networksel(), OidFunctionCall0Coll(), OidFunctionCall1Coll(), OidFunctionCall2Coll(), OidFunctionCall3Coll(), OidFunctionCall4Coll(), OidFunctionCall5Coll(), OidFunctionCall6Coll(), OidFunctionCall7Coll(), OidFunctionCall8Coll(), OidFunctionCall9Coll(), OidInputFunctionCall(), OidOutputFunctionCall(), OidReceiveFunctionCall(), OidSendFunctionCall(), patternsel_common(), pg_stats_ext_mcvlist_items(), plperl_ref_from_pg_array(), prefix_selectivity(), prepare_query_params(), printtup_prepare_info(), scalararraysel(), scalarineqsel(), ScanKeyEntryInitialize(), ScanKeyInit(), text_format(), TupleDescGetAttInMetadata(), and var_eq_const().

127 {
128  fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
129 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:146

◆ fmgr_info_C_lang()

static void fmgr_info_C_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 361 of file fmgr.c.

References Pg_finfo_record::api_version, elog, ERROR, fetch_finfo_record(), FmgrInfo::fn_addr, CFuncHashTabEntry::inforec, load_external_function(), lookup_C_func(), pfree(), PROCOID, record_C_func(), SysCacheGetAttr(), TextDatumGetCString, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_cxt_security().

362 {
363  CFuncHashTabEntry *hashentry;
364  PGFunction user_fn;
365  const Pg_finfo_record *inforec;
366  bool isnull;
367 
368  /*
369  * See if we have the function address cached already
370  */
371  hashentry = lookup_C_func(procedureTuple);
372  if (hashentry)
373  {
374  user_fn = hashentry->user_fn;
375  inforec = hashentry->inforec;
376  }
377  else
378  {
379  Datum prosrcattr,
380  probinattr;
381  char *prosrcstring,
382  *probinstring;
383  void *libraryhandle;
384 
385  /*
386  * Get prosrc and probin strings (link symbol and library filename).
387  * While in general these columns might be null, that's not allowed
388  * for C-language functions.
389  */
390  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
391  Anum_pg_proc_prosrc, &isnull);
392  if (isnull)
393  elog(ERROR, "null prosrc for C function %u", functionId);
394  prosrcstring = TextDatumGetCString(prosrcattr);
395 
396  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
397  Anum_pg_proc_probin, &isnull);
398  if (isnull)
399  elog(ERROR, "null probin for C function %u", functionId);
400  probinstring = TextDatumGetCString(probinattr);
401 
402  /* Look up the function itself */
403  user_fn = load_external_function(probinstring, prosrcstring, true,
404  &libraryhandle);
405 
406  /* Get the function information record (real or default) */
407  inforec = fetch_finfo_record(libraryhandle, prosrcstring);
408 
409  /* Cache the addresses for later calls */
410  record_C_func(procedureTuple, user_fn, inforec);
411 
412  pfree(prosrcstring);
413  pfree(probinstring);
414  }
415 
416  switch (inforec->api_version)
417  {
418  case 1:
419  /* New style: call directly */
420  finfo->fn_addr = user_fn;
421  break;
422  default:
423  /* Shouldn't get here if fetch_finfo_record did its job */
424  elog(ERROR, "unrecognized function API version: %d",
425  inforec->api_version);
426  break;
427  }
428 }
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
PGFunction fn_addr
Definition: fmgr.h:58
const Pg_finfo_record * inforec
Definition: fmgr.c:51
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
PGFunction user_fn
Definition: fmgr.c:50
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:107
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
static void record_C_func(HeapTuple procedureTuple, PGFunction user_fn, const Pg_finfo_record *inforec)
Definition: fmgr.c:556
static CFuncHashTabEntry * lookup_C_func(HeapTuple procedureTuple)
Definition: fmgr.c:532
const Pg_finfo_record * fetch_finfo_record(void *filehandle, const char *funcname)
Definition: fmgr.c:472
#define elog(elevel,...)
Definition: elog.h:214
int api_version
Definition: fmgr.h:394

◆ fmgr_info_copy()

void fmgr_info_copy ( FmgrInfo dstinfo,
FmgrInfo srcinfo,
MemoryContext  destcxt 
)

Definition at line 612 of file fmgr.c.

References FmgrInfo::fn_extra, and FmgrInfo::fn_mcxt.

Referenced by bringetbitmap(), find_partition_scheme(), gistrescan(), inclusion_get_procinfo(), initBloomState(), initGinState(), initGISTstate(), perform_pruning_base_step(), satisfies_hash_partition(), ScanKeyEntryInitializeWithInfo(), and spgbeginscan().

614 {
615  memcpy(dstinfo, srcinfo, sizeof(FmgrInfo));
616  dstinfo->fn_mcxt = destcxt;
617  dstinfo->fn_extra = NULL;
618 }
Definition: fmgr.h:56
MemoryContext fn_mcxt
Definition: fmgr.h:65
void * fn_extra
Definition: fmgr.h:64

◆ fmgr_info_cxt()

◆ fmgr_info_cxt_security()

static void fmgr_info_cxt_security ( Oid  functionId,
FmgrInfo finfo,
MemoryContext  mcxt,
bool  ignore_security 
)
static

Definition at line 146 of file fmgr.c.

References elog, ereport, errcode(), errmsg(), ERROR, fmgr_info_C_lang(), fmgr_info_other_lang(), fmgr_isbuiltin(), fmgr_lookupByName(), fmgr_security_definer(), fmgr_sql(), FmgrHookIsNeeded, FmgrInfo::fn_addr, FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FmgrInfo::fn_nargs, FmgrInfo::fn_oid, FmgrInfo::fn_retset, FmgrInfo::fn_stats, FmgrInfo::fn_strict, FmgrBuiltin::func, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, InvalidOid, FmgrBuiltin::nargs, ObjectIdGetDatum, pfree(), PROCOID, ReleaseSysCache(), FmgrBuiltin::retset, SearchSysCache1(), FmgrBuiltin::strict, SysCacheGetAttr(), TextDatumGetCString, TRACK_FUNC_ALL, TRACK_FUNC_OFF, and TRACK_FUNC_PL.

Referenced by fmgr_info(), fmgr_info_cxt(), fmgr_info_other_lang(), and fmgr_security_definer().

148 {
149  const FmgrBuiltin *fbp;
150  HeapTuple procedureTuple;
151  Form_pg_proc procedureStruct;
152  Datum prosrcdatum;
153  bool isnull;
154  char *prosrc;
155 
156  /*
157  * fn_oid *must* be filled in last. Some code assumes that if fn_oid is
158  * valid, the whole struct is valid. Some FmgrInfo struct's do survive
159  * elogs.
160  */
161  finfo->fn_oid = InvalidOid;
162  finfo->fn_extra = NULL;
163  finfo->fn_mcxt = mcxt;
164  finfo->fn_expr = NULL; /* caller may set this later */
165 
166  if ((fbp = fmgr_isbuiltin(functionId)) != NULL)
167  {
168  /*
169  * Fast path for builtin functions: don't bother consulting pg_proc
170  */
171  finfo->fn_nargs = fbp->nargs;
172  finfo->fn_strict = fbp->strict;
173  finfo->fn_retset = fbp->retset;
174  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
175  finfo->fn_addr = fbp->func;
176  finfo->fn_oid = functionId;
177  return;
178  }
179 
180  /* Otherwise we need the pg_proc entry */
181  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
182  if (!HeapTupleIsValid(procedureTuple))
183  elog(ERROR, "cache lookup failed for function %u", functionId);
184  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
185 
186  finfo->fn_nargs = procedureStruct->pronargs;
187  finfo->fn_strict = procedureStruct->proisstrict;
188  finfo->fn_retset = procedureStruct->proretset;
189 
190  /*
191  * If it has prosecdef set, non-null proconfig, or if a plugin wants to
192  * hook function entry/exit, use fmgr_security_definer call handler ---
193  * unless we are being called again by fmgr_security_definer or
194  * fmgr_info_other_lang.
195  *
196  * When using fmgr_security_definer, function stats tracking is always
197  * disabled at the outer level, and instead we set the flag properly in
198  * fmgr_security_definer's private flinfo and implement the tracking
199  * inside fmgr_security_definer. This loses the ability to charge the
200  * overhead of fmgr_security_definer to the function, but gains the
201  * ability to set the track_functions GUC as a local GUC parameter of an
202  * interesting function and have the right things happen.
203  */
204  if (!ignore_security &&
205  (procedureStruct->prosecdef ||
206  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
207  FmgrHookIsNeeded(functionId)))
208  {
210  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
211  finfo->fn_oid = functionId;
212  ReleaseSysCache(procedureTuple);
213  return;
214  }
215 
216  switch (procedureStruct->prolang)
217  {
218  case INTERNALlanguageId:
219 
220  /*
221  * For an ordinary builtin function, we should never get here
222  * because the fmgr_isbuiltin() search above will have succeeded.
223  * However, if the user has done a CREATE FUNCTION to create an
224  * alias for a builtin function, we can end up here. In that case
225  * we have to look up the function by name. The name of the
226  * internal function is stored in prosrc (it doesn't have to be
227  * the same as the name of the alias!)
228  */
229  prosrcdatum = SysCacheGetAttr(PROCOID, procedureTuple,
230  Anum_pg_proc_prosrc, &isnull);
231  if (isnull)
232  elog(ERROR, "null prosrc");
233  prosrc = TextDatumGetCString(prosrcdatum);
234  fbp = fmgr_lookupByName(prosrc);
235  if (fbp == NULL)
236  ereport(ERROR,
237  (errcode(ERRCODE_UNDEFINED_FUNCTION),
238  errmsg("internal function \"%s\" is not in internal lookup table",
239  prosrc)));
240  pfree(prosrc);
241  /* Should we check that nargs, strict, retset match the table? */
242  finfo->fn_addr = fbp->func;
243  /* note this policy is also assumed in fast path above */
244  finfo->fn_stats = TRACK_FUNC_ALL; /* ie, never track */
245  break;
246 
247  case ClanguageId:
248  fmgr_info_C_lang(functionId, finfo, procedureTuple);
249  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
250  break;
251 
252  case SQLlanguageId:
253  finfo->fn_addr = fmgr_sql;
254  finfo->fn_stats = TRACK_FUNC_PL; /* ie, track if ALL */
255  break;
256 
257  default:
258  fmgr_info_other_lang(functionId, finfo, procedureTuple);
259  finfo->fn_stats = TRACK_FUNC_OFF; /* ie, track if not OFF */
260  break;
261  }
262 
263  finfo->fn_oid = functionId;
264  ReleaseSysCache(procedureTuple);
265 }
bool strict
Definition: fmgrtab.h:29
short fn_nargs
Definition: fmgr.h:60
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
MemoryContext fn_mcxt
Definition: fmgr.h:65
short nargs
Definition: fmgrtab.h:28
PGFunction fn_addr
Definition: fmgr.h:58
static void fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:435
int errcode(int sqlerrcode)
Definition: elog.c:610
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:772
static void fmgr_info_C_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
Definition: fmgr.c:361
PGFunction func
Definition: fmgrtab.h:32
void pfree(void *pointer)
Definition: mcxt.c:1056
bool fn_retset
Definition: fmgr.h:62
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
Datum fmgr_sql(PG_FUNCTION_ARGS)
Definition: functions.c:1007
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:100
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define TextDatumGetCString(d)
Definition: builtins.h:87
static const FmgrBuiltin * fmgr_isbuiltin(Oid id)
Definition: fmgr.c:75
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define ereport(elevel,...)
Definition: elog.h:144
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
fmNodePtr fn_expr
Definition: fmgr.h:66
Datum fmgr_security_definer(PG_FUNCTION_ARGS)
Definition: fmgr.c:662
void * fn_extra
Definition: fmgr.h:64
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
unsigned char fn_stats
Definition: fmgr.h:63
bool retset
Definition: fmgrtab.h:30

◆ fmgr_info_other_lang()

static void fmgr_info_other_lang ( Oid  functionId,
FmgrInfo finfo,
HeapTuple  procedureTuple 
)
static

Definition at line 435 of file fmgr.c.

References CurrentMemoryContext, elog, ERROR, fmgr_info_cxt_security(), FmgrInfo::fn_addr, GETSTRUCT, HeapTupleIsValid, LANGOID, ObjectIdGetDatum, ReleaseSysCache(), and SearchSysCache1().

Referenced by fmgr_info_cxt_security().

436 {
437  Form_pg_proc procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
438  Oid language = procedureStruct->prolang;
439  HeapTuple languageTuple;
440  Form_pg_language languageStruct;
441  FmgrInfo plfinfo;
442 
443  languageTuple = SearchSysCache1(LANGOID, ObjectIdGetDatum(language));
444  if (!HeapTupleIsValid(languageTuple))
445  elog(ERROR, "cache lookup failed for language %u", language);
446  languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
447 
448  /*
449  * Look up the language's call handler function, ignoring any attributes
450  * that would normally cause insertion of fmgr_security_definer. We need
451  * to get back a bare pointer to the actual C-language function.
452  */
453  fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
454  CurrentMemoryContext, true);
455  finfo->fn_addr = plfinfo.fn_addr;
456 
457  ReleaseSysCache(languageTuple);
458 }
Definition: fmgr.h:56
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
PGFunction fn_addr
Definition: fmgr.h:58
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
#define elog(elevel,...)
Definition: elog.h:214
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:146

◆ fmgr_internal_function()

Oid fmgr_internal_function ( const char *  proname)

Definition at line 627 of file fmgr.c.

References fmgr_lookupByName(), FmgrBuiltin::foid, and InvalidOid.

Referenced by fmgr_internal_validator().

628 {
629  const FmgrBuiltin *fbp = fmgr_lookupByName(proname);
630 
631  if (fbp == NULL)
632  return InvalidOid;
633  return fbp->foid;
634 }
NameData proname
Definition: pg_proc.h:35
Oid foid
Definition: fmgrtab.h:27
static const FmgrBuiltin * fmgr_lookupByName(const char *name)
Definition: fmgr.c:100
#define InvalidOid
Definition: postgres_ext.h:36

◆ fmgr_isbuiltin()

static const FmgrBuiltin* fmgr_isbuiltin ( Oid  id)
static

Definition at line 75 of file fmgr.c.

References fmgr_builtin_oid_index, fmgr_builtins, fmgr_last_builtin_oid, and InvalidOidBuiltinMapping.

Referenced by fmgr_info_cxt_security().

76 {
77  uint16 index;
78 
79  /* fast lookup only possible if original oid still assigned */
80  if (id > fmgr_last_builtin_oid)
81  return NULL;
82 
83  /*
84  * Lookup function data. If there's a miss in that range it's likely a
85  * nonexistent function, returning NULL here will trigger an ERROR later.
86  */
87  index = fmgr_builtin_oid_index[id];
88  if (index == InvalidOidBuiltinMapping)
89  return NULL;
90 
91  return &fmgr_builtins[index];
92 }
const FmgrBuiltin fmgr_builtins[]
#define InvalidOidBuiltinMapping
Definition: fmgrtab.h:45
Definition: type.h:89
const Oid fmgr_last_builtin_oid
unsigned short uint16
Definition: c.h:373
const uint16 fmgr_builtin_oid_index[]

◆ fmgr_lookupByName()

static const FmgrBuiltin* fmgr_lookupByName ( const char *  name)
static

Definition at line 100 of file fmgr.c.

References fmgr_builtins, fmgr_nbuiltins, and i.

Referenced by fmgr_info_cxt_security(), and fmgr_internal_function().

101 {
102  int i;
103 
104  for (i = 0; i < fmgr_nbuiltins; i++)
105  {
106  if (strcmp(name, fmgr_builtins[i].funcName) == 0)
107  return fmgr_builtins + i;
108  }
109  return NULL;
110 }
const int fmgr_nbuiltins
const FmgrBuiltin fmgr_builtins[]
const char * name
Definition: encode.c:561
int i

◆ fmgr_security_definer()

Datum fmgr_security_definer ( PG_FUNCTION_ARGS  )

Definition at line 662 of file fmgr.c.

References fmgr_security_definer_cache::arg, AtEOXact_GUC(), DatumGetArrayTypePCopy, elog, ERROR, ExprMultipleResult, FHET_ABORT, FHET_END, FHET_START, fmgr_security_definer_cache::flinfo, fmgr_hook, fmgr_info_cxt_security(), FmgrInfo::fn_expr, FmgrInfo::fn_extra, FmgrInfo::fn_mcxt, FunctionCallInvoke, GETSTRUCT, GetUserIdAndSecContext(), GUC_ACTION_SAVE, HeapTupleIsValid, IsA, MemoryContextAllocZero(), MemoryContextSwitchTo(), NewGUCNestLevel(), ObjectIdGetDatum, OidIsValid, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PGC_S_SESSION, PGC_SUSET, PGC_USERSET, pgstat_end_function_usage(), pgstat_init_function_usage(), ProcessGUCArray(), PROCOID, fmgr_security_definer_cache::proconfig, ReleaseSysCache(), SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, SetUserIdAndSecContext(), superuser(), SysCacheGetAttr(), and fmgr_security_definer_cache::userid.

Referenced by fmgr_info_cxt_security().

663 {
664  Datum result;
665  struct fmgr_security_definer_cache *volatile fcache;
666  FmgrInfo *save_flinfo;
667  Oid save_userid;
668  int save_sec_context;
669  volatile int save_nestlevel;
670  PgStat_FunctionCallUsage fcusage;
671 
672  if (!fcinfo->flinfo->fn_extra)
673  {
674  HeapTuple tuple;
675  Form_pg_proc procedureStruct;
676  Datum datum;
677  bool isnull;
678  MemoryContext oldcxt;
679 
680  fcache = MemoryContextAllocZero(fcinfo->flinfo->fn_mcxt,
681  sizeof(*fcache));
682 
683  fmgr_info_cxt_security(fcinfo->flinfo->fn_oid, &fcache->flinfo,
684  fcinfo->flinfo->fn_mcxt, true);
685  fcache->flinfo.fn_expr = fcinfo->flinfo->fn_expr;
686 
687  tuple = SearchSysCache1(PROCOID,
688  ObjectIdGetDatum(fcinfo->flinfo->fn_oid));
689  if (!HeapTupleIsValid(tuple))
690  elog(ERROR, "cache lookup failed for function %u",
691  fcinfo->flinfo->fn_oid);
692  procedureStruct = (Form_pg_proc) GETSTRUCT(tuple);
693 
694  if (procedureStruct->prosecdef)
695  fcache->userid = procedureStruct->proowner;
696 
697  datum = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_proconfig,
698  &isnull);
699  if (!isnull)
700  {
701  oldcxt = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
702  fcache->proconfig = DatumGetArrayTypePCopy(datum);
703  MemoryContextSwitchTo(oldcxt);
704  }
705 
706  ReleaseSysCache(tuple);
707 
708  fcinfo->flinfo->fn_extra = fcache;
709  }
710  else
711  fcache = fcinfo->flinfo->fn_extra;
712 
713  /* GetUserIdAndSecContext is cheap enough that no harm in a wasted call */
714  GetUserIdAndSecContext(&save_userid, &save_sec_context);
715  if (fcache->proconfig) /* Need a new GUC nesting level */
716  save_nestlevel = NewGUCNestLevel();
717  else
718  save_nestlevel = 0; /* keep compiler quiet */
719 
720  if (OidIsValid(fcache->userid))
722  save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
723 
724  if (fcache->proconfig)
725  {
726  ProcessGUCArray(fcache->proconfig,
730  }
731 
732  /* function manager hook */
733  if (fmgr_hook)
734  (*fmgr_hook) (FHET_START, &fcache->flinfo, &fcache->arg);
735 
736  /*
737  * We don't need to restore GUC or userid settings on error, because the
738  * ensuing xact or subxact abort will do that. The PG_TRY block is only
739  * needed to clean up the flinfo link.
740  */
741  save_flinfo = fcinfo->flinfo;
742 
743  PG_TRY();
744  {
745  fcinfo->flinfo = &fcache->flinfo;
746 
747  /* See notes in fmgr_info_cxt_security */
748  pgstat_init_function_usage(fcinfo, &fcusage);
749 
750  result = FunctionCallInvoke(fcinfo);
751 
752  /*
753  * We could be calling either a regular or a set-returning function,
754  * so we have to test to see what finalize flag to use.
755  */
756  pgstat_end_function_usage(&fcusage,
757  (fcinfo->resultinfo == NULL ||
758  !IsA(fcinfo->resultinfo, ReturnSetInfo) ||
759  ((ReturnSetInfo *) fcinfo->resultinfo)->isDone != ExprMultipleResult));
760  }
761  PG_CATCH();
762  {
763  fcinfo->flinfo = save_flinfo;
764  if (fmgr_hook)
765  (*fmgr_hook) (FHET_ABORT, &fcache->flinfo, &fcache->arg);
766  PG_RE_THROW();
767  }
768  PG_END_TRY();
769 
770  fcinfo->flinfo = save_flinfo;
771 
772  if (fcache->proconfig)
773  AtEOXact_GUC(true, save_nestlevel);
774  if (OidIsValid(fcache->userid))
775  SetUserIdAndSecContext(save_userid, save_sec_context);
776  if (fmgr_hook)
777  (*fmgr_hook) (FHET_END, &fcache->flinfo, &fcache->arg);
778 
779  return result;
780 }
Definition: fmgr.h:56
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
MemoryContext fn_mcxt
Definition: fmgr.h:65
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:562
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1675
Definition: guc.h:75
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:555
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:5956
Definition: fmgr.h:760
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
ArrayType * proconfig
Definition: fmgr.c:647
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define DatumGetArrayTypePCopy(X)
Definition: array.h:250
PGDLLIMPORT fmgr_hook_type fmgr_hook
Definition: fmgr.c:39
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:298
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839
void ProcessGUCArray(ArrayType *array, GucContext context, GucSource source, GucAction action)
Definition: guc.c:10567
#define PG_CATCH()
Definition: elog.h:305
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
fmNodePtr fn_expr
Definition: fmgr.h:66
#define PG_RE_THROW()
Definition: elog.h:336
void * fn_extra
Definition: fmgr.h:64
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1747
int NewGUCNestLevel(void)
Definition: guc.c:5942
#define elog(elevel,...)
Definition: elog.h:214
#define PG_TRY()
Definition: elog.h:295
#define PG_END_TRY()
Definition: elog.h:320
static void fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt, bool ignore_security)
Definition: fmgr.c:146

◆ fmgr_symbol()

void fmgr_symbol ( Oid  functionId,
char **  mod,
char **  fn 
)

Definition at line 283 of file fmgr.c.

References elog, ERROR, FmgrHookIsNeeded, GETSTRUCT, heap_attisnull(), HeapTupleIsValid, ObjectIdGetDatum, PROCOID, pstrdup(), ReleaseSysCache(), SearchSysCache1(), SysCacheGetAttr(), and TextDatumGetCString.

Referenced by llvm_function_reference().

284 {
285  HeapTuple procedureTuple;
286  Form_pg_proc procedureStruct;
287  bool isnull;
288  Datum prosrcattr;
289  Datum probinattr;
290 
291  /* Otherwise we need the pg_proc entry */
292  procedureTuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionId));
293  if (!HeapTupleIsValid(procedureTuple))
294  elog(ERROR, "cache lookup failed for function %u", functionId);
295  procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
296 
297  /*
298  */
299  if (procedureStruct->prosecdef ||
300  !heap_attisnull(procedureTuple, Anum_pg_proc_proconfig, NULL) ||
301  FmgrHookIsNeeded(functionId))
302  {
303  *mod = NULL; /* core binary */
304  *fn = pstrdup("fmgr_security_definer");
305  ReleaseSysCache(procedureTuple);
306  return;
307  }
308 
309  /* see fmgr_info_cxt_security for the individual cases */
310  switch (procedureStruct->prolang)
311  {
312  case INTERNALlanguageId:
313  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
314  Anum_pg_proc_prosrc, &isnull);
315  if (isnull)
316  elog(ERROR, "null prosrc");
317 
318  *mod = NULL; /* core binary */
319  *fn = TextDatumGetCString(prosrcattr);
320  break;
321 
322  case ClanguageId:
323  prosrcattr = SysCacheGetAttr(PROCOID, procedureTuple,
324  Anum_pg_proc_prosrc, &isnull);
325  if (isnull)
326  elog(ERROR, "null prosrc for C function %u", functionId);
327 
328  probinattr = SysCacheGetAttr(PROCOID, procedureTuple,
329  Anum_pg_proc_probin, &isnull);
330  if (isnull)
331  elog(ERROR, "null probin for C function %u", functionId);
332 
333  /*
334  * No need to check symbol presence / API version here, already
335  * checked in fmgr_info_cxt_security.
336  */
337  *mod = TextDatumGetCString(probinattr);
338  *fn = TextDatumGetCString(prosrcattr);
339  break;
340 
341  case SQLlanguageId:
342  *mod = NULL; /* core binary */
343  *fn = pstrdup("fmgr_sql");
344  break;
345 
346  default:
347  *mod = NULL;
348  *fn = NULL; /* unknown, pass pointer */
349  break;
350  }
351 
352  ReleaseSysCache(procedureTuple);
353 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1186
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
#define FmgrHookIsNeeded(fn_oid)
Definition: fmgr.h:772
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define TextDatumGetCString(d)
Definition: builtins.h:87
uintptr_t Datum
Definition: postgres.h:367
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
static void * fn(void *arg)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall0Coll()

Datum FunctionCall0Coll ( FmgrInfo flinfo,
Oid  collation 
)

Definition at line 1115 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall0Coll().

1116 {
1117  LOCAL_FCINFO(fcinfo, 0);
1118  Datum result;
1119 
1120  InitFunctionCallInfoData(*fcinfo, flinfo, 0, collation, NULL, NULL);
1121 
1122  result = FunctionCallInvoke(fcinfo);
1123 
1124  /* Check for null result, since caller is clearly not expecting one */
1125  if (fcinfo->isnull)
1126  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1127 
1128  return result;
1129 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall1Coll()

Datum FunctionCall1Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1 
)

Definition at line 1132 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _hash_datum2hashkey(), brin_inclusion_add_value(), element_hash(), ExecHashBuildSkewHash(), ExecHashGetHashValue(), gistdentryinit(), gistFetchAtt(), gistFormTuple(), hash_range(), OidFunctionCall1Coll(), signValue(), spgdoinsert(), and TupleHashTableHash_internal().

1133 {
1134  LOCAL_FCINFO(fcinfo, 1);
1135  Datum result;
1136 
1137  InitFunctionCallInfoData(*fcinfo, flinfo, 1, collation, NULL, NULL);
1138 
1139  fcinfo->args[0].value = arg1;
1140  fcinfo->args[0].isnull = false;
1141 
1142  result = FunctionCallInvoke(fcinfo);
1143 
1144  /* Check for null result, since caller is clearly not expecting one */
1145  if (fcinfo->isnull)
1146  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1147 
1148  return result;
1149 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall2Coll()

Datum FunctionCall2Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1152 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by _bt_check_rowcompare(), _bt_checkkeys(), _bt_compare(), _bt_compare_array_elements(), _bt_compare_scankey_args(), _bt_find_extreme_element(), _bt_keep_natts(), _hash_checkqual(), array_position_common(), array_positions(), brin_inclusion_add_value(), brin_inclusion_consistent(), brin_inclusion_union(), brin_minmax_add_value(), brin_minmax_consistent(), brin_minmax_union(), call_subtype_diff(), cmpEntries(), compute_distinct_stats(), compute_partition_hash_value(), compute_range_stats(), create_range_bounds(), doPickSplit(), element_compare(), execTuplesUnequal(), genericPickSplit(), get_distance(), get_position(), get_stats_slot_range(), ginCompareEntries(), gistMakeUnionItVec(), gistMakeUnionKey(), gistUserPicksplit(), hash_range_extended(), ineq_histogram_selectivity(), make_greater_string(), mcv_get_match_bitmap(), merge_list_bounds(), mode_final(), OidFunctionCall2Coll(), partition_list_bsearch(), partition_rbound_cmp(), partition_rbound_datum_cmp(), process_ordered_aggregate_single(), qsort_partition_list_value_cmp(), range_cmp_bound_values(), range_cmp_bounds(), range_contains_elem_internal(), ri_AttributesEqual(), satisfies_hash_partition(), spgdoinsert(), spgGetCache(), spgInnerTest(), spgLeafTest(), and tuples_equal().

1153 {
1154  LOCAL_FCINFO(fcinfo, 2);
1155  Datum result;
1156 
1157  InitFunctionCallInfoData(*fcinfo, flinfo, 2, collation, NULL, NULL);
1158 
1159  fcinfo->args[0].value = arg1;
1160  fcinfo->args[0].isnull = false;
1161  fcinfo->args[1].value = arg2;
1162  fcinfo->args[1].isnull = false;
1163 
1164  result = FunctionCallInvoke(fcinfo);
1165 
1166  /* Check for null result, since caller is clearly not expecting one */
1167  if (fcinfo->isnull)
1168  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1169 
1170  return result;
1171 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall3Coll()

Datum FunctionCall3Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1174 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by bringetbitmap(), ginExtractEntries(), gistKeyIsEQ(), gistpenalty(), OidFunctionCall3Coll(), and union_tuples().

1176 {
1177  LOCAL_FCINFO(fcinfo, 3);
1178  Datum result;
1179 
1180  InitFunctionCallInfoData(*fcinfo, flinfo, 3, collation, NULL, NULL);
1181 
1182  fcinfo->args[0].value = arg1;
1183  fcinfo->args[0].isnull = false;
1184  fcinfo->args[1].value = arg2;
1185  fcinfo->args[1].isnull = false;
1186  fcinfo->args[2].value = arg3;
1187  fcinfo->args[2].isnull = false;
1188 
1189  result = FunctionCallInvoke(fcinfo);
1190 
1191  /* Check for null result, since caller is clearly not expecting one */
1192  if (fcinfo->isnull)
1193  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1194 
1195  return result;
1196 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall4Coll()

Datum FunctionCall4Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1199 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by brinbuildCallback(), brininsert(), collectMatchBitmap(), matchPartialInPendingList(), OidFunctionCall4Coll(), and scalararraysel().

1201 {
1202  LOCAL_FCINFO(fcinfo, 4);
1203  Datum result;
1204 
1205  InitFunctionCallInfoData(*fcinfo, flinfo, 4, collation, NULL, NULL);
1206 
1207  fcinfo->args[0].value = arg1;
1208  fcinfo->args[0].isnull = false;
1209  fcinfo->args[1].value = arg2;
1210  fcinfo->args[1].isnull = false;
1211  fcinfo->args[2].value = arg3;
1212  fcinfo->args[2].isnull = false;
1213  fcinfo->args[3].value = arg4;
1214  fcinfo->args[3].isnull = false;
1215 
1216  result = FunctionCallInvoke(fcinfo);
1217 
1218  /* Check for null result, since caller is clearly not expecting one */
1219  if (fcinfo->isnull)
1220  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1221 
1222  return result;
1223 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall5Coll()

Datum FunctionCall5Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1226 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by gistindex_keytest(), OidFunctionCall5Coll(), scalararraysel(), update_frameheadpos(), and update_frametailpos().

1228 {
1229  LOCAL_FCINFO(fcinfo, 5);
1230  Datum result;
1231 
1232  InitFunctionCallInfoData(*fcinfo, flinfo, 5, collation, NULL, NULL);
1233 
1234  fcinfo->args[0].value = arg1;
1235  fcinfo->args[0].isnull = false;
1236  fcinfo->args[1].value = arg2;
1237  fcinfo->args[1].isnull = false;
1238  fcinfo->args[2].value = arg3;
1239  fcinfo->args[2].isnull = false;
1240  fcinfo->args[3].value = arg4;
1241  fcinfo->args[3].isnull = false;
1242  fcinfo->args[4].value = arg5;
1243  fcinfo->args[4].isnull = false;
1244 
1245  result = FunctionCallInvoke(fcinfo);
1246 
1247  /* Check for null result, since caller is clearly not expecting one */
1248  if (fcinfo->isnull)
1249  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1250 
1251  return result;
1252 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall6Coll()

Datum FunctionCall6Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1255 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall6Coll().

1258 {
1259  LOCAL_FCINFO(fcinfo, 6);
1260  Datum result;
1261 
1262  InitFunctionCallInfoData(*fcinfo, flinfo, 6, collation, NULL, NULL);
1263 
1264  fcinfo->args[0].value = arg1;
1265  fcinfo->args[0].isnull = false;
1266  fcinfo->args[1].value = arg2;
1267  fcinfo->args[1].isnull = false;
1268  fcinfo->args[2].value = arg3;
1269  fcinfo->args[2].isnull = false;
1270  fcinfo->args[3].value = arg4;
1271  fcinfo->args[3].isnull = false;
1272  fcinfo->args[4].value = arg5;
1273  fcinfo->args[4].isnull = false;
1274  fcinfo->args[5].value = arg6;
1275  fcinfo->args[5].isnull = false;
1276 
1277  result = FunctionCallInvoke(fcinfo);
1278 
1279  /* Check for null result, since caller is clearly not expecting one */
1280  if (fcinfo->isnull)
1281  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1282 
1283  return result;
1284 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall7Coll()

Datum FunctionCall7Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1287 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directTriConsistentFn(), gincost_pattern(), OidFunctionCall7Coll(), and shimBoolConsistentFn().

1290 {
1291  LOCAL_FCINFO(fcinfo, 7);
1292  Datum result;
1293 
1294  InitFunctionCallInfoData(*fcinfo, flinfo, 7, collation, NULL, NULL);
1295 
1296  fcinfo->args[0].value = arg1;
1297  fcinfo->args[0].isnull = false;
1298  fcinfo->args[1].value = arg2;
1299  fcinfo->args[1].isnull = false;
1300  fcinfo->args[2].value = arg3;
1301  fcinfo->args[2].isnull = false;
1302  fcinfo->args[3].value = arg4;
1303  fcinfo->args[3].isnull = false;
1304  fcinfo->args[4].value = arg5;
1305  fcinfo->args[4].isnull = false;
1306  fcinfo->args[5].value = arg6;
1307  fcinfo->args[5].isnull = false;
1308  fcinfo->args[6].value = arg7;
1309  fcinfo->args[6].isnull = false;
1310 
1311  result = FunctionCallInvoke(fcinfo);
1312 
1313  /* Check for null result, since caller is clearly not expecting one */
1314  if (fcinfo->isnull)
1315  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1316 
1317  return result;
1318 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall8Coll()

Datum FunctionCall8Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1321 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by directBoolConsistentFn(), and OidFunctionCall8Coll().

1324 {
1325  LOCAL_FCINFO(fcinfo, 8);
1326  Datum result;
1327 
1328  InitFunctionCallInfoData(*fcinfo, flinfo, 8, collation, NULL, NULL);
1329 
1330  fcinfo->args[0].value = arg1;
1331  fcinfo->args[0].isnull = false;
1332  fcinfo->args[1].value = arg2;
1333  fcinfo->args[1].isnull = false;
1334  fcinfo->args[2].value = arg3;
1335  fcinfo->args[2].isnull = false;
1336  fcinfo->args[3].value = arg4;
1337  fcinfo->args[3].isnull = false;
1338  fcinfo->args[4].value = arg5;
1339  fcinfo->args[4].isnull = false;
1340  fcinfo->args[5].value = arg6;
1341  fcinfo->args[5].isnull = false;
1342  fcinfo->args[6].value = arg7;
1343  fcinfo->args[6].isnull = false;
1344  fcinfo->args[7].value = arg8;
1345  fcinfo->args[7].isnull = false;
1346 
1347  result = FunctionCallInvoke(fcinfo);
1348 
1349  /* Check for null result, since caller is clearly not expecting one */
1350  if (fcinfo->isnull)
1351  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1352 
1353  return result;
1354 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ FunctionCall9Coll()

Datum FunctionCall9Coll ( FmgrInfo flinfo,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1357 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FunctionCallInvoke, InitFunctionCallInfoData, and LOCAL_FCINFO.

Referenced by OidFunctionCall9Coll().

1361 {
1362  LOCAL_FCINFO(fcinfo, 9);
1363  Datum result;
1364 
1365  InitFunctionCallInfoData(*fcinfo, flinfo, 9, collation, NULL, NULL);
1366 
1367  fcinfo->args[0].value = arg1;
1368  fcinfo->args[0].isnull = false;
1369  fcinfo->args[1].value = arg2;
1370  fcinfo->args[1].isnull = false;
1371  fcinfo->args[2].value = arg3;
1372  fcinfo->args[2].isnull = false;
1373  fcinfo->args[3].value = arg4;
1374  fcinfo->args[3].isnull = false;
1375  fcinfo->args[4].value = arg5;
1376  fcinfo->args[4].isnull = false;
1377  fcinfo->args[5].value = arg6;
1378  fcinfo->args[5].isnull = false;
1379  fcinfo->args[6].value = arg7;
1380  fcinfo->args[6].isnull = false;
1381  fcinfo->args[7].value = arg8;
1382  fcinfo->args[7].isnull = false;
1383  fcinfo->args[8].value = arg9;
1384  fcinfo->args[8].isnull = false;
1385 
1386  result = FunctionCallInvoke(fcinfo);
1387 
1388  /* Check for null result, since caller is clearly not expecting one */
1389  if (fcinfo->isnull)
1390  elog(ERROR, "function %u returned NULL", flinfo->fn_oid);
1391 
1392  return result;
1393 }
#define ERROR
Definition: elog.h:43
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define elog(elevel,...)
Definition: elog.h:214

◆ get_call_expr_arg_stable()

bool get_call_expr_arg_stable ( Node expr,
int  argnum 
)

Definition at line 1888 of file fmgr.c.

References fmgr_security_definer_cache::arg, generate_unaccent_rules::args, IsA, list_length(), list_nth(), and PARAM_EXTERN.

Referenced by get_fn_expr_arg_stable().

1889 {
1890  List *args;
1891  Node *arg;
1892 
1893  if (expr == NULL)
1894  return false;
1895 
1896  if (IsA(expr, FuncExpr))
1897  args = ((FuncExpr *) expr)->args;
1898  else if (IsA(expr, OpExpr))
1899  args = ((OpExpr *) expr)->args;
1900  else if (IsA(expr, DistinctExpr))
1901  args = ((DistinctExpr *) expr)->args;
1902  else if (IsA(expr, ScalarArrayOpExpr))
1903  args = ((ScalarArrayOpExpr *) expr)->args;
1904  else if (IsA(expr, NullIfExpr))
1905  args = ((NullIfExpr *) expr)->args;
1906  else if (IsA(expr, WindowFunc))
1907  args = ((WindowFunc *) expr)->args;
1908  else
1909  return false;
1910 
1911  if (argnum < 0 || argnum >= list_length(args))
1912  return false;
1913 
1914  arg = (Node *) list_nth(args, argnum);
1915 
1916  /*
1917  * Either a true Const or an external Param will have a value that doesn't
1918  * change during the execution of the query. In future we might want to
1919  * consider other cases too, e.g. now().
1920  */
1921  if (IsA(arg, Const))
1922  return true;
1923  if (IsA(arg, Param) &&
1924  ((Param *) arg)->paramkind == PARAM_EXTERN)
1925  return true;
1926 
1927  return false;
1928 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Definition: nodes.h:529
static void * list_nth(const List *list, int n)
Definition: pg_list.h:277
static int list_length(const List *l)
Definition: pg_list.h:169
void * arg
Definition: pg_list.h:50

◆ get_call_expr_argtype()

Oid get_call_expr_argtype ( Node expr,
int  argnum 
)

Definition at line 1823 of file fmgr.c.

References generate_unaccent_rules::args, exprType(), get_base_element_type(), InvalidOid, IsA, list_length(), and list_nth().

Referenced by get_fn_expr_argtype(), prepare_sql_fn_parse_info(), resolve_polymorphic_argtypes(), and resolve_polymorphic_tupdesc().

1824 {
1825  List *args;
1826  Oid argtype;
1827 
1828  if (expr == NULL)
1829  return InvalidOid;
1830 
1831  if (IsA(expr, FuncExpr))
1832  args = ((FuncExpr *) expr)->args;
1833  else if (IsA(expr, OpExpr))
1834  args = ((OpExpr *) expr)->args;
1835  else if (IsA(expr, DistinctExpr))
1836  args = ((DistinctExpr *) expr)->args;
1837  else if (IsA(expr, ScalarArrayOpExpr))
1838  args = ((ScalarArrayOpExpr *) expr)->args;
1839  else if (IsA(expr, NullIfExpr))
1840  args = ((NullIfExpr *) expr)->args;
1841  else if (IsA(expr, WindowFunc))
1842  args = ((WindowFunc *) expr)->args;
1843  else
1844  return InvalidOid;
1845 
1846  if (argnum < 0 || argnum >= list_length(args))
1847  return InvalidOid;
1848 
1849  argtype = exprType((Node *) list_nth(args, argnum));
1850 
1851  /*
1852  * special hack for ScalarArrayOpExpr: what the underlying function will
1853  * actually get passed is the element type of the array.
1854  */
1855  if (IsA(expr, ScalarArrayOpExpr) &&
1856  argnum == 1)
1857  argtype = get_base_element_type(argtype);
1858 
1859  return argtype;
1860 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Definition: nodes.h:529
unsigned int Oid
Definition: postgres_ext.h:31
static void * list_nth(const List *list, int n)
Definition: pg_list.h:277
#define InvalidOid
Definition: postgres_ext.h:36
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:169
Oid get_base_element_type(Oid typid)
Definition: lsyscache.c:2709
Definition: pg_list.h:50

◆ get_fn_expr_arg_stable()

bool get_fn_expr_arg_stable ( FmgrInfo flinfo,
int  argnum 
)

Definition at line 1869 of file fmgr.c.

References FmgrInfo::fn_expr, and get_call_expr_arg_stable().

Referenced by extract_variadic_args(), leadlag_common(), and window_nth_value().

1870 {
1871  /*
1872  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1873  * node has not been initialized
1874  */
1875  if (!flinfo || !flinfo->fn_expr)
1876  return false;
1877 
1878  return get_call_expr_arg_stable(flinfo->fn_expr, argnum);
1879 }
bool get_call_expr_arg_stable(Node *expr, int argnum)
Definition: fmgr.c:1888
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_expr_argtype()

Oid get_fn_expr_argtype ( FmgrInfo flinfo,
int  argnum 
)

◆ get_fn_expr_rettype()

Oid get_fn_expr_rettype ( FmgrInfo flinfo)

Definition at line 1782 of file fmgr.c.

References exprType(), FmgrInfo::fn_expr, and InvalidOid.

Referenced by do_compile(), range_constructor2(), and range_constructor3().

1783 {
1784  Node *expr;
1785 
1786  /*
1787  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1788  * node has not been initialized
1789  */
1790  if (!flinfo || !flinfo->fn_expr)
1791  return InvalidOid;
1792 
1793  expr = flinfo->fn_expr;
1794 
1795  return exprType(expr);
1796 }
Definition: nodes.h:529
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41

◆ get_fn_expr_variadic()

bool get_fn_expr_variadic ( FmgrInfo flinfo)

Definition at line 1938 of file fmgr.c.

References FmgrInfo::fn_expr, and IsA.

Referenced by concat_internal(), count_nulls(), extract_variadic_args(), satisfies_hash_partition(), and text_format().

1939 {
1940  Node *expr;
1941 
1942  /*
1943  * can't return anything useful if we have no FmgrInfo or if its fn_expr
1944  * node has not been initialized
1945  */
1946  if (!flinfo || !flinfo->fn_expr)
1947  return false;
1948 
1949  expr = flinfo->fn_expr;
1950 
1951  if (IsA(expr, FuncExpr))
1952  return ((FuncExpr *) expr)->funcvariadic;
1953  else
1954  return false;
1955 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Definition: nodes.h:529
fmNodePtr fn_expr
Definition: fmgr.h:66

◆ get_fn_opclass_options()

bytea* get_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 1991 of file fmgr.c.

References Const::constisnull, Const::consttype, Const::constvalue, DatumGetByteaP, ereport, errcode(), errmsg(), ERROR, FmgrInfo::fn_expr, and IsA.

1992 {
1993  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1994  {
1995  Const *expr = (Const *) flinfo->fn_expr;
1996 
1997  if (expr->consttype == BYTEAOID)
1998  return expr->constisnull ? NULL : DatumGetByteaP(expr->constvalue);
1999  }
2000 
2001  ereport(ERROR,
2002  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2003  errmsg("opclass options info is absent in function call context")));
2004 
2005  return NULL;
2006 }
Datum constvalue
Definition: primnodes.h:214
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
int errcode(int sqlerrcode)
Definition: elog.c:610
Oid consttype
Definition: primnodes.h:210
#define ERROR
Definition: elog.h:43
#define DatumGetByteaP(X)
Definition: fmgr.h:330
#define ereport(elevel,...)
Definition: elog.h:144
fmNodePtr fn_expr
Definition: fmgr.h:66
int errmsg(const char *fmt,...)
Definition: elog.c:824
bool constisnull
Definition: primnodes.h:215

◆ has_fn_opclass_options()

bool has_fn_opclass_options ( FmgrInfo flinfo)

Definition at line 1975 of file fmgr.c.

References Const::constisnull, Const::consttype, FmgrInfo::fn_expr, and IsA.

1976 {
1977  if (flinfo && flinfo->fn_expr && IsA(flinfo->fn_expr, Const))
1978  {
1979  Const *expr = (Const *) flinfo->fn_expr;
1980 
1981  if (expr->consttype == BYTEAOID)
1982  return !expr->constisnull;
1983  }
1984  return false;
1985 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
Oid consttype
Definition: primnodes.h:210
fmNodePtr fn_expr
Definition: fmgr.h:66
bool constisnull
Definition: primnodes.h:215

◆ InputFunctionCall()

Datum InputFunctionCall ( FmgrInfo flinfo,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1533 of file fmgr.c.

References CStringGetDatum, elog, ERROR, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, LOCAL_FCINFO, and ObjectIdGetDatum.

Referenced by BuildTupleFromCStrings(), domain_in(), hstore_populate_record(), make_tuple_from_result_row(), NextCopyFrom(), OidInputFunctionCall(), plperl_sv_to_datum(), pltcl_func_handler(), pltcl_returnnext(), pltcl_SPI_execute_plan(), PLyObject_ToScalar(), PLyString_ToComposite(), populate_scalar(), range_in(), ReadArrayStr(), record_in(), and XmlTableGetValue().

1534 {
1535  LOCAL_FCINFO(fcinfo, 3);
1536  Datum result;
1537 
1538  if (str == NULL && flinfo->fn_strict)
1539  return (Datum) 0; /* just return null result */
1540 
1541  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1542 
1543  fcinfo->args[0].value = CStringGetDatum(str);
1544  fcinfo->args[0].isnull = false;
1545  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1546  fcinfo->args[1].isnull = false;
1547  fcinfo->args[2].value = Int32GetDatum(typmod);
1548  fcinfo->args[2].isnull = false;
1549 
1550  result = FunctionCallInvoke(fcinfo);
1551 
1552  /* Should get null result if and only if str is NULL */
1553  if (str == NULL)
1554  {
1555  if (!fcinfo->isnull)
1556  elog(ERROR, "input function %u returned non-NULL",
1557  flinfo->fn_oid);
1558  }
1559  else
1560  {
1561  if (fcinfo->isnull)
1562  elog(ERROR, "input function %u returned NULL",
1563  flinfo->fn_oid);
1564  }
1565 
1566  return result;
1567 }
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
#define CStringGetDatum(X)
Definition: postgres.h:578
uintptr_t Datum
Definition: postgres.h:367
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:214

◆ Int64GetDatum()

◆ lookup_C_func()

static CFuncHashTabEntry * lookup_C_func ( HeapTuple  procedureTuple)
static

Definition at line 532 of file fmgr.c.

References CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, GETSTRUCT, HASH_FIND, hash_search(), HeapTupleHeaderGetRawXmin, ItemPointerEquals(), HeapTupleData::t_data, and HeapTupleData::t_self.

Referenced by fmgr_info_C_lang().

533 {
534  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
535  CFuncHashTabEntry *entry;
536 
537  if (CFuncHash == NULL)
538  return NULL; /* no table yet */
539  entry = (CFuncHashTabEntry *)
541  &fn_oid,
542  HASH_FIND,
543  NULL);
544  if (entry == NULL)
545  return NULL; /* no such entry */
546  if (entry->fn_xmin == HeapTupleHeaderGetRawXmin(procedureTuple->t_data) &&
547  ItemPointerEquals(&entry->fn_tid, &procedureTuple->t_self))
548  return entry; /* OK */
549  return NULL; /* entry is out of date */
550 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:927
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
static HTAB * CFuncHash
Definition: fmgr.c:54
ItemPointerData t_self
Definition: htup.h:65
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:308
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
TransactionId fn_xmin
Definition: fmgr.c:48
ItemPointerData fn_tid
Definition: fmgr.c:49

◆ OidFunctionCall0Coll()

Datum OidFunctionCall0Coll ( Oid  functionId,
Oid  collation 
)

Definition at line 1404 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall0Coll().

1405 {
1406  FmgrInfo flinfo;
1407 
1408  fmgr_info(functionId, &flinfo);
1409 
1410  return FunctionCall0Coll(&flinfo, collation);
1411 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall0Coll(FmgrInfo *flinfo, Oid collation)
Definition: fmgr.c:1115

◆ OidFunctionCall1Coll()

Datum OidFunctionCall1Coll ( Oid  functionId,
Oid  collation,
Datum  arg1 
)

Definition at line 1414 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall1Coll().

Referenced by _bt_allequalimage(), and _hash_datum2hashkey_type().

1415 {
1416  FmgrInfo flinfo;
1417 
1418  fmgr_info(functionId, &flinfo);
1419 
1420  return FunctionCall1Coll(&flinfo, collation, arg1);
1421 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1132

◆ OidFunctionCall2Coll()

Datum OidFunctionCall2Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2 
)

Definition at line 1424 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall2Coll().

Referenced by _bt_compare_scankey_args(), and index_recheck_constraint().

1425 {
1426  FmgrInfo flinfo;
1427 
1428  fmgr_info(functionId, &flinfo);
1429 
1430  return FunctionCall2Coll(&flinfo, collation, arg1, arg2);
1431 }
Definition: fmgr.h:56
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Definition: fmgr.c:1152
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall3Coll()

Datum OidFunctionCall3Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3 
)

Definition at line 1434 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall3Coll().

1436 {
1437  FmgrInfo flinfo;
1438 
1439  fmgr_info(functionId, &flinfo);
1440 
1441  return FunctionCall3Coll(&flinfo, collation, arg1, arg2, arg3);
1442 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall3Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3)
Definition: fmgr.c:1174

◆ OidFunctionCall4Coll()

Datum OidFunctionCall4Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4 
)

Definition at line 1445 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall4Coll().

Referenced by restriction_selectivity().

1447 {
1448  FmgrInfo flinfo;
1449 
1450  fmgr_info(functionId, &flinfo);
1451 
1452  return FunctionCall4Coll(&flinfo, collation, arg1, arg2, arg3, arg4);
1453 }
Definition: fmgr.h:56
Datum FunctionCall4Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1199
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall5Coll()

Datum OidFunctionCall5Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5 
)

Definition at line 1456 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall5Coll().

Referenced by join_selectivity().

1458 {
1459  FmgrInfo flinfo;
1460 
1461  fmgr_info(functionId, &flinfo);
1462 
1463  return FunctionCall5Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5);
1464 }
Definition: fmgr.h:56
Datum FunctionCall5Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1226
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall6Coll()

Datum OidFunctionCall6Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6 
)

Definition at line 1467 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall6Coll().

1470 {
1471  FmgrInfo flinfo;
1472 
1473  fmgr_info(functionId, &flinfo);
1474 
1475  return FunctionCall6Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1476  arg6);
1477 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum FunctionCall6Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6)
Definition: fmgr.c:1255

◆ OidFunctionCall7Coll()

Datum OidFunctionCall7Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7 
)

Definition at line 1480 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall7Coll().

1483 {
1484  FmgrInfo flinfo;
1485 
1486  fmgr_info(functionId, &flinfo);
1487 
1488  return FunctionCall7Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1489  arg6, arg7);
1490 }
Definition: fmgr.h:56
Datum FunctionCall7Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7)
Definition: fmgr.c:1287
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall8Coll()

Datum OidFunctionCall8Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8 
)

Definition at line 1493 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall8Coll().

1496 {
1497  FmgrInfo flinfo;
1498 
1499  fmgr_info(functionId, &flinfo);
1500 
1501  return FunctionCall8Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1502  arg6, arg7, arg8);
1503 }
Definition: fmgr.h:56
Datum FunctionCall8Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8)
Definition: fmgr.c:1321
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidFunctionCall9Coll()

Datum OidFunctionCall9Coll ( Oid  functionId,
Oid  collation,
Datum  arg1,
Datum  arg2,
Datum  arg3,
Datum  arg4,
Datum  arg5,
Datum  arg6,
Datum  arg7,
Datum  arg8,
Datum  arg9 
)

Definition at line 1506 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and FunctionCall9Coll().

1510 {
1511  FmgrInfo flinfo;
1512 
1513  fmgr_info(functionId, &flinfo);
1514 
1515  return FunctionCall9Coll(&flinfo, collation, arg1, arg2, arg3, arg4, arg5,
1516  arg6, arg7, arg8, arg9);
1517 }
Definition: fmgr.h:56
Datum FunctionCall9Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5, Datum arg6, Datum arg7, Datum arg8, Datum arg9)
Definition: fmgr.c:1357
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidInputFunctionCall()

Datum OidInputFunctionCall ( Oid  functionId,
char *  str,
Oid  typioparam,
int32  typmod 
)

Definition at line 1648 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and InputFunctionCall().

Referenced by DefineAggregate(), exec_bind_message(), get_typdefault(), GetAggInitVal(), InsertOneValue(), parse_fcall_arguments(), slot_modify_data(), slot_store_data(), and stringTypeDatum().

1649 {
1650  FmgrInfo flinfo;
1651 
1652  fmgr_info(functionId, &flinfo);
1653  return InputFunctionCall(&flinfo, str, typioparam, typmod);
1654 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Definition: fmgr.c:1533

◆ OidOutputFunctionCall()

◆ OidReceiveFunctionCall()

Datum OidReceiveFunctionCall ( Oid  functionId,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1666 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and ReceiveFunctionCall().

Referenced by exec_bind_message(), parse_fcall_arguments(), parse_fcall_arguments_20(), slot_modify_data(), and slot_store_data().

1668 {
1669  FmgrInfo flinfo;
1670 
1671  fmgr_info(functionId, &flinfo);
1672  return ReceiveFunctionCall(&flinfo, buf, typioparam, typmod);
1673 }
Definition: fmgr.h:56
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
Definition: fmgr.c:1591
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126

◆ OidSendFunctionCall()

bytea* OidSendFunctionCall ( Oid  functionId,
Datum  val 
)

Definition at line 1676 of file fmgr.c.

References fmgr_security_definer_cache::flinfo, fmgr_info(), and SendFunctionCall().

Referenced by logicalrep_write_tuple(), and SendFunctionResult().

1677 {
1678  FmgrInfo flinfo;
1679 
1680  fmgr_info(functionId, &flinfo);
1681  return SendFunctionCall(&flinfo, val);
1682 }
Definition: fmgr.h:56
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Definition: fmgr.c:1638
long val
Definition: informix.c:664

◆ OutputFunctionCall()

◆ pg_detoast_datum()

struct varlena* pg_detoast_datum ( struct varlena datum)

Definition at line 1726 of file fmgr.c.

References detoast_attr(), and VARATT_IS_EXTENDED.

1727 {
1728  if (VARATT_IS_EXTENDED(datum))
1729  return detoast_attr(datum);
1730  else
1731  return datum;
1732 }
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:115
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:327

◆ pg_detoast_datum_copy()

struct varlena* pg_detoast_datum_copy ( struct varlena datum)

Definition at line 1735 of file fmgr.c.

References detoast_attr(), palloc(), VARATT_IS_EXTENDED, and VARSIZE.

1736 {
1737  if (VARATT_IS_EXTENDED(datum))
1738  return detoast_attr(datum);
1739  else
1740  {
1741  /* Make a modifiable copy of the varlena object */
1742  Size len = VARSIZE(datum);
1743  struct varlena *result = (struct varlena *) palloc(len);
1744 
1745  memcpy(result, datum, len);
1746  return result;
1747  }
1748 }
#define VARSIZE(PTR)
Definition: postgres.h:303
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:115
size_t Size
Definition: c.h:473
#define VARATT_IS_EXTENDED(PTR)
Definition: postgres.h:327
void * palloc(Size size)
Definition: mcxt.c:949
Definition: c.h:562

◆ pg_detoast_datum_packed()

struct varlena* pg_detoast_datum_packed ( struct varlena datum)

Definition at line 1758 of file fmgr.c.

References detoast_attr(), VARATT_IS_COMPRESSED, and VARATT_IS_EXTERNAL.

Referenced by text_to_cstring(), and text_to_cstring_buffer().

1759 {
1760  if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum))
1761  return detoast_attr(datum);
1762  else
1763  return datum;
1764 }
#define VARATT_IS_COMPRESSED(PTR)
Definition: postgres.h:312
#define VARATT_IS_EXTERNAL(PTR)
Definition: postgres.h:313
struct varlena * detoast_attr(struct varlena *attr)
Definition: detoast.c:115

◆ pg_detoast_datum_slice()

struct varlena* pg_detoast_datum_slice ( struct varlena datum,
int32  first,
int32  count 
)

Definition at line 1751 of file fmgr.c.

References detoast_attr_slice().

1752 {
1753  /* Only get the specified portion from the toast rel */
1754  return detoast_attr_slice(datum, first, count);
1755 }
struct varlena * detoast_attr_slice(struct varlena *attr, int32 sliceoffset, int32 slicelength)
Definition: detoast.c:203

◆ ReceiveFunctionCall()

Datum ReceiveFunctionCall ( FmgrInfo flinfo,
StringInfo  buf,
Oid  typioparam,
int32  typmod 
)

Definition at line 1591 of file fmgr.c.

References elog, ERROR, FmgrInfo::fn_oid, FmgrInfo::fn_strict, FunctionCallInvoke, InitFunctionCallInfoData, Int32GetDatum, InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum, and PointerGetDatum.

Referenced by CopyReadBinaryAttribute(), domain_recv(), OidReceiveFunctionCall(), range_recv(), ReadArrayBinary(), and record_recv().

1593 {
1594  LOCAL_FCINFO(fcinfo, 3);
1595  Datum result;
1596 
1597  if (buf == NULL && flinfo->fn_strict)
1598  return (Datum) 0; /* just return null result */
1599 
1600  InitFunctionCallInfoData(*fcinfo, flinfo, 3, InvalidOid, NULL, NULL);
1601 
1602  fcinfo->args[0].value = PointerGetDatum(buf);
1603  fcinfo->args[0].isnull = false;
1604  fcinfo->args[1].value = ObjectIdGetDatum(typioparam);
1605  fcinfo->args[1].isnull = false;
1606  fcinfo->args[2].value = Int32GetDatum(typmod);
1607  fcinfo->args[2].isnull = false;
1608 
1609  result = FunctionCallInvoke(fcinfo);
1610 
1611  /* Should get null result if and only if buf is NULL */
1612  if (buf == NULL)
1613  {
1614  if (!fcinfo->isnull)
1615  elog(ERROR, "receive function %u returned non-NULL",
1616  flinfo->fn_oid);
1617  }
1618  else
1619  {
1620  if (fcinfo->isnull)
1621  elog(ERROR, "receive function %u returned NULL",
1622  flinfo->fn_oid);
1623  }
1624 
1625  return result;
1626 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool fn_strict
Definition: fmgr.h:61
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
uintptr_t Datum
Definition: postgres.h:367
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:214

◆ record_C_func()

static void record_C_func ( HeapTuple  procedureTuple,
PGFunction  user_fn,
const Pg_finfo_record inforec 
)
static

Definition at line 556 of file fmgr.c.

References HASHCTL::entrysize, CFuncHashTabEntry::fn_tid, CFuncHashTabEntry::fn_xmin, GETSTRUCT, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HeapTupleHeaderGetRawXmin, CFuncHashTabEntry::inforec, HASHCTL::keysize, MemSet, HeapTupleData::t_data, HeapTupleData::t_self, and CFuncHashTabEntry::user_fn.

Referenced by fmgr_info_C_lang().

558 {
559  Oid fn_oid = ((Form_pg_proc) GETSTRUCT(procedureTuple))->oid;
560  CFuncHashTabEntry *entry;
561  bool found;
562 
563  /* Create the hash table if it doesn't exist yet */
564  if (CFuncHash == NULL)
565  {
566  HASHCTL hash_ctl;
567 
568  MemSet(&hash_ctl, 0, sizeof(hash_ctl));
569  hash_ctl.keysize = sizeof(Oid);
570  hash_ctl.entrysize = sizeof(CFuncHashTabEntry);
571  CFuncHash = hash_create("CFuncHash",
572  100,
573  &hash_ctl,
575  }
576 
577  entry = (CFuncHashTabEntry *)
579  &fn_oid,
580  HASH_ENTER,
581  &found);
582  /* OID is already filled in */
583  entry->fn_xmin = HeapTupleHeaderGetRawXmin(procedureTuple->t_data);
584  entry->fn_tid = procedureTuple->t_self;
585  entry->user_fn = user_fn;
586  entry->inforec = inforec;
587 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define HASH_ELEM
Definition: hsearch.h:87
const Pg_finfo_record * inforec
Definition: fmgr.c:51
Size entrysize
Definition: hsearch.h:73
#define MemSet(start, val, len)
Definition: c.h:949
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:927
unsigned int Oid
Definition: postgres_ext.h:31
HeapTupleHeader t_data
Definition: htup.h:68
static HTAB * CFuncHash
Definition: fmgr.c:54
ItemPointerData t_self
Definition: htup.h:65
PGFunction user_fn
Definition: fmgr.c:50
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:328
Size keysize
Definition: hsearch.h:72
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleHeaderGetRawXmin(tup)
Definition: htup_details.h:308
TransactionId fn_xmin
Definition: fmgr.c:48
ItemPointerData fn_tid
Definition: fmgr.c:49

◆ SendFunctionCall()

bytea* SendFunctionCall ( FmgrInfo flinfo,
Datum  val 
)

Definition at line 1638 of file fmgr.c.

References DatumGetByteaP, and FunctionCall1.

Referenced by array_send(), CopyOneRowTo(), OidSendFunctionCall(), printtup(), printtup_internal_20(), range_send(), and record_send().

1639 {
1640  return DatumGetByteaP(FunctionCall1(flinfo, val));
1641 }
#define DatumGetByteaP(X)
Definition: fmgr.h:330
#define FunctionCall1(flinfo, arg1)
Definition: fmgr.h:642
long val
Definition: informix.c:664

◆ set_fn_opclass_options()

void set_fn_opclass_options ( FmgrInfo flinfo,
bytea options 
)

Definition at line 1964 of file fmgr.c.

References FmgrInfo::fn_expr, InvalidOid, makeConst(), and PointerGetDatum.

Referenced by gincost_pattern(), and index_getprocinfo().

1965 {
1966  flinfo->fn_expr = (Node *) makeConst(BYTEAOID, -1, InvalidOid, -1,
1967  PointerGetDatum(options),
1968  options == NULL, false);
1969 }
#define PointerGetDatum(X)
Definition: postgres.h:556
Definition: nodes.h:529
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:299
#define InvalidOid
Definition: postgres_ext.h:36
fmNodePtr fn_expr
Definition: fmgr.h:66

Variable Documentation

◆ CFuncHash

HTAB* CFuncHash = NULL
static

Definition at line 54 of file fmgr.c.

◆ fmgr_hook

PGDLLIMPORT fmgr_hook_type fmgr_hook = NULL

Definition at line 39 of file fmgr.c.

Referenced by fmgr_security_definer(), and sepgsql_init_client_label().

◆ needs_fmgr_hook

PGDLLIMPORT needs_fmgr_hook_type needs_fmgr_hook = NULL

Definition at line 38 of file fmgr.c.

Referenced by sepgsql_init_client_label().