Commit a0bf885f authored by Tom Lane's avatar Tom Lane

Phase 2 of read-only-plans project: restructure expression-tree nodes

so that all executable expression nodes inherit from a common supertype
Expr.  This is somewhat of an exercise in code purity rather than any
real functional advance, but getting rid of the extra Oper or Func node
formerly used in each operator or function call should provide at least
a little space and speed improvement.
initdb forced by changes in stored-rules representation.
parent debb0728
......@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.17 2002/12/06 05:00:10 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.18 2002/12/12 15:49:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -806,25 +806,28 @@ find_expr_references_walker(Node *node,
}
return false;
}
if (IsA(node, Expr))
if (IsA(node, FuncExpr))
{
Expr *expr = (Expr *) node;
FuncExpr *funcexpr = (FuncExpr *) node;
if (expr->opType == OP_EXPR ||
expr->opType == DISTINCT_EXPR)
{
Oper *oper = (Oper *) expr->oper;
add_object_address(OCLASS_PROC, funcexpr->funcid, 0,
&context->addrs);
/* fall through to examine arguments */
}
if (IsA(node, OpExpr))
{
OpExpr *opexpr = (OpExpr *) node;
add_object_address(OCLASS_OPERATOR, oper->opno, 0,
&context->addrs);
}
else if (expr->opType == FUNC_EXPR)
{
Func *func = (Func *) expr->oper;
add_object_address(OCLASS_OPERATOR, opexpr->opno, 0,
&context->addrs);
/* fall through to examine arguments */
}
if (IsA(node, DistinctExpr))
{
DistinctExpr *distinctexpr = (DistinctExpr *) node;
add_object_address(OCLASS_PROC, func->funcid, 0,
&context->addrs);
}
add_object_address(OCLASS_OPERATOR, distinctexpr->opno, 0,
&context->addrs);
/* fall through to examine arguments */
}
if (IsA(node, Aggref))
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.235 2002/11/15 02:50:05 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.236 2002/12/12 15:49:23 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -1602,11 +1602,6 @@ AddRelationRawConstraints(Relation rel,
*/
expr = (Node *) make_ands_implicit((Expr *) expr);
/*
* Must fix opids in operator clauses.
*/
fix_opids(expr);
/*
* OK, store it.
*/
......@@ -1750,11 +1745,6 @@ cookDefault(ParseState *pstate,
*/
expr = eval_const_expressions(expr);
/*
* Must fix opids, in case any operators remain...
*/
fix_opids(expr);
return (expr);
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.205 2002/11/13 00:39:46 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.206 2002/12/12 15:49:24 tgl Exp $
*
*
* INTERFACE ROUTINES
......@@ -41,6 +41,7 @@
#include "executor/executor.h"
#include "miscadmin.h"
#include "optimizer/clauses.h"
#include "optimizer/planmain.h"
#include "optimizer/prep.h"
#include "parser/parse_func.h"
#include "storage/sinval.h"
......@@ -919,6 +920,7 @@ BuildIndexInfo(Form_pg_index indexStruct)
predString = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(&indexStruct->indpred)));
ii->ii_Predicate = stringToNode(predString);
fix_opfuncids((Node *) ii->ii_Predicate);
pfree(predString);
}
else
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.94 2002/09/18 21:35:20 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.95 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -424,7 +424,7 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
} while (attr->attisdropped);
rellogcols++;
tletype = exprType(tle->expr);
tletype = exprType((Node *) tle->expr);
atttype = attr->atttypid;
if (!IsBinaryCoercible(tletype, atttype))
elog(ERROR, "function declared to return %s returns %s instead of %s at column %d",
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.184 2002/12/01 18:14:22 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.185 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -35,6 +35,7 @@
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "optimizer/planmain.h"
#include "parser/parse_coerce.h"
#include "parser/parse_relation.h"
#include "rewrite/rewriteHandler.h"
......@@ -839,6 +840,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
defexprs[num_defaults] = build_column_default(rel, i + 1);
if (defexprs[num_defaults] != NULL)
{
fix_opfuncids(defexprs[num_defaults]);
defmap[num_defaults] = i;
num_defaults++;
}
......@@ -869,6 +871,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
/* check whether any constraints actually found */
if (node != (Node *) prm)
{
fix_opfuncids(node);
constraintexprs[i] = node;
hasConstraints = true;
}
......
......@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.95 2002/12/06 19:28:03 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.96 2002/12/12 15:49:24 tgl Exp $
*
*/
......@@ -417,20 +417,27 @@ explain_outNode(StringInfo str,
{
RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
es->rtable);
Expr *expr;
Func *funcnode;
Oid funcid;
char *proname;
/* Assert it's on a RangeFunction */
Assert(rte->rtekind == RTE_FUNCTION);
expr = (Expr *) rte->funcexpr;
funcnode = (Func *) expr->oper;
funcid = funcnode->funcid;
/* We only show the func name, not schema name */
proname = get_func_name(funcid);
/*
* If the expression is still a function call, we can get
* the real name of the function. Otherwise, punt (this
* can happen if the optimizer simplified away the function
* call, for example).
*/
if (rte->funcexpr && IsA(rte->funcexpr, FuncExpr))
{
FuncExpr *funcexpr = (FuncExpr *) rte->funcexpr;
Oid funcid = funcexpr->funcid;
/* We only show the func name, not schema name */
proname = get_func_name(funcid);
}
else
proname = rte->eref->aliasname;
appendStringInfo(str, " on %s",
quote_identifier(proname));
......@@ -583,7 +590,7 @@ explain_outNode(StringInfo str,
appendStringInfo(str, " InitPlan\n");
foreach(lst, plan->initPlan)
{
SubPlan *subplan = (SubPlan *) lfirst(lst);
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(lst);
SubPlanState *subplanstate = (SubPlanState *) lfirst(pslist);
es->rtable = subplan->rtable;
......@@ -683,7 +690,7 @@ explain_outNode(StringInfo str,
foreach(lst, planstate->subPlan)
{
SubPlanState *sps = (SubPlanState *) lfirst(lst);
SubPlan *sp = (SubPlan *) sps->ps.plan;
SubPlanExpr *sp = (SubPlanExpr *) sps->ps.plan;
es->rtable = sp->rtable;
for (i = 0; i < indent; i++)
......@@ -870,7 +877,7 @@ show_sort_keys(List *tlist, int nkeys, const char *qlabel,
if (target->resdom->reskey == keyno)
{
/* Deparse the expression, showing any top-level cast */
exprstr = deparse_expression(target->expr, context,
exprstr = deparse_expression((Node *) target->expr, context,
useprefix, true);
/* And add to str */
if (keyno > 1)
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.92 2002/10/21 22:06:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.93 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -159,10 +159,10 @@ DefineIndex(RangeVar *heapRelation,
* While we are at it, we reduce it to a canonical (CNF or DNF) form
* to simplify the task of proving implications.
*/
if (predicate != NULL && rangetable != NIL)
if (predicate)
{
cnfPred = canonicalize_qual((Expr *) copyObject(predicate), true);
fix_opids((Node *) cnfPred);
fix_opfuncids((Node *) cnfPred);
CheckPredicate(cnfPred, rangetable, relationId);
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.57 2002/11/23 18:26:45 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.58 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -2723,7 +2723,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
/*
* We need to make a parse state and range
* table to allow us to transformExpr and
* fix_opids to get a version of the
* fix_opfuncids to get a version of the
* expression we can pass to ExecQual
*/
pstate = make_parsestate(NULL);
......@@ -2764,8 +2764,8 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
*/
expr = eval_const_expressions(expr);
/* And fix the opids */
fix_opids(expr);
/* And fix the opfuncids */
fix_opfuncids(expr);
qual = makeList1(expr);
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.21 2002/12/09 20:31:05 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.22 2002/12/12 15:49:24 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
......@@ -1341,7 +1341,9 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
* the constraint is being added to.
*/
expr = stringToNode(ccbin);
fix_opfuncids(expr);
rels = get_rels_with_domain(domainoid);
foreach (rt, rels)
{
Relation typrel;
......@@ -1522,7 +1524,7 @@ domainPermissionCheck(HeapTuple tup, TypeName *typename)
/*
*
* domainAddConstraint
*/
char *
domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
......@@ -1601,21 +1603,20 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
expr = eval_const_expressions(expr);
/*
* Must fix opids in operator clauses.
* Convert to string form for storage.
*/
fix_opids(expr);
ccbin = nodeToString(expr);
/*
* Deparse it. Since VARNOs aren't allowed in domain
* constraints, relation context isn't required as anything
* other than a shell.
* Deparse it to produce text for consrc.
*
* Since VARNOs aren't allowed in domain constraints, relation context
* isn't required as anything other than a shell.
*/
ccsrc = deparse_expression(expr,
deparse_context_for(domainName,
InvalidOid),
false, false);
deparse_context_for(domainName,
InvalidOid),
false, false);
/* Write the constraint */
CreateConstraintEntry(constr->name, /* Constraint Name */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.32 2002/09/04 20:31:17 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.33 2002/12/12 15:49:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -77,7 +77,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType,
bool resjunk;
AttrNumber cleanResno;
AttrNumber *cleanMap;
Node *expr;
Expr *expr;
/*
* Make a memory context that will hold the JunkFilter as well as all
......@@ -104,65 +104,23 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType,
{
TargetEntry *rtarget = lfirst(t);
if (rtarget->resdom != NULL)
{
resdom = rtarget->resdom;
expr = rtarget->expr;
resjunk = resdom->resjunk;
if (!resjunk)
{
/*
* make a copy of the resdom node, changing its resno.
*/
cleanResdom = (Resdom *) copyObject(resdom);
cleanResdom->resno = cleanResno;
cleanResno++;
/*
* create a new target list entry
*/
tle = makeTargetEntry(cleanResdom, expr);
cleanTargetList = lappend(cleanTargetList, tle);
}
}
else
resdom = rtarget->resdom;
expr = rtarget->expr;
resjunk = resdom->resjunk;
if (!resjunk)
{
#ifdef SETS_FIXED
List *fjListP;
Fjoin *cleanFjoin;
List *cleanFjList;
List *fjList = lfirst(t);
Fjoin *fjNode = (Fjoin *) tl_node(fjList);
cleanFjoin = (Fjoin) copyObject((Node) fjNode);
cleanFjList = makeList1(cleanFjoin);
resdom = (Resdom) lfirst(get_fj_innerNode(fjNode));
expr = lsecond(get_fj_innerNode(fjNode));
cleanResdom = (Resdom) copyObject((Node) resdom);
set_resno(cleanResdom, cleanResno);
/*
* make a copy of the resdom node, changing its resno.
*/
cleanResdom = (Resdom *) copyObject(resdom);
cleanResdom->resno = cleanResno;
cleanResno++;
tle = (List) makeTargetEntry(cleanResdom, (Node *) expr);
set_fj_innerNode(cleanFjoin, tle);
foreach(fjListP, lnext(fjList))
{
TargetEntry *tle = lfirst(fjListP);
resdom = tle->resdom;
expr = tle->expr;
cleanResdom = (Resdom *) copyObject((Node) resdom);
cleanResno++;
cleanResdom->Resno = cleanResno;
/*
* create a new target list entry
*/
tle = (List) makeTargetEntry(cleanResdom, (Node *) expr);
cleanFjList = lappend(cleanFjList, tle);
}
lappend(cleanTargetList, cleanFjList);
#endif
/*
* create a new target list entry
*/
tle = makeTargetEntry(cleanResdom, expr);
cleanTargetList = lappend(cleanTargetList, tle);
}
}
......@@ -192,41 +150,12 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType,
{
TargetEntry *tle = lfirst(t);
if (tle->resdom != NULL)
{
resdom = tle->resdom;
expr = tle->expr;
resjunk = resdom->resjunk;
if (!resjunk)
{
cleanMap[cleanResno - 1] = resdom->resno;
cleanResno++;
}
}
else
resdom = tle->resdom;
resjunk = resdom->resjunk;
if (!resjunk)
{
#ifdef SETS_FIXED
List fjListP;
List fjList = lfirst(t);
Fjoin fjNode = (Fjoin) lfirst(fjList);
/* what the hell is this????? */
resdom = (Resdom) lfirst(get_fj_innerNode(fjNode));
#endif
cleanMap[cleanResno - 1] = tle->resdom->resno;
cleanMap[cleanResno - 1] = resdom->resno;
cleanResno++;
#ifdef SETS_FIXED
foreach(fjListP, lnext(fjList))
{
TargetEntry *tle = lfirst(fjListP);
resdom = tle->resdom;
cleanMap[cleanResno - 1] = resdom->resno;
cleanResno++;
}
#endif
}
}
}
......
......@@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.190 2002/12/05 15:50:30 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.191 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -40,6 +40,7 @@
#include "executor/execdebug.h"
#include "executor/execdefs.h"
#include "miscadmin.h"
#include "optimizer/planmain.h"
#include "optimizer/var.h"
#include "parser/parsetree.h"
#include "utils/acl.h"
......@@ -1541,6 +1542,7 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
for (i = 0; i < ncheck; i++)
{
qual = (List *) stringToNode(check[i].ccbin);
fix_opfuncids((Node *) qual);
resultRelInfo->ri_ConstraintExprs[i] = qual;
}
MemoryContextSwitchTo(oldContext);
......
......@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.31 2002/12/05 15:50:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.32 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -228,9 +228,9 @@ ExecInitNode(Plan *node, EState *estate)
subps = NIL;
foreach(subp, node->initPlan)
{
SubPlan *subplan = (SubPlan *) lfirst(subp);
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(subp);
Assert(IsA(subplan, SubPlan));
Assert(IsA(subplan, SubPlanExpr));
subps = lappend(subps, ExecInitSubPlan(subplan, estate));
}
result->initPlan = subps;
......@@ -242,9 +242,9 @@ ExecInitNode(Plan *node, EState *estate)
subps = NIL;
foreach(subp, result->subPlan)
{
SubPlan *subplan = (SubPlan *) lfirst(subp);
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(subp);
Assert(IsA(subplan, SubPlan));
Assert(IsA(subplan, SubPlanExpr));
subps = lappend(subps, ExecInitSubPlan(subplan, estate));
}
result->subPlan = subps;
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.61 2002/12/05 15:50:32 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.62 2002/12/12 15:49:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -576,93 +576,15 @@ ExecTypeFromTL(List *targetList, bool hasoid)
foreach(tlitem, targetList)
{
TargetEntry *tle = lfirst(tlitem);
Resdom *resdom;
Oid restype;
if (tle->resdom != NULL)
{
resdom = tle->resdom;
restype = resdom->restype;
TupleDescInitEntry(typeInfo,
resdom->resno,
resdom->resname,
restype,
resdom->restypmod,
0,
false);
#ifdef NOT_USED
ExecSetTypeInfo(resdom->resno - 1,
typeInfo,
(Oid) restype,
resdom->resno,
resdom->reslen,
NameStr(*resdom->resname),
get_typbyval(restype),
get_typalign(restype));
#endif
}
else
{
/* XXX this branch looks fairly broken ... tgl 12/2000 */
Resdom *fjRes;
List *fjTlistP;
List *fjList = lfirst(tlitem);
#ifdef SETS_FIXED
TargetEntry *tle;
Fjoin *fjNode = ((TargetEntry *) lfirst(fjList))->fjoin;
tle = fjNode->fj_innerNode; /* ??? */
#endif
fjRes = tle->resdom;
restype = fjRes->restype;
TupleDescInitEntry(typeInfo,
fjRes->resno,
fjRes->resname,
restype,
fjRes->restypmod,
0,
false);
#ifdef NOT_USED
ExecSetTypeInfo(fjRes->resno - 1,
typeInfo,
(Oid) restype,
fjRes->resno,
fjRes->reslen,
(char *) fjRes->resname,
get_typbyval(restype),
get_typalign(restype));
#endif
foreach(fjTlistP, lnext(fjList))
{
TargetEntry *fjTle = lfirst(fjTlistP);
fjRes = fjTle->resdom;
TupleDescInitEntry(typeInfo,
fjRes->resno,
fjRes->resname,
restype,
fjRes->restypmod,
0,
false);
#ifdef NOT_USED
ExecSetTypeInfo(fjRes->resno - 1,
typeInfo,
(Oid) fjRes->restype,
fjRes->resno,
fjRes->reslen,
(char *) fjRes->resname,
get_typbyval(fjRes->restype),
get_typalign(fjRes->restype));
#endif
}
}
Resdom *resdom = tle->resdom;
TupleDescInitEntry(typeInfo,
resdom->resno,
resdom->resname,
resdom->restype,
resdom->restypmod,
0,
false);
}
return typeInfo;
......
......@@ -45,7 +45,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.98 2002/12/05 15:50:32 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.99 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -415,7 +415,7 @@ advance_aggregates(AggState *aggstate, AggStatePerGroup pergroup)
Datum newVal;
bool isNull;
newVal = ExecEvalExprSwitchContext(aggref->target, econtext,
newVal = ExecEvalExprSwitchContext((Node *) aggref->target, econtext,
&isNull, NULL);
if (aggref->aggdistinct)
......@@ -1298,7 +1298,7 @@ ExecInitAgg(Agg *node, EState *estate)
* pg_proc.proargtypes, because the latter might be 0.
* (Consider COUNT(*).)
*/
Oid inputType = exprType(aggref->target);
Oid inputType = exprType((Node *) aggref->target);
if (!IsBinaryCoercible(inputType, aggform->aggtranstype))
elog(ERROR, "Aggregate %u needs to have compatible input type and transition type",
......@@ -1312,7 +1312,7 @@ ExecInitAgg(Agg *node, EState *estate)
* pg_proc.proargtypes, because the latter might be a pseudotype.
* (Consider COUNT(*).)
*/
Oid inputType = exprType(aggref->target);
Oid inputType = exprType((Node *) aggref->target);
Oid eq_function;
/* We don't implement DISTINCT aggs in the HASHED case */
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.72 2002/12/05 15:50:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.73 2002/12/12 15:49:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -703,28 +703,26 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
listscan = qual;
for (j = 0; j < n_keys; j++)
{
Expr *clause; /* one clause of index qual */
Oper *op; /* operator used in clause */
OpExpr *clause; /* one clause of index qual */
Node *leftop; /* expr on lhs of operator */
Node *rightop; /* expr on rhs ... */
bits16 flags = 0;
int scanvar; /* which var identifies varattno */
AttrNumber varattno = 0; /* att number used in scan */
Oid opid; /* operator id used in scan */
Oid opfuncid; /* operator id used in scan */
Datum scanvalue = 0; /* value used in scan (if const) */
/*
* extract clause information from the qualification
*/
clause = lfirst(listscan);
clause = (OpExpr *) lfirst(listscan);
listscan = lnext(listscan);
op = (Oper *) clause->oper;
if (!IsA(clause, Expr) ||!IsA(op, Oper))
if (!IsA(clause, OpExpr))
elog(ERROR, "ExecInitIndexScan: indxqual not an opclause!");
opid = op->opid;
opfuncid = clause->opfuncid;
/*
* Here we figure out the contents of the index qual. The
......@@ -767,10 +765,10 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
/*
* determine information in leftop
*/
leftop = (Node *) get_leftop(clause);
leftop = (Node *) get_leftop((Expr *) clause);
if (leftop && IsA(leftop, RelabelType))
leftop = ((RelabelType *) leftop)->arg;
leftop = (Node *) ((RelabelType *) leftop)->arg;
Assert(leftop != NULL);
......@@ -834,10 +832,10 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
/*
* now determine information in rightop
*/
rightop = (Node *) get_rightop(clause);
rightop = (Node *) get_rightop((Expr *) clause);
if (rightop && IsA(rightop, RelabelType))
rightop = ((RelabelType *) rightop)->arg;
rightop = (Node *) ((RelabelType *) rightop)->arg;
Assert(rightop != NULL);
......@@ -921,7 +919,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate)
flags,
varattno, /* attribute number to
* scan */
(RegProcedure) opid, /* reg proc to use */
opfuncid, /* reg proc to use */
scanvalue); /* constant */
}
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.52 2002/12/05 15:50:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.53 2002/12/12 15:49:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -119,16 +119,14 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals)
ltcdr = *ltQuals;
foreach(gtcdr, *gtQuals)
{
Expr *ltqual = (Expr *) lfirst(ltcdr);
Expr *gtqual = (Expr *) lfirst(gtcdr);
Oper *ltop = (Oper *) ltqual->oper;
Oper *gtop = (Oper *) gtqual->oper;
OpExpr *ltop = (OpExpr *) lfirst(ltcdr);
OpExpr *gtop = (OpExpr *) lfirst(gtcdr);
/*
* The two ops should be identical, so use either one for lookup.
*/
if (!IsA(ltop, Oper))
elog(ERROR, "MJFormSkipQuals: op not an Oper!");
if (!IsA(ltop, OpExpr))
elog(ERROR, "MJFormSkipQuals: op not an OpExpr!");
/*
* Lookup the operators, and replace the data in the copied
......@@ -137,8 +135,8 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals)
op_mergejoin_crossops(ltop->opno,
&ltop->opno,
&gtop->opno,
&ltop->opid,
&gtop->opid);
&ltop->opfuncid,
&gtop->opfuncid);
ltop->op_fcache = NULL;
gtop->op_fcache = NULL;
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.35 2002/12/05 15:50:33 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.36 2002/12/12 15:49:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -34,7 +34,7 @@ ExecSubPlan(SubPlanState *node, List *pvar,
ExprContext *econtext, bool *isNull)
{
PlanState *planstate = node->planstate;
SubPlan *subplan = (SubPlan *) node->ps.plan;
SubPlanExpr *subplan = (SubPlanExpr *) node->ps.plan;
SubLink *sublink = subplan->sublink;
SubLinkType subLinkType = sublink->subLinkType;
bool useor = sublink->useor;
......@@ -151,7 +151,7 @@ ExecSubPlan(SubPlanState *node, List *pvar,
*/
foreach(lst, sublink->oper)
{
Expr *expr = (Expr *) lfirst(lst);
OpExpr *expr = (OpExpr *) lfirst(lst);
Param *prm = lsecond(expr->args);
ParamExecData *prmdata;
Datum expresult;
......@@ -172,8 +172,8 @@ ExecSubPlan(SubPlanState *node, List *pvar,
{
switch (nodeTag(prm))
{
case T_Expr:
prm = lfirst(((Expr *) prm)->args);
case T_FuncExpr:
prm = lfirst(((FuncExpr *) prm)->args);
break;
case T_RelabelType:
prm = (Param *) (((RelabelType *) prm)->arg);
......@@ -288,7 +288,7 @@ ExecSubPlan(SubPlanState *node, List *pvar,
* ----------------------------------------------------------------
*/
SubPlanState *
ExecInitSubPlan(SubPlan *node, EState *estate)
ExecInitSubPlan(SubPlanExpr *node, EState *estate)
{
SubPlanState *subplanstate;
EState *sp_estate;
......@@ -374,7 +374,7 @@ void
ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
{
PlanState *planstate = node->planstate;
SubPlan *subplan = (SubPlan *) node->ps.plan;
SubPlanExpr *subplan = (SubPlanExpr *) node->ps.plan;
SubLink *sublink = subplan->sublink;
EState *estate = node->ps.state;
MemoryContext oldcontext;
......@@ -497,7 +497,7 @@ void
ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
{
PlanState *planstate = node->planstate;
SubPlan *subplan = (SubPlan *) node->ps.plan;
SubPlanExpr *subplan = (SubPlanExpr *) node->ps.plan;
EState *estate = node->ps.state;
List *lst;
......
This diff is collapsed.
This diff is collapsed.
/*
/*-------------------------------------------------------------------------
*
* makefuncs.c
* creator functions for primitive nodes. The functions here are for
* the most frequently created nodes.
......@@ -8,7 +9,9 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.36 2002/11/25 21:29:36 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.37 2002/12/12 15:49:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
......@@ -49,30 +52,9 @@ makeSimpleA_Expr(int oper, const char *name,
return a;
}
/*
* makeOper -
* creates an Oper node
*/
Oper *
makeOper(Oid opno,
Oid opid,
Oid opresulttype,
bool opretset)
{
Oper *oper = makeNode(Oper);
oper->opno = opno;
oper->opid = opid;
oper->opresulttype = opresulttype;
oper->opretset = opretset;
oper->op_fcache = NULL;
return oper;
}
/*
* makeVar -
* creates a Var node
*
*/
Var *
makeVar(Index varno,
......@@ -104,10 +86,10 @@ makeVar(Index varno,
/*
* makeTargetEntry -
* creates a TargetEntry node(contains a Resdom)
* creates a TargetEntry node (contains a Resdom)
*/
TargetEntry *
makeTargetEntry(Resdom *resdom, Node *expr)
makeTargetEntry(Resdom *resdom, Expr *expr)
{
TargetEntry *rt = makeNode(TargetEntry);
......@@ -188,6 +170,21 @@ makeNullConst(Oid consttype)
typByVal);
}
/*
* makeBoolExpr -
* creates a BoolExpr node
*/
Expr *
makeBoolExpr(BoolExprType boolop, List *args)
{
BoolExpr *b = makeNode(BoolExpr);
b->boolop = boolop;
b->args = args;
return (Expr *) b;
}
/*
* makeAlias -
* creates an Alias node
......@@ -210,7 +207,7 @@ makeAlias(const char *aliasname, List *colnames)
* creates a RelabelType node
*/
RelabelType *
makeRelabelType(Node *arg, Oid rtype, int32 rtypmod, CoercionForm rformat)
makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, CoercionForm rformat)
{
RelabelType *r = makeNode(RelabelType);
......
......@@ -8,12 +8,10 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.19 2002/09/02 02:47:02 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.20 2002/12/12 15:49:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "nodes/nodeFuncs.h"
......@@ -21,6 +19,7 @@
static bool var_is_inner(Var *var);
/*
* single_node -
* Returns t if node corresponds to a single-noded expression
......@@ -79,41 +78,15 @@ var_is_rel(Var *var)
*****************************************************************************/
/*
* replace_opid -
*
* Given a oper node, resets the opfid field with the
* procedure OID (regproc id).
*
* Returns the modified oper node.
* set_opfuncid -
*
* Set the opfuncid (procedure OID) in an OpExpr node,
* if it hasn't been set already.
*/
Oper *
replace_opid(Oper *oper)
void
set_opfuncid(OpExpr *opexpr)
{
oper->opid = get_opcode(oper->opno);
oper->op_fcache = NULL;
return oper;
if (opexpr->opfuncid == InvalidOid)
opexpr->opfuncid = get_opcode(opexpr->opno);
opexpr->op_fcache = NULL; /* XXX will go away soon */
}
/*****************************************************************************
* 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
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.57 2002/09/04 20:31:20 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.58 2002/12/12 15:49:28 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
......@@ -371,7 +371,7 @@ print_expr(Node *expr, List *rtable)
char *opname;
print_expr((Node *) get_leftop(e), rtable);
opname = get_opname(((Oper *) e->oper)->opno);
opname = get_opname(((OpExpr *) e)->opno);
printf(" %s ", ((opname != NULL) ? opname : "(invalid operator)"));
print_expr((Node *) get_rightop(e), rtable);
}
......@@ -432,7 +432,7 @@ print_tl(List *tlist, List *rtable)
printf("(%d):\t", tle->resdom->reskey);
else
printf(" :\t");
print_expr(tle->expr, rtable);
print_expr((Node *) tle->expr, rtable);
printf("\n");
}
printf(")\n");
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.53 2002/11/25 21:29:39 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.54 2002/12/12 15:49:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -141,7 +141,7 @@ clauselist_selectivity(Query *root,
if (is_opclause(clause) &&
(varRelid != 0 || NumRelids(clause) == 1))
{
Expr *expr = (Expr *) clause;
OpExpr *expr = (OpExpr *) clause;
if (length(expr->args) == 2)
{
......@@ -151,7 +151,7 @@ clauselist_selectivity(Query *root,
(varonleft = false,
is_pseudo_constant_clause(lfirst(expr->args))))
{
Oid opno = ((Oper *) expr->oper)->opno;
Oid opno = expr->opno;
RegProcedure oprrest = get_oprrest(opno);
s2 = restriction_selectivity(root, opno,
......@@ -430,7 +430,7 @@ clause_selectivity(Query *root,
{
/* share code with clauselist_selectivity() */
s1 = clauselist_selectivity(root,
((Expr *) clause)->args,
((BoolExpr *) clause)->args,
varRelid);
}
else if (or_clause(clause))
......@@ -443,7 +443,7 @@ clause_selectivity(Query *root,
List *arg;
s1 = 0.0;
foreach(arg, ((Expr *) clause)->args)
foreach(arg, ((BoolExpr *) clause)->args)
{
Selectivity s2 = clause_selectivity(root,
(Node *) lfirst(arg),
......@@ -454,7 +454,7 @@ clause_selectivity(Query *root,
}
else if (is_opclause(clause))
{
Oid opno = ((Oper *) ((Expr *) clause)->oper)->opno;
Oid opno = ((OpExpr *) clause)->opno;
bool is_join_clause;
if (varRelid != 0)
......@@ -479,13 +479,14 @@ clause_selectivity(Query *root,
{
/* Estimate selectivity for a join clause. */
s1 = join_selectivity(root, opno,
((Expr *) clause)->args);
((OpExpr *) clause)->args);
}
else
{
/* Estimate selectivity for a restriction clause. */
s1 = restriction_selectivity(root, opno,
((Expr *) clause)->args, varRelid);
((OpExpr *) clause)->args,
varRelid);
}
}
else if (is_funcclause(clause))
......@@ -509,7 +510,7 @@ clause_selectivity(Query *root,
/* Use node specific selectivity calculation function */
s1 = nulltestsel(root,
((NullTest *) clause)->nulltesttype,
((NullTest *) clause)->arg,
(Node *) ((NullTest *) clause)->arg,
varRelid);
}
else if (IsA(clause, BooleanTest))
......@@ -517,14 +518,14 @@ clause_selectivity(Query *root,
/* Use node specific selectivity calculation function */
s1 = booltestsel(root,
((BooleanTest *) clause)->booltesttype,
((BooleanTest *) clause)->arg,
(Node *) ((BooleanTest *) clause)->arg,
varRelid);
}
else if (IsA(clause, RelabelType))
{
/* Not sure this case is needed, but it can't hurt */
s1 = clause_selectivity(root,
((RelabelType *) clause)->arg,
(Node *) ((RelabelType *) clause)->arg,
varRelid);
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment