Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a0bf885

Browse files
committed
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.
1 parent debb072 commit a0bf885

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3362
-3405
lines changed

src/backend/catalog/dependency.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.17 2002/12/06 05:00:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.18 2002/12/12 15:49:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -806,25 +806,28 @@ find_expr_references_walker(Node *node,
806806
}
807807
return false;
808808
}
809-
if (IsA(node, Expr))
809+
if (IsA(node, FuncExpr))
810810
{
811-
Expr *expr = (Expr *) node;
811+
FuncExpr *funcexpr = (FuncExpr *) node;
812812

813-
if (expr->opType == OP_EXPR ||
814-
expr->opType == DISTINCT_EXPR)
815-
{
816-
Oper *oper = (Oper *) expr->oper;
813+
add_object_address(OCLASS_PROC, funcexpr->funcid, 0,
814+
&context->addrs);
815+
/* fall through to examine arguments */
816+
}
817+
if (IsA(node, OpExpr))
818+
{
819+
OpExpr *opexpr = (OpExpr *) node;
817820

818-
add_object_address(OCLASS_OPERATOR, oper->opno, 0,
819-
&context->addrs);
820-
}
821-
else if (expr->opType == FUNC_EXPR)
822-
{
823-
Func *func = (Func *) expr->oper;
821+
add_object_address(OCLASS_OPERATOR, opexpr->opno, 0,
822+
&context->addrs);
823+
/* fall through to examine arguments */
824+
}
825+
if (IsA(node, DistinctExpr))
826+
{
827+
DistinctExpr *distinctexpr = (DistinctExpr *) node;
824828

825-
add_object_address(OCLASS_PROC, func->funcid, 0,
826-
&context->addrs);
827-
}
829+
add_object_address(OCLASS_OPERATOR, distinctexpr->opno, 0,
830+
&context->addrs);
828831
/* fall through to examine arguments */
829832
}
830833
if (IsA(node, Aggref))

src/backend/catalog/heap.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.235 2002/11/15 02:50:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.236 2002/12/12 15:49:23 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1602,11 +1602,6 @@ AddRelationRawConstraints(Relation rel,
16021602
*/
16031603
expr = (Node *) make_ands_implicit((Expr *) expr);
16041604

1605-
/*
1606-
* Must fix opids in operator clauses.
1607-
*/
1608-
fix_opids(expr);
1609-
16101605
/*
16111606
* OK, store it.
16121607
*/
@@ -1750,11 +1745,6 @@ cookDefault(ParseState *pstate,
17501745
*/
17511746
expr = eval_const_expressions(expr);
17521747

1753-
/*
1754-
* Must fix opids, in case any operators remain...
1755-
*/
1756-
fix_opids(expr);
1757-
17581748
return (expr);
17591749
}
17601750

src/backend/catalog/index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.205 2002/11/13 00:39:46 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.206 2002/12/12 15:49:24 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -41,6 +41,7 @@
4141
#include "executor/executor.h"
4242
#include "miscadmin.h"
4343
#include "optimizer/clauses.h"
44+
#include "optimizer/planmain.h"
4445
#include "optimizer/prep.h"
4546
#include "parser/parse_func.h"
4647
#include "storage/sinval.h"
@@ -919,6 +920,7 @@ BuildIndexInfo(Form_pg_index indexStruct)
919920
predString = DatumGetCString(DirectFunctionCall1(textout,
920921
PointerGetDatum(&indexStruct->indpred)));
921922
ii->ii_Predicate = stringToNode(predString);
923+
fix_opfuncids((Node *) ii->ii_Predicate);
922924
pfree(predString);
923925
}
924926
else

src/backend/catalog/pg_proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.94 2002/09/18 21:35:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.95 2002/12/12 15:49:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -424,7 +424,7 @@ checkretval(Oid rettype, char fn_typtype, List *queryTreeList)
424424
} while (attr->attisdropped);
425425
rellogcols++;
426426

