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

Commitcff91fe

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Changed ExecConstraints() and ExecRelCheck() to cache constraint
qualification trees in the execution state to avoid memory exhaustionon INSERT, UPDATE and COPY to tables with check constraints. Thisalso speeds up those operations substantial because the nodeToString()for the constraints ccbin is only performed once per query.Jan
1 parentccf330d commitcff91fe

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

‎src/backend/commands/copy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.63 1998/10/26 00:59:21 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.63.2.1 1999/02/07 16:50:51 wieck Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -402,6 +402,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
402402
Node**indexPred=NULL;
403403
TupleDescrtupdesc;
404404
ExprContext*econtext=NULL;
405+
EState*estate=makeNode(EState);
405406

406407
#ifndefOMIT_PARTIAL_INDEX
407408
TupleTabletupleTable;
@@ -709,7 +710,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
709710
{
710711
HeapTuplenewtuple;
711712

712-
newtuple=ExecConstraints("CopyFrom",rel,tuple);
713+
newtuple=ExecConstraints("CopyFrom",rel,tuple,estate);
713714

714715
if (newtuple!=tuple)
715716
{

‎src/backend/executor/execMain.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.58 1998/10/14 05:10:00 momjian Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.58.2.1 1999/02/07 16:50:52 wieck Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -965,7 +965,8 @@ ExecAppend(TupleTableSlot *slot,
965965
{
966966
HeapTuplenewtuple;
967967

968-
newtuple=ExecConstraints("ExecAppend",resultRelationDesc,tuple);
968+
newtuple=ExecConstraints("ExecAppend",resultRelationDesc,
969+
tuple,estate);
969970

970971
if (newtuple!=tuple)/* modified by DEFAULT */
971972
{
@@ -1148,7 +1149,8 @@ ExecReplace(TupleTableSlot *slot,
11481149
{
11491150
HeapTuplenewtuple;
11501151

1151-
newtuple=ExecConstraints("ExecReplace",resultRelationDesc,tuple);
1152+
newtuple=ExecConstraints("ExecReplace",resultRelationDesc,
1153+
tuple,estate);
11521154

11531155
if (newtuple!=tuple)/* modified by DEFAULT */
11541156
{
@@ -1279,7 +1281,7 @@ ExecAttrDefault(Relation rel, HeapTuple tuple)
12791281
#endif
12801282

12811283
staticchar*
1282-
ExecRelCheck(Relationrel,HeapTupletuple)
1284+
ExecRelCheck(Relationrel,HeapTupletuple,EState*estate)
12831285
{
12841286
intncheck=rel->rd_att->constr->num_check;
12851287
ConstrCheck*check=rel->rd_att->constr->check;
@@ -1312,14 +1314,24 @@ ExecRelCheck(Relation rel, HeapTuple tuple)
13121314
econtext->ecxt_param_exec_vals=NULL;/* exec param values */
13131315
econtext->ecxt_range_table=rtlist;/* range table */
13141316

1317+
if (estate->es_result_relation_constraints==NULL)
1318+
{
1319+
estate->es_result_relation_constraints=
1320+
(List**)palloc(ncheck*sizeof(List*));
1321+
1322+
for (i=0;i<ncheck;i++)
1323+
{
1324+
qual= (List*)stringToNode(check[i].ccbin);
1325+
estate->es_result_relation_constraints[i]=qual;
1326+
}
1327+
}
1328+
13151329
for (i=0;i<ncheck;i++)
13161330
{
1317-
qual=(List*)stringToNode(check[i].ccbin);
1331+
qual=estate->es_result_relation_constraints[i];
13181332

13191333
res=ExecQual(qual,econtext);
13201334

1321-
pfree(qual);
1322-
13231335
if (!res)
13241336
returncheck[i].ccname;
13251337
}
@@ -1335,7 +1347,7 @@ ExecRelCheck(Relation rel, HeapTuple tuple)
13351347
}
13361348

13371349
HeapTuple
1338-
ExecConstraints(char*caller,Relationrel,HeapTupletuple)
1350+
ExecConstraints(char*caller,Relationrel,HeapTupletuple,EState*estate)
13391351
{
13401352
HeapTuplenewtuple=tuple;
13411353

@@ -1362,7 +1374,7 @@ ExecConstraints(char *caller, Relation rel, HeapTuple tuple)
13621374
{
13631375
char*failed;
13641376

1365-
if ((failed=ExecRelCheck(rel,tuple))!=NULL)
1377+
if ((failed=ExecRelCheck(rel,tuple,estate))!=NULL)
13661378
elog(ERROR,"%s: rejected due to CHECK constraint %s",caller,failed);
13671379
}
13681380

‎src/include/executor/executor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: executor.h,v 1.27 1998/10/14 05:10:05 momjian Exp $
9+
* $Id: executor.h,v 1.27.2.1 1999/02/07 16:50:54 wieck Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -85,7 +85,8 @@ extern HeapTuple ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot);
8585
externTupleDescExecutorStart(QueryDesc*queryDesc,EState*estate);
8686
externTupleTableSlot*ExecutorRun(QueryDesc*queryDesc,EState*estate,intfeature,intcount);
8787
externvoidExecutorEnd(QueryDesc*queryDesc,EState*estate);
88-
externHeapTupleExecConstraints(char*caller,Relationrel,HeapTupletuple);
88+
externHeapTupleExecConstraints(char*caller,Relationrel,HeapTupletuple,
89+
EState*estate);
8990
#ifdefQUERY_LIMIT
9091
externintExecutorLimit(intlimit);
9192
externintExecutorGetLimit(void);

‎src/include/nodes/execnodes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: execnodes.h,v 1.18 1998/09/01 04:36:35 momjian Exp $
9+
* $Id: execnodes.h,v 1.18.2.1 1999/02/07 16:50:55 wieck Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -199,6 +199,7 @@ typedef struct EState
199199
Snapshotes_snapshot;
200200
List*es_range_table;
201201
RelationInfo*es_result_relation_info;
202+
List**es_result_relation_constraints;
202203
Relationes_into_relation_descriptor;
203204
ParamListInfoes_param_list_info;
204205
ParamExecData*es_param_exec_vals;/* this is for subselects */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp