1996-07-09 06:22:35 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-13 23:22:53 +00:00
|
|
|
* nodeFuncs.c
|
1997-09-07 05:04:48 +00:00
|
|
|
* All node routines more complicated than simple access/modification
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1999-07-15 22:40:16 +00:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.10 1999/07/15 22:39:17 momjian Exp $
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1996-10-31 10:42:56 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
#include <sys/types.h>
|
1996-10-31 10:42:56 +00:00
|
|
|
|
|
|
|
#include "postgres.h"
|
1996-07-09 06:22:35 +00:00
|
|
|
|
|
|
|
#include "nodes/nodeFuncs.h"
|
|
|
|
#include "utils/lsyscache.h"
|
|
|
|
|
1997-09-08 21:56:23 +00:00
|
|
|
static bool var_is_inner(Var *var);
|
1997-08-19 21:40:56 +00:00
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
/*
|
1996-07-09 06:22:35 +00:00
|
|
|
* single_node -
|
1997-09-07 05:04:48 +00:00
|
|
|
* Returns t if node corresponds to a single-noded expression
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
|
|
|
bool
|
1997-09-08 21:56:23 +00:00
|
|
|
single_node(Node *node)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-08 21:56:23 +00:00
|
|
|
if (IsA(node, Ident) ||IsA(node, Const) ||IsA(node, Var) ||IsA(node, Param))
|
1998-09-01 03:29:17 +00:00
|
|
|
return true;
|
1997-09-07 05:04:48 +00:00
|
|
|
else
|
1998-09-01 03:29:17 +00:00
|
|
|
return false;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 05:04:48 +00:00
|
|
|
* VAR nodes
|
1996-07-09 06:22:35 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
|
|
|
bool
|
1997-09-08 21:56:23 +00:00
|
|
|
var_is_outer(Var *var)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1998-09-01 03:29:17 +00:00
|
|
|
return (bool) (var->varno == OUTER);
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
1997-09-08 02:41:22 +00:00
|
|
|
static bool
|
1997-09-08 21:56:23 +00:00
|
|
|
var_is_inner(Var *var)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1998-09-01 03:29:17 +00:00
|
|
|
return (bool) (var->varno == INNER);
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
1997-09-08 21:56:23 +00:00
|
|
|
var_is_rel(Var *var)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-07 05:04:48 +00:00
|
|
|
return (bool)
|
1997-09-08 21:56:23 +00:00
|
|
|
!(var_is_inner(var) || var_is_outer(var));
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 05:04:48 +00:00
|
|
|
* OPER nodes
|
1996-07-09 06:22:35 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
/*
|
1996-07-09 06:22:35 +00:00
|
|
|
* replace_opid -
|
1997-09-07 05:04:48 +00:00
|
|
|
*
|
|
|
|
* Given a oper node, resets the opfid field with the
|
|
|
|
* procedure OID (regproc id).
|
|
|
|
*
|
|
|
|
* Returns the modified oper node.
|
|
|
|
*
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
1998-02-26 04:46:47 +00:00
|
|
|
Oper *
|
1997-09-08 21:56:23 +00:00
|
|
|
replace_opid(Oper *oper)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
1997-09-07 05:04:48 +00:00
|
|
|
oper->opid = get_opcode(oper->opno);
|
|
|
|
oper->op_fcache = NULL;
|
1998-09-01 03:29:17 +00:00
|
|
|
return oper;
|
1996-07-09 06:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1997-09-07 05:04:48 +00:00
|
|
|
* constant (CONST, PARAM) nodes
|
1996-07-09 06:22:35 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-07 05:04:48 +00:00
|
|
|
/*
|
1996-07-09 06:22:35 +00:00
|
|
|
* non_null -
|
1997-09-07 05:04:48 +00:00
|
|
|
* Returns t if the node is a non-null constant, e.g., if the node has a
|
|
|
|
* valid `constvalue' field.
|
|
|
|
*
|
1996-07-09 06:22:35 +00:00
|
|
|
*/
|
|
|
|
bool
|
1997-09-08 21:56:23 +00:00
|
|
|
non_null(Expr *c)
|
1996-07-09 06:22:35 +00:00
|
|
|
{
|
|
|
|
|
1997-09-08 21:56:23 +00:00
|
|
|
if (IsA(c, Const) &&!((Const *) c)->constisnull)
|
1998-09-01 03:29:17 +00:00
|
|
|
return true;
|
1997-09-07 05:04:48 +00:00
|
|
|
else
|
1998-09-01 03:29:17 +00:00
|
|
|
return false;
|
1997-09-07 05:04:48 +00:00
|
|
|
}
|