diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index ff8555e39d..9df08908c2 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -6,7 +6,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.71 1999/02/03 21:16:03 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.72 1999/02/07 16:17:10 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -505,6 +505,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) Node **indexPred = NULL; TupleDesc rtupdesc; ExprContext *econtext = NULL; + EState *estate = makeNode(EState); /* for ExecConstraints() */ #ifndef OMIT_PARTIAL_INDEX TupleTable tupleTable; @@ -805,7 +806,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim) */ if (rel->rd_att->constr) - ExecConstraints("CopyFrom", rel, tuple); + ExecConstraints("CopyFrom", rel, tuple, estate); heap_insert(rel, tuple); diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index d511e5f6e5..5ce90902b4 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.74 1999/02/07 14:20:11 wieck Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.75 1999/02/07 16:17:11 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -1124,7 +1124,7 @@ ExecAppend(TupleTableSlot *slot, if (resultRelationDesc->rd_att->constr) { - ExecConstraints("ExecAppend", resultRelationDesc, tuple); + ExecConstraints("ExecAppend", resultRelationDesc, tuple, estate); } /****************** @@ -1327,7 +1327,7 @@ ExecReplace(TupleTableSlot *slot, if (resultRelationDesc->rd_att->constr) { - ExecConstraints("ExecReplace", resultRelationDesc, tuple); + ExecConstraints("ExecReplace", resultRelationDesc, tuple, estate); } /* @@ -1472,7 +1472,7 @@ ExecAttrDefault(Relation rel, HeapTuple tuple) #endif static char * -ExecRelCheck(Relation rel, HeapTuple tuple) +ExecRelCheck(Relation rel, HeapTuple tuple, EState *estate) { int ncheck = rel->rd_att->constr->num_check; ConstrCheck *check = rel->rd_att->constr->check; @@ -1505,14 +1505,24 @@ ExecRelCheck(Relation rel, HeapTuple tuple) econtext->ecxt_param_exec_vals = NULL; /* exec param values */ econtext->ecxt_range_table = rtlist; /* range table */ + if (estate->es_result_relation_constraints == NULL) + { + estate->es_result_relation_constraints = + (List **)palloc(ncheck * sizeof(List *)); + + for (i = 0; i < ncheck; i++) + { + qual = (List *) stringToNode(check[i].ccbin); + estate->es_result_relation_constraints[i] = qual; + } + } + for (i = 0; i < ncheck; i++) { - qual = (List *) stringToNode(check[i].ccbin); + qual = estate->es_result_relation_constraints[i]; res = ExecQual(qual, econtext); - freeObject(qual); - if (!res) return check[i].ccname; } @@ -1528,7 +1538,7 @@ ExecRelCheck(Relation rel, HeapTuple tuple) } void -ExecConstraints(char *caller, Relation rel, HeapTuple tuple) +ExecConstraints(char *caller, Relation rel, HeapTuple tuple, EState *estate) { Assert(rel->rd_att->constr); @@ -1549,7 +1559,7 @@ ExecConstraints(char *caller, Relation rel, HeapTuple tuple) { char *failed; - if ((failed = ExecRelCheck(rel, tuple)) != NULL) + if ((failed = ExecRelCheck(rel, tuple, estate)) != NULL) elog(ERROR, "%s: rejected due to CHECK constraint %s", caller, failed); } diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h index 33774d21f4..68d89897d0 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: executor.h,v 1.28 1998/11/27 19:33:32 vadim Exp $ + * $Id: executor.h,v 1.29 1999/02/07 16:17:12 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -85,7 +85,8 @@ extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot); extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate); extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count); extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate); -extern void ExecConstraints(char *caller, Relation rel, HeapTuple tuple); +extern void ExecConstraints(char *caller, Relation rel, HeapTuple tuple, + EState *estate); #ifdef QUERY_LIMIT extern int ExecutorLimit(int limit); extern int ExecutorGetLimit(void); diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index d9cdd2509d..45625c62e7 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: execnodes.h,v 1.22 1999/01/29 09:23:13 vadim Exp $ + * $Id: execnodes.h,v 1.23 1999/02/07 16:17:14 wieck Exp $ * *------------------------------------------------------------------------- */ @@ -199,6 +199,7 @@ typedef struct EState Snapshot es_snapshot; List *es_range_table; RelationInfo *es_result_relation_info; + List **es_result_relation_constraints; Relation es_into_relation_descriptor; ParamListInfo es_param_list_info; ParamExecData *es_param_exec_vals; /* this is for subselects */