summaryrefslogtreecommitdiff
path: root/src/backend/nodes/nodeFuncs.c
blob: 42dd9a2dab8e529711e4b1d2bb95e2e0532452d1 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*-------------------------------------------------------------------------
 *
 * nodeFuncs.c
 *	  All node routines more complicated than simple access/modification
 *
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.14 2001/03/22 03:59:32 momjian Exp $
 *
 *-------------------------------------------------------------------------
 */

#include <sys/types.h>

#include "postgres.h"

#include "nodes/nodeFuncs.h"
#include "utils/lsyscache.h"

static bool var_is_inner(Var *var);

/*
 * single_node -
 *	  Returns t if node corresponds to a single-noded expression
 */
bool
single_node(Node *node)
{
	if (IsA(node, Ident) ||IsA(node, Const) ||IsA(node, Var) ||IsA(node, Param))
		return true;
	else
		return false;
}

/*****************************************************************************
 *		VAR nodes
 *****************************************************************************/

/*
 *		var_is_outer
 *		var_is_inner
 *		var_is_mat
 *		var_is_rel
 *
 *		Returns t iff the var node corresponds to (respectively):
 *		the outer relation in a join
 *		the inner relation of a join
 *		a materialized relation
 *		a base relation (i.e., not an attribute reference, a variable from
 *				some lower join level, or a sort result)
 *		var node is an array reference
 *
 */
bool
var_is_outer(Var *var)
{
	return (bool) (var->varno == OUTER);
}

static bool
var_is_inner(Var *var)
{
	return (bool) (var->varno == INNER);
}

bool
var_is_rel(Var *var)
{
	return (bool)
	!(var_is_inner(var) || var_is_outer(var));
}

/*****************************************************************************
 *		OPER nodes
 *****************************************************************************/

/*
 * replace_opid -
 *
 *		Given a oper node, resets the opfid field with the
 *		procedure OID (regproc id).
 *
 *		Returns the modified oper node.
 *
 */
Oper *
replace_opid(Oper *oper)
{
	oper->opid = get_opcode(oper->opno);
	oper->op_fcache = NULL;
	return oper;
}

/*****************************************************************************
 *		constant (CONST, PARAM) nodes
 *****************************************************************************/

#ifdef NOT_USED
/*
 * non_null -
 *		Returns t if the node is a non-null constant, e.g., if the node has a
 *		valid `constvalue' field.
 *
 */
bool
non_null(Expr *c)
{

	if (IsA(c, Const) &&!((Const *) c)->constisnull)
		return true;
	else
		return false;
}

#endif