diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-15 16:17:59 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-12-15 16:17:59 +0000 |
| commit | 5bab36e9f6c3f3a9e14a89e1124179a339d2c3a1 (patch) | |
| tree | a05154b129808efc7882599d96a1132051c2403b /src/backend/commands/tablecmds.c | |
| parent | 90b3a0b6fd3bc74804c01156491635e5d95091d9 (diff) | |
| download | postgresql-5bab36e9f6c3f3a9e14a89e1124179a339d2c3a1.tar.gz | |
Revise executor APIs so that all per-query state structure is built in
a per-query memory context created by CreateExecutorState --- and destroyed
by FreeExecutorState. This provides a final solution to the longstanding
problem of memory leaked by various ExecEndNode calls.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
| -rw-r--r-- | src/backend/commands/tablecmds.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index a7a19c6f74..09c60bdf3f 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.60 2002/12/13 19:45:51 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.61 2002/12/15 16:17:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -37,7 +37,6 @@ #include "nodes/makefuncs.h" #include "optimizer/clauses.h" #include "optimizer/plancat.h" -#include "optimizer/planmain.h" #include "optimizer/prep.h" #include "parser/gramparse.h" #include "parser/parse_coerce.h" @@ -2713,6 +2712,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr) ParseState *pstate; bool successful = true; HeapScanDesc scan; + EState *estate; ExprContext *econtext; TupleTableSlot *slot; HeapTuple tuple; @@ -2723,9 +2723,7 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr) /* * We need to make a parse state and range - * table to allow us to transformExpr and - * fix_opfuncids to get a version of the - * expression we can pass to ExecQual + * table to allow us to do transformExpr() */ pstate = make_parsestate(NULL); rte = addRangeTableEntryForRelation(pstate, @@ -2765,19 +2763,22 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr) */ expr = eval_const_expressions(expr); - /* And fix the opfuncids */ - fix_opfuncids(expr); + /* Needs to be in implicit-ANDs form for ExecQual */ + qual = make_ands_implicit((Expr *) expr); - qual = makeList1(expr); + /* Need an EState to run ExecQual */ + estate = CreateExecutorState(); + econtext = GetPerTupleExprContext(estate); /* build execution state for qual */ - qualstate = (List *) ExecInitExpr((Expr *) qual, NULL); + qualstate = (List *) ExecPrepareExpr((Expr *) qual, estate); /* Make tuple slot to hold tuples */ slot = MakeTupleTableSlot(); ExecSetSlotDescriptor(slot, RelationGetDescr(rel), false); - /* Make an expression context for ExecQual */ - econtext = MakeExprContext(slot, CurrentMemoryContext); + + /* Arrange for econtext's scan tuple to be the tuple under test */ + econtext->ecxt_scantuple = slot; /* * Scan through the rows now, checking the expression at each row. @@ -2797,8 +2798,8 @@ AlterTableAddCheckConstraint(Relation rel, Constraint *constr) heap_endscan(scan); - FreeExprContext(econtext); pfree(slot); + FreeExecutorState(estate); if (!successful) elog(ERROR, "AlterTableAddConstraint: rejected due to CHECK constraint %s", |
