Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a4f7dd

Browse files
committed
Phase 3 of read-only-plans project: ExecInitExpr now builds expression
execution state trees, and ExecEvalExpr takes an expression state treenot an expression plan tree. The plan tree is now read-only as far asthe executor is concerned. Next step is to begin actually exploitingthis property.
1 parent77b7a74 commit3a4f7dd

Some content is hidden

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

49 files changed

+973
-795
lines changed

‎contrib/intagg/int_aggregate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include"catalog/pg_proc.h"
2626
#include"catalog/pg_type.h"
2727
#include"executor/executor.h"
28-
#include"utils/fcache.h"
2928
#include"utils/sets.h"
3029
#include"utils/syscache.h"
3130
#include"access/tupmacs.h"

‎src/backend/bootstrap/bootstrap.c

Lines changed: 4 additions & 1 deletion
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/bootstrap/bootstrap.c,v 1.145 2002/11/14 23:53:27 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.146 2002/12/13 19:45:45 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -31,6 +31,7 @@
3131
#include"catalog/catname.h"
3232
#include"catalog/index.h"
3333
#include"catalog/pg_type.h"
34+
#include"executor/executor.h"
3435
#include"libpq/pqsignal.h"
3536
#include"miscadmin.h"
3637
#include"storage/ipc.h"
@@ -1142,6 +1143,8 @@ index_register(Oid heap,
11421143
/* predicate will likely be null, but may as well copy it */
11431144
newind->il_info->ii_Predicate= (List*)
11441145
copyObject(indexInfo->ii_Predicate);
1146+
newind->il_info->ii_PredicateState= (List*)
1147+
ExecInitExpr((Expr*)newind->il_info->ii_Predicate,NULL);
11451148

11461149
newind->il_next=ILHead;
11471150
ILHead=newind;

‎src/backend/catalog/index.c

Lines changed: 8 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/index.c,v 1.206 2002/12/12 15:49:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.207 2002/12/13 19:45:47 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -912,6 +912,7 @@ BuildIndexInfo(Form_pg_index indexStruct)
912912

913913
/*
914914
* If partial index, convert predicate into expression nodetree
915+
* and prepare an execution state nodetree for it
915916
*/
916917
if (VARSIZE(&indexStruct->indpred)>VARHDRSZ)
917918
{
@@ -921,10 +922,15 @@ BuildIndexInfo(Form_pg_index indexStruct)
921922
PointerGetDatum(&indexStruct->indpred)));
922923
ii->ii_Predicate=stringToNode(predString);
923924
fix_opfuncids((Node*)ii->ii_Predicate);
925+
ii->ii_PredicateState= (List*)
926+
ExecInitExpr((Expr*)ii->ii_Predicate,NULL);
924927
pfree(predString);
925928
}
926929
else
930+
{
927931
ii->ii_Predicate=NIL;
932+
ii->ii_PredicateState=NIL;
933+
}
928934