427-
tletype = exprType(tle->expr);
427+
tletype = exprType((Node *) tle->expr);
428428
atttype = attr->atttypid;
429429
if (!IsBinaryCoercible(tletype, atttype))
430430
elog(ERROR, "function declared to return %s returns %s instead of %s at column %d",

src/backend/commands/copy.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.184 2002/12/01 18:14:22 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.185 2002/12/12 15:49:24 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -35,6 +35,7 @@
3535
#include "mb/pg_wchar.h"
3636
#include "miscadmin.h"
3737
#include "nodes/makefuncs.h"
38+
#include "optimizer/planmain.h"
3839
#include "parser/parse_coerce.h"
3940
#include "parser/parse_relation.h"
4041
#include "rewrite/rewriteHandler.h"
@@ -839,6 +840,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
839840
defexprs[num_defaults] = build_column_default(rel, i + 1);
840841
if (defexprs[num_defaults] != NULL)
841842
{
843+
fix_opfuncids(defexprs[num_defaults]);
842844
defmap[num_defaults] = i;
843845
num_defaults++;
844846
}
@@ -869,6 +871,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
869871
/* check whether any constraints actually found */
870872
if (node != (Node *) prm)
871873
{
874+
fix_opfuncids(node);
872875
constraintexprs[i] = node;
873876
hasConstraints = true;
874877
}

src/backend/commands/explain.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.95 2002/12/06 19:28:03 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.96 2002/12/12 15:49:24 tgl Exp $
99
*
1010
*/
1111

@@ -417,20 +417,27 @@ explain_outNode(StringInfo str,
417417
{
418418
RangeTblEntry *rte = rt_fetch(((Scan *) plan)->scanrelid,
419419
es->rtable);
420-
Expr *expr;
421-
Func *funcnode;
422-
Oid funcid;
423420
char *proname;
424421

425422
/* Assert it's on a RangeFunction */
426423
Assert(rte->rtekind == RTE_FUNCTION);
427424

428-
expr = (Expr *) rte->funcexpr;
429-
funcnode = (Func *) expr->oper;
430-
funcid = funcnode->funcid;
431-
432-
/* We only show the func name, not schema name */
433-
proname = get_func_name(funcid);
425+
/*
426+
* If the expression is still a function call, we can get
427+
* the real name of the function. Otherwise, punt (this
428+
* can happen if the optimizer simplified away the function
429+
* call, for example).
430+
*/
431+
if (rte->funcexpr && IsA(rte->funcexpr, FuncExpr))
432+
{
433+
FuncExpr *funcexpr = (FuncExpr *) rte->funcexpr;
434+
Oid funcid = funcexpr->funcid;
435+
436+
/* We only show the func name, not schema name */
437+
proname = get_func_name(funcid);
438+
}
439+
else
440+
proname = rte->eref->aliasname;
434441

435442
appendStringInfo(str, " on %s",
436443
quote_identifier(proname));
@@ -583,7 +590,7 @@ explain_outNode(StringInfo str,
583590
appendStringInfo(str, " InitPlan\n");
584591
foreach(lst, plan->initPlan)
585592
{
586-
SubPlan *subplan = (SubPlan *) lfirst(lst);
593+
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(lst);
587594
SubPlanState *subplanstate = (SubPlanState *) lfirst(pslist);
588595

589596
es->rtable = subplan->rtable;
@@ -683,7 +690,7 @@ explain_outNode(StringInfo str,
683690
foreach(lst, planstate->subPlan)
684691
{
685692
SubPlanState *sps = (SubPlanState *) lfirst(lst);
686-
SubPlan *sp = (SubPlan *) sps->ps.plan;
693+
SubPlanExpr *sp = (SubPlanExpr *) sps->ps.plan;
687694

688695
es->rtable = sp->rtable;
689696
for (i = 0; i < indent; i++)
@@ -870,7 +877,7 @@ show_sort_keys(List *tlist, int nkeys, const char *qlabel,
870877
if (target->resdom->reskey == keyno)
871878
{
872879
/* Deparse the expression, showing any top-level cast */
873-
exprstr = deparse_expression(target->expr, context,
880+
exprstr = deparse_expression((Node *) target->expr, context,
874881
useprefix, true);
875882
/* And add to str */
876883
if (keyno > 1)

src/backend/commands/indexcmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.92 2002/10/21 22:06:19 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.93 2002/12/12 15:49:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -159,10 +159,10 @@ DefineIndex(RangeVar *heapRelation,
159159
* While we are at it, we reduce it to a canonical (CNF or DNF) form
160160
* to simplify the task of proving implications.
161161
*/
162-
if (predicate != NULL && rangetable != NIL)
162+
if (predicate)
163163
{
164164
cnfPred = canonicalize_qual((Expr *) copyObject(predicate), true);
165-
fix_opids((Node *) cnfPred);
165+
fix_opfuncids((Node *) cnfPred);
166166
CheckPredicate(cnfPred, rangetable, relationId);
167167
}
168168

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.57 2002/11/23 18:26:45 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.58 2002/12/12 15:49:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2723,7 +2723,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27232723
/*
27242724
* We need to make a parse state and range
27252725
* table to allow us to transformExpr and
2726-
* fix_opids to get a version of the
2726+
* fix_opfuncids to get a version of the
27272727
* expression we can pass to ExecQual
27282728
*/
27292729
pstate = make_parsestate(NULL);
@@ -2764,8 +2764,8 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27642764
*/
27652765
expr = eval_const_expressions(expr);
27662766

2767-
/* And fix the opids */
2768-
fix_opids(expr);
2767+
/* And fix the opfuncids */
2768+
fix_opfuncids(expr);
27692769

27702770
qual = makeList1(expr);
27712771

src/backend/commands/typecmds.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.21 2002/12/09 20:31:05 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.22 2002/12/12 15:49:24 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -1341,7 +1341,9 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
13411341
* the constraint is being added to.
13421342
*/
13431343
expr = stringToNode(ccbin);
1344+
fix_opfuncids(expr);
13441345
rels = get_rels_with_domain(domainoid);
1346+
13451347
foreach (rt, rels)
13461348
{
13471349
Relation typrel;
@@ -1522,7 +1524,7 @@ domainPermissionCheck(HeapTuple tup, TypeName *typename)
15221524

15231525

15241526
/*
1525-
*
1527+
* domainAddConstraint
15261528
*/
15271529
char *
15281530
domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
@@ -1601,21 +1603,20 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
16011603
expr = eval_const_expressions(expr);
16021604

16031605
/*
1604-
* Must fix opids in operator clauses.
1606+
* Convert to string form for storage.
16051607
*/
1606-
fix_opids(expr);
1607-
16081608
ccbin = nodeToString(expr);
16091609

16101610
/*
1611-
* Deparse it. Since VARNOs aren't allowed in domain
1612-
* constraints, relation context isn't required as anything
1613-
* other than a shell.
1611+
* Deparse it to produce text for consrc.
1612+
*
1613+
* Since VARNOs aren't allowed in domain constraints, relation context
1614+
* isn't required as anything other than a shell.
16141615
*/
16151616
ccsrc = deparse_expression(expr,
1616-
deparse_context_for(domainName,
1617-
InvalidOid),
1618-
false, false);
1617+
deparse_context_for(domainName,
1618+
InvalidOid),
1619+
false, false);
16191620

16201621
/* Write the constraint */
16211622
CreateConstraintEntry(constr->name, /* Constraint Name */

0 commit comments

Comments
 (0)