execUtils.c 18.5 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * execUtils.c
4
 *	  miscellaneous executor utility routines
5
 *
6
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
B
Add:  
Bruce Momjian 已提交
7
 * Portions Copyright (c) 1994, Regents of the University of California
8 9 10
 *
 *
 * IDENTIFICATION
11
 *	  $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.78 2001/10/25 05:49:27 momjian Exp $
12 13 14 15 16
 *
 *-------------------------------------------------------------------------
 */
/*
 * INTERFACE ROUTINES
17
 *		ExecAssignExprContext	Common code for plan node init routines.
18
 *
19 20 21
 *		ExecOpenIndices			\
 *		ExecCloseIndices		 | referenced by InitPlan, EndPlan,
 *		ExecInsertIndexTuples	/  ExecAppend, ExecReplace
22 23 24 25
 *
 *	 NOTES
 *		This file has traditionally been the place to stick misc.
 *		executor support stuff that doesn't really go anyplace else.
26 27 28
 *
 */

29 30
#include "postgres.h"

31
#include "access/genam.h"
B
Bruce Momjian 已提交
32
#include "access/heapam.h"
33
#include "catalog/catname.h"
B
Bruce Momjian 已提交
34
#include "catalog/index.h"
H
Hiroshi Inoue 已提交
35
#include "catalog/catalog.h"
B
Bruce Momjian 已提交
36
#include "catalog/pg_index.h"
B
Bruce Momjian 已提交
37
#include "executor/execdebug.h"
H
Hiroshi Inoue 已提交
38
#include "miscadmin.h"
39 40
#include "utils/builtins.h"
#include "utils/fmgroids.h"
41
#include "utils/memutils.h"
42 43
#include "utils/relcache.h"
#include "utils/syscache.h"
44

45

46
/* ----------------------------------------------------------------
47 48
 *		global counters for number of tuples processed, retrieved,
 *		appended, replaced, deleted.
49 50
 * ----------------------------------------------------------------
 */
51 52 53 54 55 56 57
int			NTupleProcessed;
int			NTupleRetrieved;
int			NTupleReplaced;
int			NTupleAppended;
int			NTupleDeleted;
int			NIndexTupleInserted;
extern int	NIndexTupleProcessed;		/* have to be defined in the
58 59
										 * access method level so that the
										 * cinterface.a will link ok. */
60 61

/* ----------------------------------------------------------------
62
 *						statistic functions
63 64 65 66
 * ----------------------------------------------------------------
 */

/* ----------------------------------------------------------------
67
 *		ResetTupleCount
68 69
 * ----------------------------------------------------------------
 */
70
#ifdef NOT_USED
71
void
72
ResetTupleCount(void)
73
{
74 75 76 77 78 79
	NTupleProcessed = 0;
	NTupleRetrieved = 0;
	NTupleAppended = 0;
	NTupleDeleted = 0;
	NTupleReplaced = 0;
	NIndexTupleProcessed = 0;
80
}
81
#endif
82 83

/* ----------------------------------------------------------------
84
 *		PrintTupleCount
85 86
 * ----------------------------------------------------------------
 */
87
#ifdef NOT_USED
88
void
89
DisplayTupleCount(FILE *statfp)
90
{
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	if (NTupleProcessed > 0)
		fprintf(statfp, "!\t%d tuple%s processed, ", NTupleProcessed,
				(NTupleProcessed == 1) ? "" : "s");
	else
	{
		fprintf(statfp, "!\tno tuples processed.\n");
		return;
	}
	if (NIndexTupleProcessed > 0)
		fprintf(statfp, "%d indextuple%s processed, ", NIndexTupleProcessed,
				(NIndexTupleProcessed == 1) ? "" : "s");
	if (NIndexTupleInserted > 0)
		fprintf(statfp, "%d indextuple%s inserted, ", NIndexTupleInserted,
				(NIndexTupleInserted == 1) ? "" : "s");
	if (NTupleRetrieved > 0)
		fprintf(statfp, "%d tuple%s retrieved. ", NTupleRetrieved,
				(NTupleRetrieved == 1) ? "" : "s");
	if (NTupleAppended > 0)
		fprintf(statfp, "%d tuple%s appended. ", NTupleAppended,
				(NTupleAppended == 1) ? "" : "s");
	if (NTupleDeleted > 0)
		fprintf(statfp, "%d tuple%s deleted. ", NTupleDeleted,
				(NTupleDeleted == 1) ? "" : "s");
	if (NTupleReplaced > 0)
		fprintf(statfp, "%d tuple%s replaced. ", NTupleReplaced,
				(NTupleReplaced == 1) ? "" : "s");
	fprintf(statfp, "\n");
118
}
119
#endif
120 121