929935
/* Other info */
930936
ii->ii_Unique=indexStruct->indisunique;
@@ -1483,7 +1489,7 @@ IndexBuildHeapScan(Relation heapRelation,
14831489
Datumattdata[INDEX_MAX_KEYS];
14841490
charnulls[INDEX_MAX_KEYS];
14851491
doublereltuples;
1486-
List*predicate=indexInfo->ii_Predicate;
1492+
List*predicate=indexInfo->ii_PredicateState;
14871493
TupleTabletupleTable;
14881494
TupleTableSlot*slot;
14891495
ExprContext*econtext;

‎src/backend/commands/copy.c

Lines changed: 14 additions & 12 deletions
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.185 2002/12/12 15:49:24 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.186 2002/12/13 19:45:48 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -758,7 +758,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
758758
num_defaults;
759759
FmgrInfo*in_functions;
760760
Oid*elements;
761-
Node**constraintexprs;
761+
ExprState**constraintexprs;
762762
boolhasConstraints= false;
763763
inti;
764764
List*cur;
@@ -772,7 +772,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
772772
TupleTableSlot*slot;
773773
boolfile_has_oids;
774774
int*defmap;
775-
Node**defexprs;/* array of default att expressions */
775+
ExprState**defexprs;/* array of default att expressions */
776776
ExprContext*econtext;/* used for ExecEvalExpr for default atts */
777777
MemoryContextoldcontext=CurrentMemoryContext;
778778

@@ -812,8 +812,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
812812
in_functions= (FmgrInfo*)palloc(num_phys_attrs*sizeof(FmgrInfo));
813813
elements= (Oid*)palloc(num_phys_attrs*sizeof(Oid));
814814
defmap= (int*)palloc(num_phys_attrs*sizeof(int));
815-
defexprs= (Node**)palloc(num_phys_attrs*sizeof(Node*));
816-
constraintexprs= (Node**)palloc0(num_phys_attrs*sizeof(Node*));
815+
defexprs= (ExprState**)palloc(num_phys_attrs*sizeof(ExprState*));
816+
constraintexprs= (ExprState**)palloc0(num_phys_attrs*sizeof(ExprState*));
817817

818818
for (i=0;i<num_phys_attrs;i++)
819819
{
@@ -837,10 +837,12 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
837837
{
838838
/* attribute is NOT to be copied */
839839
/* use default value if one exists */
840-
defexprs[num_defaults]=build_column_default(rel,i+1);
841-
if (defexprs[num_defaults]!=NULL)
840+
Node*defexpr=build_column_default(rel,i+1);
841+
842+
if (defexpr!=NULL)
842843
{
843-
fix_opfuncids(defexprs[num_defaults]);
844+
fix_opfuncids(defexpr);
845+
defexprs[num_defaults]=ExecInitExpr((Expr*)defexpr,NULL);
844846
defmap[num_defaults]=i;
845847
num_defaults++;
846848
}
@@ -872,7 +874,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
872874
if (node!= (Node*)prm)
873875
{
874876
fix_opfuncids(node);
875-
constraintexprs[i]=node;
877+
constraintexprs[i]=ExecInitExpr((Expr*)node,NULL);
876878
hasConstraints= true;
877879
}
878880
}
@@ -1165,10 +1167,10 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
11651167

11661168
for (i=0;i<num_phys_attrs;i++)
11671169
{
1168-
Node*node=constraintexprs[i];
1170+
ExprState*exprstate=constraintexprs[i];
11691171
boolisnull;
11701172

1171-
if (node==NULL)
1173+
if (exprstate==NULL)
11721174
continue;/* no constraint for this attr */
11731175

11741176
/* Insert current row's value into the Param value */
@@ -1180,7 +1182,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
11801182
* to replace the value (consider e.g. a timestamp precision
11811183
* restriction).
11821184
*/
1183-
values[i]=ExecEvalExpr(node,econtext,
1185+
values[i]=ExecEvalExpr(exprstate,econtext,
11841186
&isnull,NULL);
11851187
nulls[i]=isnull ?'n' :' ';
11861188
}

‎src/backend/commands/explain.c

Lines changed: 9 additions & 11 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.96 2002/12/12 15:49:24 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.97 2002/12/13 19:45:49 tgl Exp $
99
*
1010
*/
1111

@@ -582,26 +582,24 @@ explain_outNode(StringInfo str,
582582
if (plan->initPlan)
583583
{
584584
List*saved_rtable=es->rtable;
585-
List*pslist=planstate->initPlan;
586585
List*lst;
587586

588587
for (i=0;i<indent;i++)
589588
appendStringInfo(str," ");
590589
appendStringInfo(str," InitPlan\n");
591-
foreach(lst,plan->initPlan)
590+
foreach(lst,planstate->initPlan)
592591
{
593-
SubPlanExpr*subplan= (SubPlanExpr*)lfirst(lst);
594-
SubPlanState*subplanstate= (SubPlanState*)lfirst(pslist);
592+
SubPlanExprState*sps= (SubPlanExprState*)lfirst(lst);
593+
SubPlanExpr*sp= (SubPlanExpr*)sps->xprstate.expr;
595594

596-
es->rtable=subplan->rtable;
595+
es->rtable=sp->rtable;
597596
for (i=0;i<indent;i++)
598597
appendStringInfo(str," ");
599598
appendStringInfo(str," -> ");
600-
explain_outNode(str,subplan->plan,
601-
subplanstate->planstate,
599+
explain_outNode(str,sp->plan,
600+
sps->planstate,
602601
NULL,
603602
indent+4,es);
604-
pslist=lnext(pslist);
605603
}
606604
es->rtable=saved_rtable;
607605
}
@@ -689,8 +687,8 @@ explain_outNode(StringInfo str,
689687
appendStringInfo(str," SubPlan\n");
690688
foreach(lst,planstate->subPlan)
691689
{
692-
SubPlanState*sps= (SubPlanState*)lfirst(lst);
693-
SubPlanExpr*sp= (SubPlanExpr*)sps->ps.plan;
690+
SubPlanExprState*sps= (SubPlanExprState*)lfirst(lst);
691+
SubPlanExpr*sp= (SubPlanExpr*)sps->xprstate.expr;
694692

695693
es->rtable=sp->rtable;
696694
for (i=0;i<indent;i++)

‎src/backend/commands/indexcmds.c

Lines changed: 4 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/commands/indexcmds.c,v 1.93 2002/12/12 15:49:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.94 2002/12/13 19:45:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -24,6 +24,7 @@
2424
#include"catalog/pg_opclass.h"
2525
#include"catalog/pg_proc.h"
2626
#include"commands/defrem.h"
27+
#include"executor/executor.h"
2728
#include"miscadmin.h"
2829
#include"optimizer/clauses.h"
2930
#include"optimizer/planmain.h"
@@ -172,6 +173,8 @@ DefineIndex(RangeVar *heapRelation,
172173
*/
173174
indexInfo=makeNode(IndexInfo);
174175
indexInfo->ii_Predicate=cnfPred;
176+
indexInfo->ii_PredicateState= (List*)
177+
ExecInitExpr((Expr*)cnfPred,NULL);
175178
indexInfo->ii_FuncOid=InvalidOid;
176179
indexInfo->ii_Unique=unique;
177180

‎src/backend/commands/prepare.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2002, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.9 2002/12/05 15:50:30 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.10 2002/12/13 19:45:51 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -15,6 +15,7 @@
1515
#include"commands/prepare.h"
1616
#include"executor/executor.h"
1717
#include"utils/guc.h"
18+
#include"optimizer/planmain.h"
1819
#include"optimizer/planner.h"
1920
#include"rewrite/rewriteHandler.h"
2021
#include"tcop/pquery.h"
@@ -110,17 +111,22 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest)
110111
{
111112
intnargs=length(entry->argtype_list);
112113
inti=0;
114+
List*exprstates;
113115
ExprContext*econtext=MakeExprContext(NULL,CurrentMemoryContext);
114116

115117
/* Parser should have caught this error, but check */
116118
if (nargs!=length(stmt->params))
117119
elog(ERROR,"ExecuteQuery: wrong number of arguments");
118120

121+
fix_opfuncids((Node*)stmt->params);
122+
123+
exprstates= (List*)ExecInitExpr((Expr*)stmt->params,NULL);
124+
119125
paramLI= (ParamListInfo)palloc0((nargs+1)*sizeof(ParamListInfoData));
120126

121-
foreach(l,stmt->params)
127+
foreach(l,exprstates)
122128
{
123-
Node*n=lfirst(l);
129+
ExprState*n=lfirst(l);
124130
boolisNull;
125131

126132
paramLI[i].value=ExecEvalExprSwitchContext(n,

‎src/backend/commands/tablecmds.c

Lines changed: 7 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/commands/tablecmds.c,v 1.59 2002/12/12 20:35:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.60 2002/12/13 19:45:51 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2718,6 +2718,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27182718
HeapTupletuple;
27192719
RangeTblEntry*rte;
27202720
List*qual;
2721+
List*qualstate;
27212722
Node*expr;
27222723

27232724
/*
@@ -2769,6 +2770,9 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27692770

27702771
qual=makeList1(expr);
27712772

2773+
/* build execution state for qual */
2774+
qualstate= (List*)ExecInitExpr((Expr*)qual,NULL);
2775+
27722776
/* Make tuple slot to hold tuples */
27732777
slot=MakeTupleTableSlot();
27742778
ExecSetSlotDescriptor(slot,RelationGetDescr(rel), false);
@@ -2783,7 +2787,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
27832787
while ((tuple=heap_getnext(scan,ForwardScanDirection))!=NULL)
27842788
{
27852789
ExecStoreTuple(tuple,slot,InvalidBuffer, false);
2786-
if (!ExecQual(qual,econtext, true))
2790+
if (!ExecQual(qualstate,econtext, true))
27872791
{
27882792
successful= false;
27892793
break;
@@ -3820,6 +3824,7 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
38203824
indexInfo->ii_KeyAttrNumbers[0]=1;
38213825
indexInfo->ii_KeyAttrNumbers[1]=2;
38223826
indexInfo->ii_Predicate=NIL;
3827+
indexInfo->ii_PredicateState=NIL;
38233828
indexInfo->ii_FuncOid=InvalidOid;
38243829
indexInfo->ii_Unique= true;
38253830

‎src/backend/commands/typecmds.c

Lines changed: 8 additions & 6 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.23 2002/12/12 20:35:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.24 2002/12/13 19:45:52 tgl Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -1244,7 +1244,8 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
12441244
Form_pg_typetypTup;
12451245
ExprContext*econtext;
12461246
char*ccbin;
1247-
Node*expr;
1247+
Expr*expr;
1248+
ExprState*exprstate;
12481249
intcounter=0;
12491250
Constraint*constr;
12501251

@@ -1336,10 +1337,11 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
13361337
* Test all values stored in the attributes based on the domain
13371338
* the constraint is being added to.
13381339
*/
1339-
expr=stringToNode(ccbin);
1340-
fix_opfuncids(expr);
1340+
expr= (Expr*)stringToNode(ccbin);
1341+
fix_opfuncids((Node*)expr);
1342+
exprstate=ExecInitExpr(expr,NULL);
13411343

1342-
/* Make an expression context forExecQual */
1344+
/* Make an expression context forExecEvalExpr */
13431345
econtext=MakeExprContext(NULL,CurrentMemoryContext);
13441346

13451347
rels=get_rels_with_domain(domainoid);
@@ -1375,7 +1377,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
13751377
econtext->domainValue_datum=d;
13761378
econtext->domainValue_isNull=isNull;
13771379

1378-
conResult=ExecEvalExpr(expr,econtext,&isNull,NULL);
1380+
conResult=ExecEvalExpr(exprstate,econtext,&isNull,NULL);
13791381

13801382
if (!isNull&& !DatumGetBool(conResult))
13811383
elog(ERROR,"AlterDomainAddConstraint: Domain %s constraint %s failed",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp