]> granicus.if.org Git - postgresql/blob - src/backend/nodes/nodeFuncs.c
Massive commit to run PGINDENT on all *.c and *.h files.
[postgresql] / src / backend / nodes / nodeFuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * nodeFuncs.c--
4  *        All node routines more complicated than simple access/modification
5  *
6  * Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  *        $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.4 1997/09/07 04:42:49 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14
15 #include <sys/types.h>
16
17 #include "postgres.h"
18
19 #include "nodes/primnodes.h"
20 #include "nodes/plannodes.h"
21 #include "nodes/pg_list.h"
22 #include "nodes/relation.h"
23 #include "nodes/nodeFuncs.h"
24 #include "utils/lsyscache.h"
25
26 static bool             var_is_inner(Var * var);
27
28 /*
29  * single_node -
30  *        Returns t if node corresponds to a single-noded expression
31  */
32 bool
33 single_node(Node * node)
34 {
35         if (IsA(node, Ident) || IsA(node, Const) || IsA(node, Var) || IsA(node, Param))
36                 return (true);
37         else
38                 return (false);
39 }
40
41 /*****************************************************************************
42  *              VAR nodes
43  *****************************************************************************/
44
45 /*
46  *              var_is_outer
47  *              var_is_inner
48  *              var_is_mat
49  *              var_is_rel
50  *
51  *              Returns t iff the var node corresponds to (respectively):
52  *              the outer relation in a join
53  *              the inner relation of a join
54  *              a materialized relation
55  *              a base relation (i.e., not an attribute reference, a variable from
56  *                              some lower join level, or a sort result)
57  *              var node is an array reference
58  *
59  */
60 bool
61 var_is_outer(Var * var)
62 {
63         return ((bool) (var->varno == OUTER));
64 }
65
66 static                  bool
67 var_is_inner(Var * var)
68 {
69         return ((bool) (var->varno == INNER));
70 }
71
72 bool
73 var_is_rel(Var * var)
74 {
75         return (bool)
76                 ! (var_is_inner(var) || var_is_outer(var));
77 }
78
79 /*****************************************************************************
80  *              OPER nodes
81  *****************************************************************************/
82
83 /*
84  * replace_opid -
85  *
86  *              Given a oper node, resets the opfid field with the
87  *              procedure OID (regproc id).
88  *
89  *              Returns the modified oper node.
90  *
91  */
92 Oper               *
93 replace_opid(Oper * oper)
94 {
95         oper->opid = get_opcode(oper->opno);
96         oper->op_fcache = NULL;
97         return (oper);
98 }
99
100 /*****************************************************************************
101  *              constant (CONST, PARAM) nodes
102  *****************************************************************************/
103
104 /*
105  * non_null -
106  *              Returns t if the node is a non-null constant, e.g., if the node has a
107  *              valid `constvalue' field.
108  *
109  */
110 bool
111 non_null(Expr * c)
112 {
113
114         if (IsA(c, Const) && !((Const *) c)->constisnull)
115                 return (true);
116         else
117                 return (false);
118 }