/* ----------------------------------------------------------------
122
 *				 miscellaneous node-init support functions
123
 *
124
 *		ExecAssignExprContext	- assigns the node's expression context
125 126 127 128
 * ----------------------------------------------------------------
 */

/* ----------------
129 130 131 132 133 134
 *		ExecAssignExprContext
 *
 *		This initializes the ExprContext field.  It is only necessary
 *		to do this for nodes which use ExecQual or ExecProject
 *		because those routines depend on econtext.	Other nodes that
 *		don't have to evaluate expressions don't need to do this.
135
 *
136 137
 * Note: we assume CurrentMemoryContext is the correct per-query context.
 * This should be true during plan node initialization.
138 139 140
 * ----------------
 */
void
141
ExecAssignExprContext(EState *estate, CommonState *commonstate)
142
{
143
	ExprContext *econtext = makeNode(ExprContext);
144

145 146 147 148
	econtext->ecxt_scantuple = NULL;
	econtext->ecxt_innertuple = NULL;
	econtext->ecxt_outertuple = NULL;
	econtext->ecxt_per_query_memory = CurrentMemoryContext;
B
Bruce Momjian 已提交
149

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
	/*
	 * Create working memory for expression evaluation in this context.
	 */
	econtext->ecxt_per_tuple_memory =
		AllocSetContextCreate(CurrentMemoryContext,
							  "PlanExprContext",
							  ALLOCSET_DEFAULT_MINSIZE,
							  ALLOCSET_DEFAULT_INITSIZE,
							  ALLOCSET_DEFAULT_MAXSIZE);
	econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
	econtext->ecxt_param_list_info = estate->es_param_list_info;
	econtext->ecxt_aggvalues = NULL;
	econtext->ecxt_aggnulls = NULL;

	commonstate->cs_ExprContext = econtext;
165 166 167
}

/* ----------------
168
 *		MakeExprContext
169
 *
170 171 172 173
 *		Build an expression context for use outside normal plan-node cases.
 *		A fake scan-tuple slot can be supplied (pass NULL if not needed).
 *		A memory context sufficiently long-lived to use as fcache context
 *		must be supplied as well.
174 175
 * ----------------
 */
176 177 178
ExprContext *
MakeExprContext(TupleTableSlot *slot,
				MemoryContext queryContext)
179
{
180
	ExprContext *econtext = makeNode(ExprContext);
181

182 183 184 185
	econtext->ecxt_scantuple = slot;
	econtext->ecxt_innertuple = NULL;
	econtext->ecxt_outertuple = NULL;
	econtext->ecxt_per_query_memory = queryContext;
B
Bruce Momjian 已提交
186

187 188 189 190 191 192
	/*
	 * We make the temporary context a child of current working context,
	 * not of the specified queryContext.  This seems reasonable but I'm
	 * not totally sure about it...
	 *
	 * Expression contexts made via this routine typically don't live long
B
Bruce Momjian 已提交
193 194 195
	 * enough to get reset, so specify a minsize of 0.	That avoids
	 * alloc'ing any memory in the common case where expr eval doesn't use
	 * any.
196 197 198 199 200 201 202 203 204 205 206 207 208 209
	 */
	econtext->ecxt_per_tuple_memory =
		AllocSetContextCreate(CurrentMemoryContext,
							  "TempExprContext",
							  0,
							  ALLOCSET_DEFAULT_INITSIZE,
							  ALLOCSET_DEFAULT_MAXSIZE);
	econtext->ecxt_param_exec_vals = NULL;
	econtext->ecxt_param_list_info = NULL;
	econtext->ecxt_aggvalues = NULL;
	econtext->ecxt_aggnulls = NULL;

	return econtext;
}
210

211 212
/*
 * Free an ExprContext made by MakeExprContext, including the temporary
B
Bruce Momjian 已提交
213
 * context used for expression evaluation.	Note this will cause any
214 215 216 217 218 219 220
 * pass-by-reference expression result to go away!
 */
