PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
funccache.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * funccache.h
4 * Function cache definitions.
5 *
6 * See funccache.c for comments.
7 *
8 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
10 *
11 * src/include/utils/funccache.h
12 *
13 *-------------------------------------------------------------------------
14 */
15#ifndef FUNCCACHE_H
16#define FUNCCACHE_H
17
18#include "access/htup_details.h"
19#include "fmgr.h"
20#include "storage/itemptr.h"
21
22struct CachedFunctionHashKey; /* forward references */
23struct CachedFunction;
24
25/*
26 * Callback that cached_function_compile() invokes when it's necessary to
27 * compile a cached function. The callback must fill in *function (except
28 * for the fields of struct CachedFunction), or throw an error if trouble.
29 * fcinfo: current call information
30 * procTup: function's pg_proc row from catcache
31 * hashkey: hash key that will be used for the function
32 * function: pre-zeroed workspace, of size passed to cached_function_compile()
33 * forValidator: passed through from cached_function_compile()
34 */
36 HeapTuple procTup,
37 const struct CachedFunctionHashKey *hashkey,
39 bool forValidator);
40
41/*
42 * Callback called when discarding a cache entry. Free any free-able
43 * subsidiary data of cfunc, but not the struct CachedFunction itself.
44 */
45typedef void (*CachedFunctionDeleteCallback) (struct CachedFunction *cfunc);
46
47/*
48 * Hash lookup key for functions. This must account for all aspects
49 * of a specific call that might lead to different data types or
50 * collations being used within the function.
51 */
53{
55
56 bool isTrigger; /* true if called as a DML trigger */
57 bool isEventTrigger; /* true if called as an event trigger */
58
59 /* be careful that pad bytes in this struct get zeroed! */
60
61 /*
62 * We include the language-specific size of the function's cache entry in
63 * the cache key. This covers the case where CREATE OR REPLACE FUNCTION
64 * is used to change the implementation language, and the new language
65 * also uses funccache.c but needs a different-sized cache entry.
66 */
68
69 /*
70 * For a trigger function, the OID of the trigger is part of the hash key
71 * --- we want to compile the trigger function separately for each trigger
72 * it is used with, in case the rowtype or transition table names are
73 * different. Zero if not called as a DML trigger.
74 */
76
77 /*
78 * We must include the input collation as part of the hash key too,
79 * because we have to generate different plans (with different Param
80 * collations) for different collation settings.
81 */
83
84 /* Number of arguments (counting input arguments only, ie pronargs) */
85 int nargs;
86
87 /* If you change anything below here, fix hashing code in funccache.c! */
88
89 /*
90 * If relevant, the result descriptor for a function returning composite.
91 */
93
94 /*
95 * Input argument types, with any polymorphic types resolved to actual
96 * types. Only the first nargs entries are valid.
97 */
100
101/*
102 * Representation of a compiled function. This struct contains just the
103 * fields that funccache.c needs to deal with. It will typically be
104 * embedded in a larger struct containing function-language-specific data.
105 */
106typedef struct CachedFunction
107{
108 /* back-link to hashtable entry, or NULL if not in hash table */
110 /* xmin and ctid of function's pg_proc row; used to detect invalidation */
113 /* deletion callback */
115
116 /* this field changes when the function is used: */
119
124 Size cacheEntrySize,
125 bool includeResultType,
126 bool forValidator);
127extern void cfunc_resolve_polymorphic_argtypes(int numargs,
128 Oid *argtypes,
129 char *argmodes,
130 Node *call_expr,
131 bool forValidator,
132 const char *proname);
133
134#endif /* FUNCCACHE_H */
uint64_t uint64
Definition: c.h:503
uint32 TransactionId
Definition: c.h:623
size_t Size
Definition: c.h:576
void(* CachedFunctionCompileCallback)(FunctionCallInfo fcinfo, HeapTuple procTup, const struct CachedFunctionHashKey *hashkey, struct CachedFunction *function, bool forValidator)
Definition: funccache.h:35
void(* CachedFunctionDeleteCallback)(struct CachedFunction *cfunc)
Definition: funccache.h:45
struct CachedFunction CachedFunction
void cfunc_resolve_polymorphic_argtypes(int numargs, Oid *argtypes, char *argmodes, Node *call_expr, bool forValidator, const char *proname)
Definition: funccache.c:348
CachedFunction * cached_function_compile(FunctionCallInfo fcinfo, CachedFunction *function, CachedFunctionCompileCallback ccallback, CachedFunctionDeleteCallback dcallback, Size cacheEntrySize, bool includeResultType, bool forValidator)
Definition: funccache.c:480
struct CachedFunctionHashKey CachedFunctionHashKey
on_exit_nicely_callback function
#define FUNC_MAX_ARGS
NameData proname
Definition: pg_proc.h:35
unsigned int Oid
Definition: postgres_ext.h:30
TupleDesc callResultType
Definition: funccache.h:92
Oid argtypes[FUNC_MAX_ARGS]
Definition: funccache.h:98
TransactionId fn_xmin
Definition: funccache.h:111
CachedFunctionDeleteCallback dcallback
Definition: funccache.h:114
uint64 use_count
Definition: funccache.h:117
ItemPointerData fn_tid
Definition: funccache.h:112
CachedFunctionHashKey * fn_hashkey
Definition: funccache.h:109
Definition: nodes.h:135