mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Phase 3 of read-only-plans project: ExecInitExpr now builds expression
execution state trees, and ExecEvalExpr takes an expression state tree not an expression plan tree. The plan tree is now read-only as far as the executor is concerned. Next step is to begin actually exploiting this property.
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.185 2002/12/12 15:49:24 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.186 2002/12/13 19:45:48 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -758,7 +758,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
num_defaults;
|
||||
FmgrInfo *in_functions;
|
||||
Oid *elements;
|
||||
Node **constraintexprs;
|
||||
ExprState **constraintexprs;
|
||||
bool hasConstraints = false;
|
||||
int i;
|
||||
List *cur;
|
||||
@ -772,7 +772,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
TupleTableSlot *slot;
|
||||
bool file_has_oids;
|
||||
int *defmap;
|
||||
Node **defexprs; /* array of default att expressions */
|
||||
ExprState **defexprs; /* array of default att expressions */
|
||||
ExprContext *econtext; /* used for ExecEvalExpr for default atts */
|
||||
MemoryContext oldcontext = CurrentMemoryContext;
|
||||
|
||||
@ -812,8 +812,8 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
in_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
|
||||
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
|
||||
defexprs = (Node **) palloc(num_phys_attrs * sizeof(Node *));
|
||||
constraintexprs = (Node **) palloc0(num_phys_attrs * sizeof(Node *));
|
||||
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
|
||||
constraintexprs = (ExprState **) palloc0(num_phys_attrs * sizeof(ExprState *));
|
||||
|
||||
for (i = 0; i < num_phys_attrs; i++)
|
||||
{
|
||||
@ -837,10 +837,12 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
{
|
||||
/* attribute is NOT to be copied */
|
||||
/* use default value if one exists */
|
||||
defexprs[num_defaults] = build_column_default(rel, i + 1);
|
||||
if (defexprs[num_defaults] != NULL)
|
||||
Node *defexpr = build_column_default(rel, i + 1);
|
||||
|
||||
if (defexpr != NULL)
|
||||
{
|
||||
fix_opfuncids(defexprs[num_defaults]);
|
||||
fix_opfuncids(defexpr);
|
||||
defexprs[num_defaults] = ExecInitExpr((Expr *) defexpr, NULL);
|
||||
defmap[num_defaults] = i;
|
||||
num_defaults++;
|
||||
}
|
||||
@ -872,7 +874,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
if (node != (Node *) prm)
|
||||
{
|
||||
fix_opfuncids(node);
|
||||
constraintexprs[i] = node;
|
||||
constraintexprs[i] = ExecInitExpr((Expr *) node, NULL);
|
||||
hasConstraints = true;
|
||||
}
|
||||
}
|
||||
@ -1165,10 +1167,10 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
|
||||
for (i = 0; i < num_phys_attrs; i++)
|
||||
{
|
||||
Node *node = constraintexprs[i];
|
||||
ExprState *exprstate = constraintexprs[i];
|
||||
bool isnull;
|
||||
|
||||
if (node == NULL)
|
||||
if (exprstate == NULL)
|
||||
continue; /* no constraint for this attr */
|
||||
|
||||
/* Insert current row's value into the Param value */
|
||||
@ -1180,7 +1182,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
|
||||
* to replace the value (consider e.g. a timestamp precision
|
||||
* restriction).
|
||||
*/
|
||||
values[i] = ExecEvalExpr(node, econtext,
|
||||
values[i] = ExecEvalExpr(exprstate, econtext,
|
||||
&isnull, NULL);
|
||||
nulls[i] = isnull ? 'n' : ' ';
|
||||
}
|
||||
|
@ -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.96 2002/12/12 15:49:24 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.97 2002/12/13 19:45:49 tgl Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -582,26 +582,24 @@ explain_outNode(StringInfo str,
|
||||
if (plan->initPlan)
|
||||
{
|
||||
List *saved_rtable = es->rtable;
|
||||
List *pslist = planstate->initPlan;
|
||||
List *lst;
|
||||
|
||||
for (i = 0; i < indent; i++)
|
||||
appendStringInfo(str, " ");
|
||||
appendStringInfo(str, " InitPlan\n");
|
||||
foreach(lst, plan->initPlan)
|
||||
foreach(lst, planstate->initPlan)
|
||||
{
|
||||
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(lst);
|
||||
SubPlanState *subplanstate = (SubPlanState *) lfirst(pslist);
|
||||
SubPlanExprState *sps = (SubPlanExprState *) lfirst(lst);
|
||||
SubPlanExpr *sp = (SubPlanExpr *) sps->xprstate.expr;
|
||||
|
||||
es->rtable = subplan->rtable;
|
||||
es->rtable = sp->rtable;
|
||||
for (i = 0; i < indent; i++)
|
||||
appendStringInfo(str, " ");
|
||||
appendStringInfo(str, " -> ");
|
||||
explain_outNode(str, subplan->plan,
|
||||
subplanstate->planstate,
|
||||
explain_outNode(str, sp->plan,
|
||||
sps->planstate,
|
||||
NULL,
|
||||
indent + 4, es);
|
||||
pslist = lnext(pslist);
|
||||
}
|
||||
es->rtable = saved_rtable;
|
||||
}
|
||||
@ -689,8 +687,8 @@ explain_outNode(StringInfo str,
|
||||
appendStringInfo(str, " SubPlan\n");
|
||||
foreach(lst, planstate->subPlan)
|
||||
{
|
||||
SubPlanState *sps = (SubPlanState *) lfirst(lst);
|
||||
SubPlanExpr *sp = (SubPlanExpr *) sps->ps.plan;
|
||||
SubPlanExprState *sps = (SubPlanExprState *) lfirst(lst);
|
||||
SubPlanExpr *sp = (SubPlanExpr *) sps->xprstate.expr;
|
||||
|
||||
es->rtable = sp->rtable;
|
||||
for (i = 0; i < indent; i++)
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.93 2002/12/12 15:49:24 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.94 2002/12/13 19:45:50 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -24,6 +24,7 @@
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "executor/executor.h"
|
||||
#include "miscadmin.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "optimizer/planmain.h"
|
||||
@ -172,6 +173,8 @@ DefineIndex(RangeVar *heapRelation,
|
||||
*/
|
||||
indexInfo = makeNode(IndexInfo);
|
||||
indexInfo->ii_Predicate = cnfPred;
|
||||
indexInfo->ii_PredicateState = (List *)
|
||||
ExecInitExpr((Expr *) cnfPred, NULL);
|
||||
indexInfo->ii_FuncOid = InvalidOid;
|
||||
indexInfo->ii_Unique = unique;
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Copyright (c) 2002, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.9 2002/12/05 15:50:30 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/prepare.c,v 1.10 2002/12/13 19:45:51 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -15,6 +15,7 @@
|
||||
#include "commands/prepare.h"
|
||||
#include "executor/executor.h"
|
||||
#include "utils/guc.h"
|
||||
#include "optimizer/planmain.h"
|
||||
#include "optimizer/planner.h"
|
||||
#include "rewrite/rewriteHandler.h"
|
||||
#include "tcop/pquery.h"
|
||||
@ -110,17 +111,22 @@ ExecuteQuery(ExecuteStmt *stmt, CommandDest outputDest)
|
||||
{
|
||||
int nargs = length(entry->argtype_list);
|
||||
int i = 0;
|
||||
List *exprstates;
|
||||
ExprContext *econtext = MakeExprContext(NULL, CurrentMemoryContext);
|
||||
|
||||
/* Parser should have caught this error, but check */
|
||||
if (nargs != length(stmt->params))
|
||||
elog(ERROR, "ExecuteQuery: wrong number of arguments");
|
||||
|
||||
fix_opfuncids((Node *) stmt->params);
|
||||
|
||||
exprstates = (List *) ExecInitExpr((Expr *) stmt->params, NULL);
|
||||
|
||||
paramLI = (ParamListInfo) palloc0((nargs + 1) * sizeof(ParamListInfoData));
|
||||
|
||||
foreach(l, stmt->params)
|
||||
foreach(l, exprstates)
|
||||
{
|
||||
Node *n = lfirst(l);
|
||||
ExprState *n = lfirst(l);
|
||||
bool isNull;
|
||||
|
||||
paramLI[i].value = ExecEvalExprSwitchContext(n,
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.59 2002/12/12 20:35:12 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.60 2002/12/13 19:45:51 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -2718,6 +2718,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
|
||||
HeapTuple tuple;
|
||||
RangeTblEntry *rte;
|
||||
List *qual;
|
||||
List *qualstate;
|
||||
Node *expr;
|
||||
|
||||
/*
|
||||
@ -2769,6 +2770,9 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
|
||||
|
||||
qual = makeList1(expr);
|
||||
|
||||
/* build execution state for qual */
|
||||
qualstate = (List *) ExecInitExpr((Expr *) qual, NULL);
|
||||
|
||||
/* Make tuple slot to hold tuples */
|
||||
slot = MakeTupleTableSlot();
|
||||
ExecSetSlotDescriptor(slot, RelationGetDescr(rel), false);
|
||||
@ -2783,7 +2787,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr)
|
||||
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
|
||||
{
|
||||
ExecStoreTuple(tuple, slot, InvalidBuffer, false);
|
||||
if (!ExecQual(qual, econtext, true))
|
||||
if (!ExecQual(qualstate, econtext, true))
|
||||
{
|
||||
successful = false;
|
||||
break;
|
||||
@ -3820,6 +3824,7 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
|
||||
indexInfo->ii_KeyAttrNumbers[0] = 1;
|
||||
indexInfo->ii_KeyAttrNumbers[1] = 2;
|
||||
indexInfo->ii_Predicate = NIL;
|
||||
indexInfo->ii_PredicateState = NIL;
|
||||
indexInfo->ii_FuncOid = InvalidOid;
|
||||
indexInfo->ii_Unique = true;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.23 2002/12/12 20:35:12 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.24 2002/12/13 19:45:52 tgl Exp $
|
||||
*
|
||||
* DESCRIPTION
|
||||
* The "DefineFoo" routines take the parse tree and pick out the
|
||||
@ -1244,7 +1244,8 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
Form_pg_type typTup;
|
||||
ExprContext *econtext;
|
||||
char *ccbin;
|
||||
Node *expr;
|
||||
Expr *expr;
|
||||
ExprState *exprstate;
|
||||
int counter = 0;
|
||||
Constraint *constr;
|
||||
|
||||
@ -1336,10 +1337,11 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
* Test all values stored in the attributes based on the domain
|
||||
* the constraint is being added to.
|
||||
*/
|
||||
expr = stringToNode(ccbin);
|
||||
fix_opfuncids(expr);
|
||||
expr = (Expr *) stringToNode(ccbin);
|
||||
fix_opfuncids((Node *) expr);
|
||||
exprstate = ExecInitExpr(expr, NULL);
|
||||
|
||||
/* Make an expression context for ExecQual */
|
||||
/* Make an expression context for ExecEvalExpr */
|
||||
econtext = MakeExprContext(NULL, CurrentMemoryContext);
|
||||
|
||||
rels = get_rels_with_domain(domainoid);
|
||||
@ -1375,7 +1377,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
|
||||
econtext->domainValue_datum = d;
|
||||
econtext->domainValue_isNull = isNull;
|
||||
|
||||
conResult = ExecEvalExpr(expr, econtext, &isNull, NULL);
|
||||
conResult = ExecEvalExpr(exprstate, econtext, &isNull, NULL);
|
||||
|
||||
if (!isNull && !DatumGetBool(conResult))
|
||||
elog(ERROR, "AlterDomainAddConstraint: Domain %s constraint %s failed",
|
||||
|
Reference in New Issue
Block a user