void
FreeExprContext(ExprContext *econtext)
{
	MemoryContextDelete(econtext->ecxt_per_tuple_memory);
	pfree(econtext);
221 222
}

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
/*
 * Build a per-output-tuple ExprContext for an EState.
 *
 * This is normally invoked via GetPerTupleExprContext() macro.
 */
ExprContext *
MakePerTupleExprContext(EState *estate)
{
	if (estate->es_per_tuple_exprcontext == NULL)
	{
		MemoryContext oldContext;

		oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
		estate->es_per_tuple_exprcontext =
			MakeExprContext(NULL, estate->es_query_cxt);
		MemoryContextSwitchTo(oldContext);
	}
	return estate->es_per_tuple_exprcontext;
}

243
/* ----------------------------------------------------------------
244
 *		Result slot tuple type and ProjectionInfo support
245 246 247 248
 * ----------------------------------------------------------------
 */

/* ----------------
249
 *		ExecAssignResultType
250 251 252
 * ----------------
 */
void
253
ExecAssignResultType(CommonState *commonstate,
254
					 TupleDesc tupDesc, bool shouldFree)
255
{
256
	TupleTableSlot *slot = commonstate->cs_ResultTupleSlot;
257

258
	ExecSetSlotDescriptor(slot, tupDesc, shouldFree);
259 260 261
}

/* ----------------
262
 *		ExecAssignResultTypeFromOuterPlan
263 264 265
 * ----------------
 */
void
266
ExecAssignResultTypeFromOuterPlan(Plan *node, CommonState *commonstate)
267
{
268 269
	Plan	   *outerPlan;
	TupleDesc	tupDesc;
270 271 272 273

	outerPlan = outerPlan(node);
	tupDesc = ExecGetTupType(outerPlan);

274
	ExecAssignResultType(commonstate, tupDesc, false);
275 276 277
}

/* ----------------
278
 *		ExecAssignResultTypeFromTL
279 280 281
 * ----------------
 */
void
282
ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate)
283
{
284
	TupleDesc	tupDesc;
285

286 287
	tupDesc = ExecTypeFromTL(node->targetlist);
	ExecAssignResultType(commonstate, tupDesc, true);
288 289 290
}

/* ----------------
291
 *		ExecGetResultType
292 293 294
 * ----------------
 */
TupleDesc
295
ExecGetResultType(CommonState *commonstate)
296
{
297 298 299
	TupleTableSlot *slot = commonstate->cs_ResultTupleSlot;

	return slot->ttc_tupleDescriptor;
300 301 302
}

/* ----------------
303 304
 *		ExecAssignProjectionInfo
		  forms the projection information from the node's targetlist
305 306 307
 * ----------------
 */
void
308
ExecAssignProjectionInfo(Plan *node, CommonState *commonstate)
309
{
310
	ProjectionInfo *projInfo;
311 312
	List	   *targetList;
	int			len;
313 314 315 316 317 318 319

	targetList = node->targetlist;
	len = ExecTargetListLength(targetList);

	projInfo = makeNode(ProjectionInfo);
	projInfo->pi_targetlist = targetList;
	projInfo->pi_len = len;
320
	projInfo->pi_tupValue = (len <= 0) ? NULL : (Datum *) palloc(sizeof(Datum) * len);
321 322 323 324
	projInfo->pi_exprContext = commonstate->cs_ExprContext;
	projInfo->pi_slot = commonstate->cs_ResultTupleSlot;

	commonstate->cs_ProjInfo = projInfo;
325 326 327 328
}


/* ----------------
329
 *		ExecFreeProjectionInfo
330 331 332
 * ----------------
 */
void
333
ExecFreeProjectionInfo(CommonState *commonstate)
334
{
335 336
	ProjectionInfo *projInfo;

337 338 339
	/*
	 * get projection info.  if NULL then this node has none so we just
	 * return.
340 341 342 343 344
	 */
	projInfo = commonstate->cs_ProjInfo;
	if (projInfo == NULL)
		return;

345 346
	/*
	 * clean up memory used.
347 348 349 350 351 352
	 */
	if (projInfo->pi_tupValue != NULL)
		pfree(projInfo->pi_tupValue);

	pfree(projInfo);
	commonstate->cs_ProjInfo = NULL;
353 354
}

