47#define FUNCS_PER_USER 128
50static int cfunc_match(
const void *key1,
const void *key2,
Size keysize);
181 elog(
WARNING,
"trying to insert a function that already exists");
222 tupdesc =
function->fn_hashkey->callResultType;
229 elog(
WARNING,
"trying to delete function that does not exist");
251 bool includeResultType,
295 if (procStruct->pronargs > 0)
297 hashkey->
nargs = procStruct->pronargs;
298 memcpy(hashkey->
argtypes, procStruct->proargtypes.values,
299 procStruct->pronargs *
sizeof(
Oid));
317 if (includeResultType)
349 Oid *argtypes,
char *argmodes,
350 Node *call_expr,
bool forValidator,
363 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
364 errmsg(
"could not determine actual argument "
365 "type for polymorphic function \"%s\"",
369 for (
i = 0;
i < numargs;
i++)
371 char argmode = argmodes ? argmodes[
i] : PROARGMODE_IN;
373 if (argmode == PROARGMODE_OUT || argmode == PROARGMODE_TABLE)
375 if (argtypes[
i] == RECORDOID || argtypes[
i] == RECORDARRAYOID)
381 argtypes[
i] = resolvedtype;
389 for (
i = 0;
i < numargs;
i++)
396 case ANYCOMPATIBLEOID:
397 case ANYCOMPATIBLENONARRAYOID:
398 argtypes[
i] = INT4OID;
401 case ANYCOMPATIBLEARRAYOID:
402 argtypes[
i] = INT4ARRAYOID;
405 case ANYCOMPATIBLERANGEOID:
406 argtypes[
i] = INT4RANGEOID;
408 case ANYMULTIRANGEOID:
409 argtypes[
i] = INT4MULTIRANGEOID;
485 bool includeResultType,
492 bool function_valid =
false;
493 bool hashkey_valid =
false;
500 elog(
ERROR,
"cache lookup failed for function %u", funcOid);
512 cacheEntrySize, includeResultType,
514 hashkey_valid =
true;
525 function_valid =
true;
568 cacheEntrySize, includeResultType,
584 memset(
function, 0, cacheEntrySize);
598 ccallback(fcinfo, procTup, &hashkey,
function, forValidator);
#define OidIsValid(objectId)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define CALLED_AS_EVENT_TRIGGER(fcinfo)
Oid get_call_expr_argtype(Node *expr, int argnum)
bool resolve_polymorphic_argtypes(int numargs, Oid *argtypes, char *argmodes, Node *call_expr)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
static void compute_function_hashkey(FunctionCallInfo fcinfo, Form_pg_proc procStruct, CachedFunctionHashKey *hashkey, Size cacheEntrySize, bool includeResultType, bool forValidator)
static void cfunc_hashtable_init(void)
static uint32 cfunc_hash(const void *key, Size keysize)
static HTAB * cfunc_hashtable
static void cfunc_hashtable_insert(CachedFunction *function, CachedFunctionHashKey *func_key)
static int cfunc_match(const void *key1, const void *key2, Size keysize)
struct CachedFunctionHashEntry CachedFunctionHashEntry
void cfunc_resolve_polymorphic_argtypes(int numargs, Oid *argtypes, char *argmodes, Node *call_expr, bool forValidator, const char *proname)
CachedFunction * cached_function_compile(FunctionCallInfo fcinfo, CachedFunction *function, CachedFunctionCompileCallback ccallback, CachedFunctionDeleteCallback dcallback, Size cacheEntrySize, bool includeResultType, bool forValidator)
static CachedFunction * cfunc_hashtable_lookup(CachedFunctionHashKey *func_key)
static void cfunc_hashtable_delete(CachedFunction *function)
static void delete_function(CachedFunction *func)
void(* CachedFunctionCompileCallback)(FunctionCallInfo fcinfo, HeapTuple procTup, const struct CachedFunctionHashKey *hashkey, struct CachedFunction *function, bool forValidator)
void(* CachedFunctionDeleteCallback)(struct CachedFunction *cfunc)
struct CachedFunctionHashKey CachedFunctionHashKey
static uint32 hash_combine(uint32 a, uint32 b)
static Datum hash_any(const unsigned char *k, int keylen)
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
static TransactionId HeapTupleHeaderGetRawXmin(const HeapTupleHeaderData *tup)
static void * GETSTRUCT(const HeapTupleData *tuple)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext TopMemoryContext
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
on_exit_nicely_callback function
FormData_pg_proc * Form_pg_proc
static uint32 DatumGetUInt32(Datum X)
static Datum ObjectIdGetDatum(Oid X)
CachedFunctionHashKey key
CachedFunction * function
Oid argtypes[FUNC_MAX_ARGS]
CachedFunctionDeleteCallback dcallback
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define CALLED_AS_TRIGGER(fcinfo)
void FreeTupleDesc(TupleDesc tupdesc)
uint32 hashRowType(TupleDesc desc)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
bool equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)