aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/fcache.h
blob: bb081a04748d0154d7ee3d543ee318d899fd7038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*-------------------------------------------------------------------------
 *
 * fcache.h
 *		Declarations for function cache records.
 *
 * The first time any Oper or Func node is evaluated, we compute a cache
 * record for the function being invoked, and save a pointer to the cache
 * record in the Oper or Func node.  This saves repeated lookup of info
 * about the function.
 *
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $Id: fcache.h,v 1.16 2001/03/22 04:01:12 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */
#ifndef FCACHE_H
#define FCACHE_H

#include "fmgr.h"
#include "nodes/execnodes.h"

/*
 * A FunctionCache record is built for all functions regardless of language.
 *
 * We store the fmgr lookup info to avoid recomputing it on each call.
 * We also store a prebuilt FunctionCallInfo struct.  When evaluating a
 * function-returning-set, fcinfo holds the argument values across calls
 * so that we need not re-evaluate the arguments for each call.  Even for
 * non-set functions, fcinfo saves a few cycles per call by allowing us to
 * avoid redundant setup of its fields.
 */

typedef struct FunctionCache
{

	/*
	 * Function manager's lookup info for the target function.
	 */
	FmgrInfo	func;

	/*
	 * Per-call info for calling the target function.  Unvarying fields
	 * are set up by init_fcache().  Argument values are filled in as
	 * needed.
	 */
	FunctionCallInfoData fcinfo;

	/*
	 * "Resultinfo" node --- used only if target function returns a set.
	 */
	ReturnSetInfo rsinfo;

	/*
	 * argsValid is true when we are evaluating a set-valued function and
	 * we are in the middle of a call series; we want to pass the same
	 * argument values to the function again (and again, until it returns
	 * ExprEndResult).
	 */
	bool		argsValid;		/* TRUE if fcinfo contains valid arguments */

	/*
	 * hasSetArg is true if we found a set-valued argument to the
	 * function. This causes the function result to be a set as well.
	 */
	bool		hasSetArg;		/* some argument returns a set */
} FunctionCache;


extern FunctionCachePtr init_fcache(Oid foid, int nargs,
			MemoryContext fcacheCxt);

#endif	 /* FCACHE_H */