355 356 357 358 359 360 361 362 363
/* ----------------
 *		ExecFreeExprContext
 * ----------------
 */
void
ExecFreeExprContext(CommonState *commonstate)
{
	ExprContext *econtext;

364 365 366
	/*
	 * get expression context.	if NULL then this node has none so we just
	 * return.
367 368 369 370 371
	 */
	econtext = commonstate->cs_ExprContext;
	if (econtext == NULL)
		return;

372 373
	/*
	 * clean up memory used.
374
	 */
375
	MemoryContextDelete(econtext->ecxt_per_tuple_memory);
376 377 378 379
	pfree(econtext);
	commonstate->cs_ExprContext = NULL;
}

380
/* ----------------------------------------------------------------
381 382 383 384 385 386
 *		the following scan type support functions are for
 *		those nodes which are stubborn and return tuples in
 *		their Scan tuple slot instead of their Result tuple
 *		slot..	luck fur us, these nodes do not do projections
 *		so we don't have to worry about getting the ProjectionInfo
 *		right for them...  -cim 6/3/91
387 388 389 390
 * ----------------------------------------------------------------
 */

/* ----------------
391
 *		ExecGetScanType
392 393 394
 * ----------------
 */
TupleDesc
395
ExecGetScanType(CommonScanState *csstate)
396
{
397 398 399
	TupleTableSlot *slot = csstate->css_ScanTupleSlot;

	return slot->ttc_tupleDescriptor;
400 401 402
}

/* ----------------
403
 *		ExecAssignScanType
404 405 406
 * ----------------
 */
void
407
ExecAssignScanType(CommonScanState *csstate,
408
				   TupleDesc tupDesc, bool shouldFree)
409
{
410
	TupleTableSlot *slot = csstate->css_ScanTupleSlot;
411

412
	ExecSetSlotDescriptor(slot, tupDesc, shouldFree);
413 414 415
}

/* ----------------
416
 *		ExecAssignScanTypeFromOuterPlan
417 418 419
 * ----------------
 */
void
420
ExecAssignScanTypeFromOuterPlan(Plan *node, CommonScanState *csstate)
421
{
422 423
	Plan	   *outerPlan;
	TupleDesc	tupDesc;
424 425 426

	outerPlan = outerPlan(node);
	tupDesc = ExecGetTupType(outerPlan);
427

428
	ExecAssignScanType(csstate, tupDesc, false);
429 430 431 432
}


/* ----------------------------------------------------------------
433
 *				  ExecInsertIndexTuples support
434 435
 * ----------------------------------------------------------------
 */
436 437 438 439

/* ----------------------------------------------------------------
 *		ExecOpenIndices
 *
440
 *		Find the indices associated with a result relation, open them,
441
 *		and save information about them in the result ResultRelInfo.
442
 *
443
 *		At entry, caller has already opened and locked
444
 *		resultRelInfo->ri_RelationDesc.
445
 *
446
 *		This used to be horribly ugly code, and slow too because it
B
Bruce Momjian 已提交
447
 *		did a sequential scan of pg_index.	Now we rely on the relcache
448 449 450
 *		to cache a list of the OIDs of the indices associated with any
 *		specific relation, and we use the pg_index syscache to get the
 *		entries we need from pg_index.
451 452 453
 * ----------------------------------------------------------------
 */
void
454
ExecOpenIndices(ResultRelInfo *resultRelInfo)
455
{
456
	Relation	resultRelation = resultRelInfo->ri_RelationDesc;
457 458 459 460
	List	   *indexoidlist,
			   *indexoidscan;
	int			len,
				i;
461 462
	RelationPtr relationDescs;
	IndexInfo **indexInfoArray;
463

464
	resultRelInfo->ri_NumIndices = 0;
465 466

	/* checks for disabled indexes */
B
Bruce Momjian 已提交
467
	if (!RelationGetForm(resultRelation)->relhasindex)
H
Hiroshi Inoue 已提交
468 469
		return;
	if (IsIgnoringSystemIndexes() &&
470
		IsSystemRelationName(RelationGetRelationName(resultRelation)))
H
Hiroshi Inoue 已提交
471
		return;
472

473 474
	/*
	 * Get cached list of index OIDs
475
	 */
476 477 478 479
	indexoidlist = RelationGetIndexList(resultRelation);
	len = length(indexoidlist);
	if (len == 0)
		return;
480

481 482
	/*
	 * allocate space for result arrays
483
	 */
484 485 486
	relationDescs = (RelationPtr) palloc(len * sizeof(Relation));
	indexInfoArray = (IndexInfo **) palloc(len * sizeof(IndexInfo *));

487 488 489
	resultRelInfo->ri_NumIndices = len;
	resultRelInfo->ri_IndexRelationDescs = relationDescs;
	resultRelInfo->ri_IndexRelationInfo = indexInfoArray;
490

491 492
	/*
	 * For each index, open the index relation and save pg_index info.
493
	 */
494 495
	i = 0;
	foreach(indexoidscan, indexoidlist)
496
	{
497 498 499 500
		Oid			indexOid = lfirsti(indexoidscan);
		Relation	indexDesc;
		HeapTuple	indexTuple;
		IndexInfo  *ii;
501

502
		/*
503
		 * Open (and lock, if necessary) the index relation
504
		 *
505 506 507 508
		 * If the index AM is not safe for concurrent updates, obtain an
		 * exclusive lock on the index to lock out other updaters as well
		 * as readers (index_beginscan places AccessShareLock). We will
		 * release this lock in ExecCloseIndices.
509
		 *
510 511
		 * If the index AM supports concurrent updates, we obtain no lock
		 * here at all, which is a tad weird, but safe since any critical
512 513 514
		 * operation on the index (like deleting it) will acquire
		 * exclusive lock on the parent table.	Perhaps someday we should
		 * acquire RowExclusiveLock on the index here?
515 516
		 *
		 * If there are multiple not-concurrent-safe indexes, all backends
517 518 519 520
		 * must lock the indexes in the same order or we will get
		 * deadlocks here during concurrent updates.  This is guaranteed
		 * by RelationGetIndexList(), which promises to return the index
		 * list in OID order.
521
		 */
522 523
		indexDesc = index_open(indexOid);

524
		if (!indexDesc->rd_am->amconcurrent)
525
			LockRelation(indexDesc, AccessExclusiveLock);
526

527 528
		/*
		 * Get the pg_index tuple for the index
529
		 */
530 531 532
		indexTuple = SearchSysCache(INDEXRELID,
									ObjectIdGetDatum(indexOid),
									0, 0, 0);
533 534
		if (!HeapTupleIsValid(indexTuple))
			elog(ERROR, "ExecOpenIndices: index %u not found", indexOid);
535

536 537
		/*
		 * extract the index key information from the tuple
538
		 */
539
		ii = BuildIndexInfo(indexTuple);
540

541 542
		ReleaseSysCache(indexTuple);

543 544 545
		relationDescs[i] = indexDesc;
		indexInfoArray[i] = ii;
		i++;
546
	}
547

548
	freeList(indexoidlist);
549 550 551
}

/* ----------------------------------------------------------------
552
 *		ExecCloseIndices
553
 *
554
 *		Close the index relations stored in resultRelInfo
555 556 557
 * ----------------------------------------------------------------
 */
void
558
ExecCloseIndices(ResultRelInfo *resultRelInfo)
559
{
560 561
	int			i;
	int			numIndices;
562
	RelationPtr indexDescs;
563

564
	numIndices = resultRelInfo->ri_NumIndices;
565
	indexDescs = resultRelInfo->ri_IndexRelationDescs;
566 567

	for (i = 0; i < numIndices; i++)
V
Vadim B. Mikheev 已提交
568
	{
569
		if (indexDescs[i] == NULL)
V
Vadim B. Mikheev 已提交
570
			continue;
B
Bruce Momjian 已提交
571

572
		/* Drop lock, if one was acquired by ExecOpenIndices */
573
		if (!indexDescs[i]->rd_am->amconcurrent)
574
			UnlockRelation(indexDescs[i], AccessExclusiveLock);
575

576
		index_close(indexDescs[i]);
V
Vadim B. Mikheev 已提交
577
	}
B
Bruce Momjian 已提交
578

579 580 581
	/*
	 * XXX should free indexInfo array here too.
	 */
582 583 584
}

/* ----------------------------------------------------------------
585
 *		ExecInsertIndexTuples
586
 *
587 588 589 590 591 592 593
 *		This routine takes care of inserting index tuples
 *		into all the relations indexing the result relation
 *		when a heap tuple is inserted into the result relation.
 *		Much of this code should be moved into the genam
 *		stuff as it only exists here because the genam stuff
 *		doesn't provide the functionality needed by the
 *		executor.. -cim 9/27/89
594 595 596
 * ----------------------------------------------------------------
 */
void
597
ExecInsertIndexTuples(TupleTableSlot *slot,
598
					  ItemPointer tupleid,
599
					  EState *estate,
600
					  bool is_update)
601
{
602
	HeapTuple	heapTuple;
603
	ResultRelInfo *resultRelInfo;
604 605 606 607
	int			i;
	int			numIndices;
	RelationPtr relationDescs;
	Relation	heapRelation;
608
	TupleDesc	heapDescriptor;
609 610
	IndexInfo **indexInfoArray;
	ExprContext *econtext;
611 612
	Datum		datum[INDEX_MAX_KEYS];
	char		nullv[INDEX_MAX_KEYS];
613 614

	heapTuple = slot->val;
615

616 617
	/*
	 * Get information from the result relation info structure.
618
	 */
619 620 621 622 623
	resultRelInfo = estate->es_result_relation_info;
	numIndices = resultRelInfo->ri_NumIndices;
	relationDescs = resultRelInfo->ri_IndexRelationDescs;
	indexInfoArray = resultRelInfo->ri_IndexRelationInfo;
	heapRelation = resultRelInfo->ri_RelationDesc;
624 625
	heapDescriptor = RelationGetDescr(heapRelation);

626
	/*
B
Bruce Momjian 已提交
627 628 629
	 * We will use the EState's per-tuple context for evaluating
	 * predicates and functional-index functions (creating it if it's not
	 * already there).
630
	 */
631
	econtext = GetPerTupleExprContext(estate);
632 633 634

	/* Arrange for econtext's scan tuple to be the tuple under test */
	econtext->ecxt_scantuple = slot;
635

636 637
	/*
	 * for each index, form and insert the index tuple
638
	 */
639 640
	for (i = 0; i < numIndices; i++)
	{
641
		IndexInfo  *indexInfo;
642
		List	   *predicate;
643 644
		InsertIndexResult result;

645 646 647 648 649
		if (relationDescs[i] == NULL)
			continue;

		indexInfo = indexInfoArray[i];
		predicate = indexInfo->ii_Predicate;
650
		if (predicate != NIL)
651 652
		{
			/* Skip this index-update if the predicate isn't satisfied */
653
			if (!ExecQual(predicate, econtext, false))
654 655 656
				continue;
		}

657 658 659
		/*
		 * FormIndexDatum fills in its datum and null parameters with
		 * attribute information taken from the given heap tuple.
660
		 */
661 662 663 664 665 666
		FormIndexDatum(indexInfo,
					   heapTuple,
					   heapDescriptor,
					   econtext->ecxt_per_tuple_memory,
					   datum,
					   nullv);
667 668 669

		result = index_insert(relationDescs[i], /* index relation */
							  datum,	/* array of heaptuple Datums */
670
							  nullv,	/* info on nulls */
B
Bruce Momjian 已提交
671
							  &(heapTuple->t_self),		/* tid of heap tuple */
672 673
							  heapRelation);

674 675
		/*
		 * keep track of index inserts for debugging
676 677 678 679 680 681
		 */
		IncrIndexInserted();

		if (result)
			pfree(result);
	}
682
}
V
Vadim B. Mikheev 已提交
683

684 685
void
SetChangedParamList(Plan *node, List *newchg)
V
Vadim B. Mikheev 已提交
686
{
687 688 689
	List	   *nl;

	foreach(nl, newchg)
V
Vadim B. Mikheev 已提交
690
	{
691 692
		int			paramId = lfirsti(nl);

V
Vadim B. Mikheev 已提交
693
		/* if this node doesn't depend on a param ... */
694 695
		if (!intMember(paramId, node->extParam) &&
			!intMember(paramId, node->locParam))
V
Vadim B. Mikheev 已提交
696 697
			continue;
		/* if this param is already in list of changed ones ... */
698
		if (intMember(paramId, node->chgParam))
V
Vadim B. Mikheev 已提交
699 700
			continue;
		/* else - add this param to the list */
701
		node->chgParam = lappendi(node->chgParam, paramId);
V
Vadim B. Mikheev 已提交
702 703
	}
}