1 /*-------------------------------------------------------------------------
4 * top level executor interface routines
11 * The old ExecutorMain() has been replaced by ExecutorStart(),
12 * ExecutorRun() and ExecutorEnd()
14 * These three procedures are the external interfaces to the executor.
15 * In each case, the query descriptor and the execution state is required
18 * ExecutorStart() must be called at the beginning of any execution of any
19 * query plan and ExecutorEnd() should always be called at the end of
20 * execution of a plan.
22 * ExecutorRun accepts direction and count arguments that specify whether
23 * the plan is to be executed forwards, backwards, and for how many tuples.
25 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
26 * Portions Copyright (c) 1994, Regents of the University of California
30 * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.187 2002/11/23 03:59:07 momjian Exp $
32 *-------------------------------------------------------------------------
36 #include "access/heapam.h"
37 #include "catalog/heap.h"
38 #include "catalog/namespace.h"
39 #include "commands/tablecmds.h"
40 #include "commands/trigger.h"
41 #include "executor/execdebug.h"
42 #include "executor/execdefs.h"
43 #include "miscadmin.h"
44 #include "optimizer/var.h"
45 #include "parser/parsetree.h"
46 #include "utils/acl.h"
47 #include "utils/lsyscache.h"
50 /* decls for local routines only used within this module */
51 static TupleDesc InitPlan(CmdType operation,
55 static void initResultRelInfo(ResultRelInfo *resultRelInfo,
56 Index resultRelationIndex,
59 static void EndPlan(Plan *plan, EState *estate);
60 static TupleTableSlot *ExecutePlan(EState *estate, Plan *plan,
63 ScanDirection direction,
64 DestReceiver *destfunc);
65 static void ExecSelect(TupleTableSlot *slot,
66 DestReceiver *destfunc,
68 static void ExecInsert(TupleTableSlot *slot, ItemPointer tupleid,
70 static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
72 static void ExecUpdate(TupleTableSlot *slot, ItemPointer tupleid,
74 static TupleTableSlot *EvalPlanQualNext(EState *estate);
75 static void EndEvalPlanQual(EState *estate);
76 static void ExecCheckQueryPerms(CmdType operation, Query *parseTree,
78 static void ExecCheckPlanPerms(Plan *plan, List *rangeTable,
80 static void ExecCheckRTPerms(List *rangeTable, CmdType operation);
81 static void ExecCheckRTEPerms(RangeTblEntry *rte, CmdType operation);
83 /* end of local decls */
86 /* ----------------------------------------------------------------
89 * This routine must be called at the beginning of any execution of any
92 * returns a TupleDesc which describes the attributes of the tuples to
93 * be returned by the query. (Same value is saved in queryDesc)
95 * NB: the CurrentMemoryContext when this is called must be the context
96 * to be used as the per-query context for the query plan. ExecutorRun()
97 * and ExecutorEnd() must be called in this same memory context.
98 * ----------------------------------------------------------------
101 ExecutorStart(QueryDesc *queryDesc, EState *estate)
106 Assert(queryDesc != NULL);
108 if (queryDesc->plantree->nParamExec > 0)
109 estate->es_param_exec_vals = (ParamExecData *)
110 palloc0(queryDesc->plantree->nParamExec * sizeof(ParamExecData));
113 * Make our own private copy of the current query snapshot data.
115 * This "freezes" our idea of which tuples are good and which are not for
116 * the life of this query, even if it outlives the current command and
119 estate->es_snapshot = CopyQuerySnapshot();
122 * Initialize the plan
124 result = InitPlan(queryDesc->operation,
125 queryDesc->parsetree,
129 queryDesc->tupDesc = result;
134 /* ----------------------------------------------------------------
137 * This is the main routine of the executor module. It accepts
138 * the query descriptor from the traffic cop and executes the
141 * ExecutorStart must have been called already.
143 * If direction is NoMovementScanDirection then nothing is done
144 * except to start up/shut down the destination. Otherwise,
145 * we retrieve up to 'count' tuples in the specified direction.
147 * Note: count = 0 is interpreted as no portal limit, e.g. run to
150 * ----------------------------------------------------------------
153 ExecutorRun(QueryDesc *queryDesc, EState *estate,
154 ScanDirection direction, long count)
159 DestReceiver *destfunc;
160 TupleTableSlot *result;
165 Assert(queryDesc != NULL);
168 * extract information from the query descriptor and the query
171 operation = queryDesc->operation;
172 plan = queryDesc->plantree;
173 dest = queryDesc->dest;
176 * startup tuple receiver
178 estate->es_processed = 0;
179 estate->es_lastoid = InvalidOid;
181 destfunc = DestToFunction(dest);
182 (*destfunc->setup) (destfunc, (int) operation,
183 queryDesc->portalName, queryDesc->tupDesc);
188 if (direction == NoMovementScanDirection)
191 result = ExecutePlan(estate,
201 (*destfunc->cleanup) (destfunc);
206 /* ----------------------------------------------------------------
209 * This routine must be called at the end of execution of any
211 * ----------------------------------------------------------------
214 ExecutorEnd(QueryDesc *queryDesc, EState *estate)
217 Assert(queryDesc != NULL);
219 EndPlan(queryDesc->plantree, estate);
221 if (estate->es_snapshot != NULL)
223 if (estate->es_snapshot->xcnt > 0)
224 pfree(estate->es_snapshot->xip);
225 pfree(estate->es_snapshot);
226 estate->es_snapshot = NULL;
229 if (estate->es_param_exec_vals != NULL)
231 pfree(estate->es_param_exec_vals);
232 estate->es_param_exec_vals = NULL;
238 * ExecCheckQueryPerms
239 * Check access permissions for all relations referenced in a query.
242 ExecCheckQueryPerms(CmdType operation, Query *parseTree, Plan *plan)
245 * Check RTEs in the query's primary rangetable.
247 ExecCheckRTPerms(parseTree->rtable, operation);
250 * Search for subplans and APPEND nodes to check their rangetables.
252 ExecCheckPlanPerms(plan, parseTree->rtable, operation);
257 * Recursively scan the plan tree to check access permissions in
261 ExecCheckPlanPerms(Plan *plan, List *rangeTable, CmdType operation)
268 /* Check subplans, which we assume are plain SELECT queries */
270 foreach(subp, plan->initPlan)
272 SubPlan *subplan = (SubPlan *) lfirst(subp);
274 ExecCheckRTPerms(subplan->rtable, CMD_SELECT);
275 ExecCheckPlanPerms(subplan->plan, subplan->rtable, CMD_SELECT);
277 foreach(subp, plan->subPlan)
279 SubPlan *subplan = (SubPlan *) lfirst(subp);
281 ExecCheckRTPerms(subplan->rtable, CMD_SELECT);
282 ExecCheckPlanPerms(subplan->plan, subplan->rtable, CMD_SELECT);
285 /* Check lower plan nodes */
287 ExecCheckPlanPerms(plan->lefttree, rangeTable, operation);
288 ExecCheckPlanPerms(plan->righttree, rangeTable, operation);
290 /* Do node-type-specific checks */
292 switch (nodeTag(plan))
296 SubqueryScan *scan = (SubqueryScan *) plan;
299 /* Recursively check the subquery */
300 rte = rt_fetch(scan->scan.scanrelid, rangeTable);
301 Assert(rte->rtekind == RTE_SUBQUERY);
302 ExecCheckQueryPerms(operation, rte->subquery, scan->subplan);
307 Append *app = (Append *) plan;
310 foreach(appendplans, app->appendplans)
312 ExecCheckPlanPerms((Plan *) lfirst(appendplans),
326 * Check access permissions for all relations listed in a range table.
329 ExecCheckRTPerms(List *rangeTable, CmdType operation)
333 foreach(lp, rangeTable)
335 RangeTblEntry *rte = lfirst(lp);
337 ExecCheckRTEPerms(rte, operation);
343 * Check access permissions for a single RTE.
346 ExecCheckRTEPerms(RangeTblEntry *rte, CmdType operation)
350 AclResult aclcheck_result;
353 * Only plain-relation RTEs need to be checked here. Subquery RTEs
354 * will be checked when ExecCheckPlanPerms finds the SubqueryScan
355 * node, and function RTEs are checked by init_fcache when the
356 * function is prepared for execution. Join and special RTEs need no
359 if (rte->rtekind != RTE_RELATION)
365 * userid to check as: current user unless we have a setuid
368 * Note: GetUserId() is presently fast enough that there's no harm in
369 * calling it separately for each RTE. If that stops being true, we
370 * could call it once in ExecCheckQueryPerms and pass the userid down
371 * from there. But for now, no need for the extra clutter.
373 userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
375 #define CHECK(MODE) pg_class_aclcheck(relOid, userid, MODE)
377 if (rte->checkForRead)
379 aclcheck_result = CHECK(ACL_SELECT);
380 if (aclcheck_result != ACLCHECK_OK)
381 aclcheck_error(aclcheck_result, get_rel_name(relOid));
384 if (rte->checkForWrite)
387 * Note: write access in a SELECT context means SELECT FOR UPDATE.
388 * Right now we don't distinguish that from true update as far as
389 * permissions checks are concerned.
394 aclcheck_result = CHECK(ACL_INSERT);
398 aclcheck_result = CHECK(ACL_UPDATE);
401 aclcheck_result = CHECK(ACL_DELETE);
404 elog(ERROR, "ExecCheckRTEPerms: bogus operation %d",
406 aclcheck_result = ACLCHECK_OK; /* keep compiler quiet */
409 if (aclcheck_result != ACLCHECK_OK)
410 aclcheck_error(aclcheck_result, get_rel_name(relOid));
415 /* ===============================================================
416 * ===============================================================
417 static routines follow
418 * ===============================================================
419 * ===============================================================
422 typedef struct execRowMark
429 typedef struct evalPlanQual
434 struct evalPlanQual *free;
437 /* ----------------------------------------------------------------
440 * Initializes the query plan: open files, allocate storage
441 * and start up the rule manager
442 * ----------------------------------------------------------------
445 InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
448 Relation intoRelationDesc;
452 * Do permissions checks.
454 ExecCheckQueryPerms(operation, parseTree, plan);
457 * get information from query descriptor
459 rangeTable = parseTree->rtable;
462 * initialize the node's execution state
464 estate->es_range_table = rangeTable;
467 * if there is a result relation, initialize result relation stuff
469 if (parseTree->resultRelation != 0 && operation != CMD_SELECT)
471 List *resultRelations = parseTree->resultRelations;
472 int numResultRelations;
473 ResultRelInfo *resultRelInfos;
475 if (resultRelations != NIL)
478 * Multiple result relations (due to inheritance)
479 * parseTree->resultRelations identifies them all
481 ResultRelInfo *resultRelInfo;
483 numResultRelations = length(resultRelations);
484 resultRelInfos = (ResultRelInfo *)
485 palloc(numResultRelations * sizeof(ResultRelInfo));
486 resultRelInfo = resultRelInfos;
487 while (resultRelations != NIL)
489 initResultRelInfo(resultRelInfo,
490 lfirsti(resultRelations),
494 resultRelations = lnext(resultRelations);
500 * Single result relation identified by
501 * parseTree->resultRelation
503 numResultRelations = 1;
504 resultRelInfos = (ResultRelInfo *) palloc(sizeof(ResultRelInfo));
505 initResultRelInfo(resultRelInfos,
506 parseTree->resultRelation,
511 estate->es_result_relations = resultRelInfos;
512 estate->es_num_result_relations = numResultRelations;
513 /* Initialize to first or only result rel */
514 estate->es_result_relation_info = resultRelInfos;
519 * if no result relation, then set state appropriately
521 estate->es_result_relations = NULL;
522 estate->es_num_result_relations = 0;
523 estate->es_result_relation_info = NULL;
527 * Have to lock relations selected for update
529 estate->es_rowMark = NIL;
530 if (parseTree->rowMarks != NIL)
534 foreach(l, parseTree->rowMarks)
536 Index rti = lfirsti(l);
537 Oid relid = getrelid(rti, rangeTable);
541 relation = heap_open(relid, RowShareLock);
542 erm = (execRowMark *) palloc(sizeof(execRowMark));
543 erm->relation = relation;
545 snprintf(erm->resname, 32, "ctid%u", rti);
546 estate->es_rowMark = lappend(estate->es_rowMark, erm);
551 * initialize the executor "tuple" table. We need slots for all the
552 * plan nodes, plus possibly output slots for the junkfilter(s). At
553 * this point we aren't sure if we need junkfilters, so just add slots
554 * for them unconditionally.
557 int nSlots = ExecCountSlotsNode(plan);
559 if (parseTree->resultRelations != NIL)
560 nSlots += length(parseTree->resultRelations);
563 estate->es_tupleTable = ExecCreateTupleTable(nSlots);
566 /* mark EvalPlanQual not active */
567 estate->es_origPlan = plan;
568 estate->es_evalPlanQual = NULL;
569 estate->es_evTuple = NULL;
570 estate->es_evTupleNull = NULL;
571 estate->es_useEvalPlan = false;
574 * initialize the private state information for all the nodes in the
575 * query tree. This opens files, allocates storage and leaves us
576 * ready to start processing tuples.
578 ExecInitNode(plan, estate, NULL);
581 * Get the tuple descriptor describing the type of tuples to return.
582 * (this is especially important if we are creating a relation with
585 tupType = ExecGetTupType(plan); /* tuple descriptor */
588 * Initialize the junk filter if needed. SELECT and INSERT queries
589 * need a filter if there are any junk attrs in the tlist. UPDATE and
590 * DELETE always need one, since there's always a junk 'ctid'
591 * attribute present --- no need to look first.
594 bool junk_filter_needed = false;
601 foreach(tlist, plan->targetlist)
603 TargetEntry *tle = (TargetEntry *) lfirst(tlist);
605 if (tle->resdom->resjunk)
607 junk_filter_needed = true;
614 junk_filter_needed = true;
620 if (junk_filter_needed)
623 * If there are multiple result relations, each one needs its
624 * own junk filter. Note this is only possible for
625 * UPDATE/DELETE, so we can't be fooled by some needing a
626 * filter and some not.
628 if (parseTree->resultRelations != NIL)
631 ResultRelInfo *resultRelInfo;
633 /* Top plan had better be an Append here. */
634 Assert(IsA(plan, Append));
635 Assert(((Append *) plan)->isTarget);
636 subplans = ((Append *) plan)->appendplans;
637 Assert(length(subplans) == estate->es_num_result_relations);
638 resultRelInfo = estate->es_result_relations;
639 while (subplans != NIL)
641 Plan *subplan = (Plan *) lfirst(subplans);
644 j = ExecInitJunkFilter(subplan->targetlist,
645 ExecGetTupType(subplan),
646 ExecAllocTableSlot(estate->es_tupleTable));
647 resultRelInfo->ri_junkFilter = j;
649 subplans = lnext(subplans);
653 * Set active junkfilter too; at this point ExecInitAppend
654 * has already selected an active result relation...
656 estate->es_junkFilter =
657 estate->es_result_relation_info->ri_junkFilter;
661 /* Normal case with just one JunkFilter */
664 j = ExecInitJunkFilter(plan->targetlist,
666 ExecAllocTableSlot(estate->es_tupleTable));
667 estate->es_junkFilter = j;
668 if (estate->es_result_relation_info)
669 estate->es_result_relation_info->ri_junkFilter = j;
671 /* For SELECT, want to return the cleaned tuple type */
672 if (operation == CMD_SELECT)
673 tupType = j->jf_cleanTupType;
677 estate->es_junkFilter = NULL;
681 * initialize the "into" relation
683 intoRelationDesc = (Relation) NULL;
685 if (operation == CMD_SELECT)
687 if (!parseTree->isPortal)
690 * a select into table --- need to create the "into" table
692 if (parseTree->into != NULL)
701 * find namespace to create in, check permissions
703 intoName = parseTree->into->relname;
704 namespaceId = RangeVarGetCreationNamespace(parseTree->into);
706 aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(),
708 if (aclresult != ACLCHECK_OK)
709 aclcheck_error(aclresult,
710 get_namespace_name(namespaceId));
713 * have to copy tupType to get rid of constraints
715 tupdesc = CreateTupleDescCopy(tupType);
718 * Formerly we forced the output table to have OIDs, but
719 * as of 7.3 it will not have OIDs, because it's too late
720 * here to change the tupdescs of the already-initialized
721 * plan tree. (Perhaps we could recurse and change them
722 * all, but it's not really worth the trouble IMHO...)
726 heap_create_with_catalog(intoName,
732 allowSystemTableMods);
734 FreeTupleDesc(tupdesc);
737 * Advance command counter so that the newly-created
738 * relation's catalog tuples will be visible to heap_open.
740 CommandCounterIncrement();
743 * If necessary, create a TOAST table for the into
744 * relation. Note that AlterTableCreateToastTable ends
745 * with CommandCounterIncrement(), so that the TOAST table
746 * will be visible for insertion.
748 AlterTableCreateToastTable(intoRelationId, true);
750 intoRelationDesc = heap_open(intoRelationId,
751 AccessExclusiveLock);
756 estate->es_into_relation_descriptor = intoRelationDesc;
762 * Initialize ResultRelInfo data for one result relation
765 initResultRelInfo(ResultRelInfo *resultRelInfo,
766 Index resultRelationIndex,
770 Oid resultRelationOid;
771 Relation resultRelationDesc;
773 resultRelationOid = getrelid(resultRelationIndex, rangeTable);
774 resultRelationDesc = heap_open(resultRelationOid, RowExclusiveLock);
776 switch (resultRelationDesc->rd_rel->relkind)
778 case RELKIND_SEQUENCE:
779 elog(ERROR, "You can't change sequence relation %s",
780 RelationGetRelationName(resultRelationDesc));
782 case RELKIND_TOASTVALUE:
783 elog(ERROR, "You can't change toast relation %s",
784 RelationGetRelationName(resultRelationDesc));
787 elog(ERROR, "You can't change view relation %s",
788 RelationGetRelationName(resultRelationDesc));
792 MemSet(resultRelInfo, 0, sizeof(ResultRelInfo));
793 resultRelInfo->type = T_ResultRelInfo;
794 resultRelInfo->ri_RangeTableIndex = resultRelationIndex;
795 resultRelInfo->ri_RelationDesc = resultRelationDesc;
796 resultRelInfo->ri_NumIndices = 0;
797 resultRelInfo->ri_IndexRelationDescs = NULL;
798 resultRelInfo->ri_IndexRelationInfo = NULL;
799 /* make a copy so as not to depend on relcache info not changing... */
800 resultRelInfo->ri_TrigDesc = CopyTriggerDesc(resultRelationDesc->trigdesc);
801 resultRelInfo->ri_TrigFunctions = NULL;
802 resultRelInfo->ri_ConstraintExprs = NULL;
803 resultRelInfo->ri_junkFilter = NULL;
806 * If there are indices on the result relation, open them and save
807 * descriptors in the result relation info, so that we can add new
808 * index entries for the tuples we add/update. We need not do this
809 * for a DELETE, however, since deletion doesn't affect indexes.
811 if (resultRelationDesc->rd_rel->relhasindex &&
812 operation != CMD_DELETE)
813 ExecOpenIndices(resultRelInfo);
816 /* ----------------------------------------------------------------
819 * Cleans up the query plan -- closes files and free up storages
820 * ----------------------------------------------------------------
823 EndPlan(Plan *plan, EState *estate)
825 ResultRelInfo *resultRelInfo;
830 * shut down any PlanQual processing we were doing
832 if (estate->es_evalPlanQual != NULL)
833 EndEvalPlanQual(estate);
836 * shut down the node-type-specific query processing
838 ExecEndNode(plan, NULL);
841 * destroy the executor "tuple" table.
843 ExecDropTupleTable(estate->es_tupleTable, true);
844 estate->es_tupleTable = NULL;
847 * close the result relation(s) if any, but hold locks until xact
848 * commit. Also clean up junkfilters if present.
850 resultRelInfo = estate->es_result_relations;
851 for (i = estate->es_num_result_relations; i > 0; i--)
853 /* Close indices and then the relation itself */
854 ExecCloseIndices(resultRelInfo);
855 heap_close(resultRelInfo->ri_RelationDesc, NoLock);
856 /* Delete the junkfilter if any */
857 if (resultRelInfo->ri_junkFilter != NULL)
858 ExecFreeJunkFilter(resultRelInfo->ri_junkFilter);
863 * close the "into" relation if necessary, again keeping lock
865 if (estate->es_into_relation_descriptor != NULL)
866 heap_close(estate->es_into_relation_descriptor, NoLock);
869 * There might be a junkfilter without a result relation.
871 if (estate->es_num_result_relations == 0 &&
872 estate->es_junkFilter != NULL)
874 ExecFreeJunkFilter(estate->es_junkFilter);
875 estate->es_junkFilter = NULL;
879 * close any relations selected FOR UPDATE, again keeping locks
881 foreach(l, estate->es_rowMark)
883 execRowMark *erm = lfirst(l);
885 heap_close(erm->relation, NoLock);
889 /* ----------------------------------------------------------------
892 * processes the query plan to retrieve 'numberTuples' tuples in the
893 * direction specified.
894 * Retrieves all tuples if numberTuples is 0
896 * result is either a slot containing the last tuple in the case
897 * of a SELECT or NULL otherwise.
899 * Note: the ctid attribute is a 'junk' attribute that is removed before the
901 * ----------------------------------------------------------------
903 static TupleTableSlot *
904 ExecutePlan(EState *estate,
908 ScanDirection direction,
909 DestReceiver *destfunc)
911 JunkFilter *junkfilter;
912 TupleTableSlot *slot;
913 ItemPointer tupleid = NULL;
914 ItemPointerData tuple_ctid;
915 long current_tuple_count;
916 TupleTableSlot *result;
919 * initialize local variables
922 current_tuple_count = 0;
928 estate->es_direction = direction;
931 * Process BEFORE EACH STATEMENT triggers
936 ExecBSUpdateTriggers(estate, estate->es_result_relation_info);
939 ExecBSDeleteTriggers(estate, estate->es_result_relation_info);
942 ExecBSInsertTriggers(estate, estate->es_result_relation_info);
949 * Loop until we've processed the proper number of tuples from the
955 /* Reset the per-output-tuple exprcontext */
956 ResetPerTupleExprContext(estate);
959 * Execute the plan and obtain a tuple
962 if (estate->es_useEvalPlan)
964 slot = EvalPlanQualNext(estate);
966 slot = ExecProcNode(plan, NULL);
969 slot = ExecProcNode(plan, NULL);
972 * if the tuple is null, then we assume there is nothing more to
973 * process so we just return null...
982 * if we have a junk filter, then project a new tuple with the
985 * Store this new "clean" tuple in the junkfilter's resultSlot.
986 * (Formerly, we stored it back over the "dirty" tuple, which is
987 * WRONG because that tuple slot has the wrong descriptor.)
989 * Also, extract all the junk information we need.
991 if ((junkfilter = estate->es_junkFilter) != (JunkFilter *) NULL)
998 * extract the 'ctid' junk attribute.
1000 if (operation == CMD_UPDATE || operation == CMD_DELETE)
1002 if (!ExecGetJunkAttribute(junkfilter,
1007 elog(ERROR, "ExecutePlan: NO (junk) `ctid' was found!");
1009 /* shouldn't ever get a null result... */
1011 elog(ERROR, "ExecutePlan: (junk) `ctid' is NULL!");
1013 tupleid = (ItemPointer) DatumGetPointer(datum);
1014 tuple_ctid = *tupleid; /* make sure we don't free the
1016 tupleid = &tuple_ctid;
1018 else if (estate->es_rowMark != NIL)
1023 foreach(l, estate->es_rowMark)
1025 execRowMark *erm = lfirst(l);
1027 HeapTupleData tuple;
1028 TupleTableSlot *newSlot;
1031 if (!ExecGetJunkAttribute(junkfilter,
1036 elog(ERROR, "ExecutePlan: NO (junk) `%s' was found!",
1039 /* shouldn't ever get a null result... */
1041 elog(ERROR, "ExecutePlan: (junk) `%s' is NULL!",
1044 tuple.t_self = *((ItemPointer) DatumGetPointer(datum));
1045 test = heap_mark4update(erm->relation, &tuple, &buffer,
1046 estate->es_snapshot->curcid);
1047 ReleaseBuffer(buffer);
1050 case HeapTupleSelfUpdated:
1051 /* treat it as deleted; do not process */
1054 case HeapTupleMayBeUpdated:
1057 case HeapTupleUpdated:
1058 if (XactIsoLevel == XACT_SERIALIZABLE)
1059 elog(ERROR, "Can't serialize access due to concurrent update");
1060 if (!(ItemPointerEquals(&(tuple.t_self),
1061 (ItemPointer) DatumGetPointer(datum))))
1063 newSlot = EvalPlanQual(estate, erm->rti, &(tuple.t_self));
1064 if (!(TupIsNull(newSlot)))
1067 estate->es_useEvalPlan = true;
1073 * if tuple was deleted or PlanQual failed for
1074 * updated tuple - we must not return this
1080 elog(ERROR, "Unknown status %u from heap_mark4update", test);
1087 * Finally create a new "clean" tuple with all junk attributes
1090 newTuple = ExecRemoveJunk(junkfilter, slot);
1092 slot = ExecStoreTuple(newTuple, /* tuple to store */
1093 junkfilter->jf_resultSlot, /* dest slot */
1094 InvalidBuffer, /* this tuple has no
1096 true); /* tuple should be pfreed */
1100 * now that we have a tuple, do the appropriate thing with it..
1101 * either return it to the user, add it to a relation someplace,
1102 * delete it from a relation, or modify some of its attributes.
1107 ExecSelect(slot, /* slot containing tuple */
1108 destfunc, /* destination's tuple-receiver
1115 ExecInsert(slot, tupleid, estate);
1120 ExecDelete(slot, tupleid, estate);
1125 ExecUpdate(slot, tupleid, estate);
1130 elog(LOG, "ExecutePlan: unknown operation in queryDesc");
1136 * check our tuple count.. if we've processed the proper number
1137 * then quit, else loop again and process more tuples. Zero
1138 * number_tuples means no limit.
1140 current_tuple_count++;
1141 if (numberTuples == current_tuple_count)
1146 * Process AFTER EACH STATEMENT triggers
1151 ExecASUpdateTriggers(estate, estate->es_result_relation_info);
1154 ExecASDeleteTriggers(estate, estate->es_result_relation_info);
1157 ExecASInsertTriggers(estate, estate->es_result_relation_info);
1164 * here, result is either a slot containing a tuple in the case of a
1165 * SELECT or NULL otherwise.
1170 /* ----------------------------------------------------------------
1173 * SELECTs are easy.. we just pass the tuple to the appropriate
1174 * print function. The only complexity is when we do a
1175 * "SELECT INTO", in which case we insert the tuple into
1176 * the appropriate relation (note: this is a newly created relation
1177 * so we don't need to worry about indices or locks.)
1178 * ----------------------------------------------------------------
1181 ExecSelect(TupleTableSlot *slot,
1182 DestReceiver *destfunc,
1189 * get the heap tuple out of the tuple table slot
1192 attrtype = slot->ttc_tupleDescriptor;
1195 * insert the tuple into the "into relation"
1197 if (estate->es_into_relation_descriptor != NULL)
1199 heap_insert(estate->es_into_relation_descriptor, tuple,
1200 estate->es_snapshot->curcid);
1205 * send the tuple to the front end (or the screen)
1207 (*destfunc->receiveTuple) (tuple, attrtype, destfunc);
1209 (estate->es_processed)++;
1212 /* ----------------------------------------------------------------
1215 * INSERTs are trickier.. we have to insert the tuple into
1216 * the base relation and insert appropriate tuples into the
1218 * ----------------------------------------------------------------
1221 ExecInsert(TupleTableSlot *slot,
1222 ItemPointer tupleid,
1226 ResultRelInfo *resultRelInfo;
1227 Relation resultRelationDesc;
1232 * get the heap tuple out of the tuple table slot
1237 * get information on the (current) result relation
1239 resultRelInfo = estate->es_result_relation_info;
1240 resultRelationDesc = resultRelInfo->ri_RelationDesc;
1242 /* BEFORE ROW INSERT Triggers */
1243 if (resultRelInfo->ri_TrigDesc &&
1244 resultRelInfo->ri_TrigDesc->n_before_row[TRIGGER_EVENT_INSERT] > 0)
1248 newtuple = ExecBRInsertTriggers(estate, resultRelInfo, tuple);
1250 if (newtuple == NULL) /* "do nothing" */
1253 if (newtuple != tuple) /* modified by Trigger(s) */
1256 * Insert modified tuple into tuple table slot, replacing the
1257 * original. We assume that it was allocated in per-tuple
1258 * memory context, and therefore will go away by itself. The
1259 * tuple table slot should not try to clear it.
1261 ExecStoreTuple(newtuple, slot, InvalidBuffer, false);
1267 * Check the constraints of the tuple
1269 if (resultRelationDesc->rd_att->constr)
1270 ExecConstraints("ExecInsert", resultRelInfo, slot, estate);
1275 newId = heap_insert(resultRelationDesc, tuple,
1276 estate->es_snapshot->curcid);
1279 (estate->es_processed)++;
1280 estate->es_lastoid = newId;
1281 setLastTid(&(tuple->t_self));
1286 * Note: heap_insert adds a new tuple to a relation. As a side effect,
1287 * the tupleid of the new tuple is placed in the new tuple's t_ctid
1290 numIndices = resultRelInfo->ri_NumIndices;
1292 ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false);
1294 /* AFTER ROW INSERT Triggers */
1295 ExecARInsertTriggers(estate, resultRelInfo, tuple);
1298 /* ----------------------------------------------------------------
1301 * DELETE is like UPDATE, we delete the tuple and its
1303 * ----------------------------------------------------------------
1306 ExecDelete(TupleTableSlot *slot,
1307 ItemPointer tupleid,
1310 ResultRelInfo *resultRelInfo;
1311 Relation resultRelationDesc;
1312 ItemPointerData ctid;
1316 * get information on the (current) result relation
1318 resultRelInfo = estate->es_result_relation_info;
1319 resultRelationDesc = resultRelInfo->ri_RelationDesc;
1321 /* BEFORE ROW DELETE Triggers */
1322 if (resultRelInfo->ri_TrigDesc &&
1323 resultRelInfo->ri_TrigDesc->n_before_row[TRIGGER_EVENT_DELETE] > 0)
1327 dodelete = ExecBRDeleteTriggers(estate, resultRelInfo, tupleid);
1329 if (!dodelete) /* "do nothing" */
1337 result = heap_delete(resultRelationDesc, tupleid,
1339 estate->es_snapshot->curcid);
1342 case HeapTupleSelfUpdated:
1343 /* already deleted by self; nothing to do */
1346 case HeapTupleMayBeUpdated:
1349 case HeapTupleUpdated:
1350 if (XactIsoLevel == XACT_SERIALIZABLE)
1351 elog(ERROR, "Can't serialize access due to concurrent update");
1352 else if (!(ItemPointerEquals(tupleid, &ctid)))
1354 TupleTableSlot *epqslot = EvalPlanQual(estate,
1355 resultRelInfo->ri_RangeTableIndex, &ctid);
1357 if (!TupIsNull(epqslot))
1363 /* tuple already deleted; nothing to do */
1367 elog(ERROR, "Unknown status %u from heap_delete", result);
1372 (estate->es_processed)++;
1375 * Note: Normally one would think that we have to delete index tuples
1376 * associated with the heap tuple now..
1378 * ... but in POSTGRES, we have no need to do this because the vacuum
1379 * daemon automatically opens an index scan and deletes index tuples
1380 * when it finds deleted heap tuples. -cim 9/27/89
1383 /* AFTER ROW DELETE Triggers */
1384 ExecARDeleteTriggers(estate, resultRelInfo, tupleid);
1387 /* ----------------------------------------------------------------
1390 * note: we can't run UPDATE queries with transactions
1391 * off because UPDATEs are actually INSERTs and our
1392 * scan will mistakenly loop forever, updating the tuple
1393 * it just inserted.. This should be fixed but until it
1394 * is, we don't want to get stuck in an infinite loop
1395 * which corrupts your database..
1396 * ----------------------------------------------------------------
1399 ExecUpdate(TupleTableSlot *slot,
1400 ItemPointer tupleid,
1404 ResultRelInfo *resultRelInfo;
1405 Relation resultRelationDesc;
1406 ItemPointerData ctid;
1411 * abort the operation if not running transactions
1413 if (IsBootstrapProcessingMode())
1415 elog(WARNING, "ExecUpdate: UPDATE can't run without transactions");
1420 * get the heap tuple out of the tuple table slot
1425 * get information on the (current) result relation
1427 resultRelInfo = estate->es_result_relation_info;
1428 resultRelationDesc = resultRelInfo->ri_RelationDesc;
1430 /* BEFORE ROW UPDATE Triggers */
1431 if (resultRelInfo->ri_TrigDesc &&
1432 resultRelInfo->ri_TrigDesc->n_before_row[TRIGGER_EVENT_UPDATE] > 0)
1436 newtuple = ExecBRUpdateTriggers(estate, resultRelInfo,
1439 if (newtuple == NULL) /* "do nothing" */
1442 if (newtuple != tuple) /* modified by Trigger(s) */
1445 * Insert modified tuple into tuple table slot, replacing the
1446 * original. We assume that it was allocated in per-tuple
1447 * memory context, and therefore will go away by itself. The
1448 * tuple table slot should not try to clear it.
1450 ExecStoreTuple(newtuple, slot, InvalidBuffer, false);
1456 * Check the constraints of the tuple
1458 * If we generate a new candidate tuple after EvalPlanQual testing, we
1459 * must loop back here and recheck constraints. (We don't need to
1460 * redo triggers, however. If there are any BEFORE triggers then
1461 * trigger.c will have done mark4update to lock the correct tuple, so
1462 * there's no need to do them again.)
1465 if (resultRelationDesc->rd_att->constr)
1466 ExecConstraints("ExecUpdate", resultRelInfo, slot, estate);
1469 * replace the heap tuple
1471 result = heap_update(resultRelationDesc, tupleid, tuple,
1473 estate->es_snapshot->curcid);
1476 case HeapTupleSelfUpdated:
1477 /* already deleted by self; nothing to do */
1480 case HeapTupleMayBeUpdated:
1483 case HeapTupleUpdated:
1484 if (XactIsoLevel == XACT_SERIALIZABLE)
1485 elog(ERROR, "Can't serialize access due to concurrent update");
1486 else if (!(ItemPointerEquals(tupleid, &ctid)))
1488 TupleTableSlot *epqslot = EvalPlanQual(estate,
1489 resultRelInfo->ri_RangeTableIndex, &ctid);
1491 if (!TupIsNull(epqslot))
1494 tuple = ExecRemoveJunk(estate->es_junkFilter, epqslot);
1495 slot = ExecStoreTuple(tuple,
1496 estate->es_junkFilter->jf_resultSlot,
1497 InvalidBuffer, true);
1501 /* tuple already deleted; nothing to do */
1505 elog(ERROR, "Unknown status %u from heap_update", result);
1510 (estate->es_processed)++;
1513 * Note: instead of having to update the old index tuples associated
1514 * with the heap tuple, all we do is form and insert new index tuples.
1515 * This is because UPDATEs are actually DELETEs and INSERTs and index
1516 * tuple deletion is done automagically by the vacuum daemon. All we
1517 * do is insert new index tuples. -cim 9/27/89
1523 * heap_update updates a tuple in the base relation by invalidating it
1524 * and then inserting a new tuple to the relation. As a side effect,
1525 * the tupleid of the new tuple is placed in the new tuple's t_ctid
1526 * field. So we now insert index tuples using the new tupleid stored
1530 numIndices = resultRelInfo->ri_NumIndices;
1532 ExecInsertIndexTuples(slot, &(tuple->t_self), estate, false);
1534 /* AFTER ROW UPDATE Triggers */
1535 ExecARUpdateTriggers(estate, resultRelInfo, tupleid, tuple);
1539 ExecRelCheck(ResultRelInfo *resultRelInfo,
1540 TupleTableSlot *slot, EState *estate)
1542 Relation rel = resultRelInfo->ri_RelationDesc;
1543 int ncheck = rel->rd_att->constr->num_check;
1544 ConstrCheck *check = rel->rd_att->constr->check;
1545 ExprContext *econtext;
1546 MemoryContext oldContext;
1551 * If first time through for this result relation, build expression
1552 * nodetrees for rel's constraint expressions. Keep them in the
1553 * per-query memory context so they'll survive throughout the query.
1555 if (resultRelInfo->ri_ConstraintExprs == NULL)
1557 oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
1558 resultRelInfo->ri_ConstraintExprs =
1559 (List **) palloc(ncheck * sizeof(List *));
1560 for (i = 0; i < ncheck; i++)
1562 qual = (List *) stringToNode(check[i].ccbin);
1563 resultRelInfo->ri_ConstraintExprs[i] = qual;
1565 MemoryContextSwitchTo(oldContext);
1569 * We will use the EState's per-tuple context for evaluating
1570 * constraint expressions (creating it if it's not already there).
1572 econtext = GetPerTupleExprContext(estate);
1574 /* Arrange for econtext's scan tuple to be the tuple under test */
1575 econtext->ecxt_scantuple = slot;
1577 /* And evaluate the constraints */
1578 for (i = 0; i < ncheck; i++)
1580 qual = resultRelInfo->ri_ConstraintExprs[i];
1583 * NOTE: SQL92 specifies that a NULL result from a constraint
1584 * expression is not to be treated as a failure. Therefore, tell
1585 * ExecQual to return TRUE for NULL.
1587 if (!ExecQual(qual, econtext, true))
1588 return check[i].ccname;
1591 /* NULL result means no error */
1592 return (char *) NULL;
1596 ExecConstraints(const char *caller, ResultRelInfo *resultRelInfo,
1597 TupleTableSlot *slot, EState *estate)
1599 Relation rel = resultRelInfo->ri_RelationDesc;
1600 HeapTuple tuple = slot->val;
1601 TupleConstr *constr = rel->rd_att->constr;
1605 if (constr->has_not_null)
1607 int natts = rel->rd_att->natts;
1610 for (attrChk = 1; attrChk <= natts; attrChk++)
1612 if (rel->rd_att->attrs[attrChk - 1]->attnotnull &&
1613 heap_attisnull(tuple, attrChk))
1614 elog(ERROR, "%s: Fail to add null value in not null attribute %s",
1615 caller, NameStr(rel->rd_att->attrs[attrChk - 1]->attname));
1619 if (constr->num_check > 0)
1623 if ((failed = ExecRelCheck(resultRelInfo, slot, estate)) != NULL)
1624 elog(ERROR, "%s: rejected due to CHECK constraint \"%s\" on \"%s\"",
1625 caller, failed, RelationGetRelationName(rel));
1630 * Check a modified tuple to see if we want to process its updated version
1631 * under READ COMMITTED rules.
1633 * See backend/executor/README for some info about how this works.
1636 EvalPlanQual(EState *estate, Index rti, ItemPointer tid)
1641 HeapTupleData tuple;
1642 HeapTuple copyTuple = NULL;
1649 * find relation containing target tuple
1651 if (estate->es_result_relation_info != NULL &&
1652 estate->es_result_relation_info->ri_RangeTableIndex == rti)
1653 relation = estate->es_result_relation_info->ri_RelationDesc;
1659 foreach(l, estate->es_rowMark)
1661 if (((execRowMark *) lfirst(l))->rti == rti)
1663 relation = ((execRowMark *) lfirst(l))->relation;
1667 if (relation == NULL)
1668 elog(ERROR, "EvalPlanQual: can't find RTE %d", (int) rti);
1674 * Loop here to deal with updated or busy tuples
1676 tuple.t_self = *tid;
1681 if (heap_fetch(relation, SnapshotDirty, &tuple, &buffer, false, NULL))
1683 TransactionId xwait = SnapshotDirty->xmax;
1685 if (TransactionIdIsValid(SnapshotDirty->xmin))
1686 elog(ERROR, "EvalPlanQual: t_xmin is uncommitted ?!");
1689 * If tuple is being updated by other transaction then we have
1690 * to wait for its commit/abort.
1692 if (TransactionIdIsValid(xwait))
1694 ReleaseBuffer(buffer);
1695 XactLockTableWait(xwait);
1700 * We got tuple - now copy it for use by recheck query.
1702 copyTuple = heap_copytuple(&tuple);
1703 ReleaseBuffer(buffer);
1708 * Oops! Invalid tuple. Have to check is it updated or deleted.
1709 * Note that it's possible to get invalid SnapshotDirty->tid if
1710 * tuple updated by this transaction. Have we to check this ?
1712 if (ItemPointerIsValid(&(SnapshotDirty->tid)) &&
1713 !(ItemPointerEquals(&(tuple.t_self), &(SnapshotDirty->tid))))
1715 /* updated, so look at the updated copy */
1716 tuple.t_self = SnapshotDirty->tid;
1721 * Deleted or updated by this transaction; forget it.
1727 * For UPDATE/DELETE we have to return tid of actual row we're
1730 *tid = tuple.t_self;
1733 * Need to run a recheck subquery. Find or create a PQ stack entry.
1735 epq = (evalPlanQual *) estate->es_evalPlanQual;
1736 rtsize = length(estate->es_range_table);
1739 if (epq != NULL && epq->rti == 0)
1741 /* Top PQ stack entry is idle, so re-use it */
1742 Assert(!(estate->es_useEvalPlan) &&
1743 epq->estate.es_evalPlanQual == NULL);
1749 * If this is request for another RTE - Ra, - then we have to check
1750 * wasn't PlanQual requested for Ra already and if so then Ra' row was
1751 * updated again and we have to re-start old execution for Ra and
1752 * forget all what we done after Ra was suspended. Cool? -:))
1754 if (epq != NULL && epq->rti != rti &&
1755 epq->estate.es_evTuple[rti - 1] != NULL)
1759 evalPlanQual *oldepq;
1761 /* pop previous PlanQual from the stack */
1762 epqstate = &(epq->estate);
1763 oldepq = (evalPlanQual *) epqstate->es_evalPlanQual;
1764 Assert(oldepq->rti != 0);
1765 /* stop execution */
1766 ExecEndNode(epq->plan, NULL);
1767 ExecDropTupleTable(epqstate->es_tupleTable, true);
1768 epqstate->es_tupleTable = NULL;
1769 heap_freetuple(epqstate->es_evTuple[epq->rti - 1]);
1770 epqstate->es_evTuple[epq->rti - 1] = NULL;
1771 /* push current PQ to freePQ stack */
1774 estate->es_evalPlanQual = (Pointer) epq;
1775 } while (epq->rti != rti);
1779 * If we are requested for another RTE then we have to suspend
1780 * execution of current PlanQual and start execution for new one.
1782 if (epq == NULL || epq->rti != rti)
1784 /* try to reuse plan used previously */
1785 evalPlanQual *newepq = (epq != NULL) ? epq->free : NULL;
1787 if (newepq == NULL) /* first call or freePQ stack is empty */
1789 newepq = (evalPlanQual *) palloc(sizeof(evalPlanQual));
1790 newepq->free = NULL;
1793 * Each stack level has its own copy of the plan tree. This
1794 * is wasteful, but necessary as long as plan nodes point to
1795 * exec state nodes rather than vice versa. Note that
1796 * copyfuncs.c doesn't attempt to copy the exec state nodes,
1797 * which is a good thing in this situation.
1799 newepq->plan = copyObject(estate->es_origPlan);
1802 * Init stack level's EState. We share top level's copy of
1803 * es_result_relations array and other non-changing status. We
1804 * need our own tupletable, es_param_exec_vals, and other
1807 epqstate = &(newepq->estate);
1808 memcpy(epqstate, estate, sizeof(EState));
1809 epqstate->es_direction = ForwardScanDirection;
1810 if (estate->es_origPlan->nParamExec > 0)
1811 epqstate->es_param_exec_vals = (ParamExecData *)
1812 palloc(estate->es_origPlan->nParamExec *
1813 sizeof(ParamExecData));
1814 epqstate->es_tupleTable = NULL;
1815 epqstate->es_per_tuple_exprcontext = NULL;
1818 * Each epqstate must have its own es_evTupleNull state, but
1819 * all the stack entries share es_evTuple state. This allows
1820 * sub-rechecks to inherit the value being examined by an
1823 epqstate->es_evTupleNull = (bool *) palloc(rtsize * sizeof(bool));
1825 /* first PQ stack entry */
1826 epqstate->es_evTuple = (HeapTuple *)
1827 palloc0(rtsize * sizeof(HeapTuple));
1829 /* later stack entries share the same storage */
1830 epqstate->es_evTuple = epq->estate.es_evTuple;
1834 /* recycle previously used EState */
1835 epqstate = &(newepq->estate);
1837 /* push current PQ to the stack */
1838 epqstate->es_evalPlanQual = (Pointer) epq;
1840 estate->es_evalPlanQual = (Pointer) epq;
1845 Assert(epq->rti == rti);
1846 epqstate = &(epq->estate);
1849 * Ok - we're requested for the same RTE. Unfortunately we still have
1850 * to end and restart execution of the plan, because ExecReScan
1851 * wouldn't ensure that upper plan nodes would reset themselves. We
1852 * could make that work if insertion of the target tuple were
1853 * integrated with the Param mechanism somehow, so that the upper plan
1854 * nodes know that their children's outputs have changed.
1858 /* stop execution */
1859 ExecEndNode(epq->plan, NULL);
1860 ExecDropTupleTable(epqstate->es_tupleTable, true);
1861 epqstate->es_tupleTable = NULL;
1865 * free old RTE' tuple, if any, and store target tuple where
1866 * relation's scan node will see it
1868 if (epqstate->es_evTuple[rti - 1] != NULL)
1869 heap_freetuple(epqstate->es_evTuple[rti - 1]);
1870 epqstate->es_evTuple[rti - 1] = copyTuple;
1873 * Initialize for new recheck query; be careful to copy down state
1874 * that might have changed in top EState.
1876 epqstate->es_result_relation_info = estate->es_result_relation_info;
1877 epqstate->es_junkFilter = estate->es_junkFilter;
1878 if (estate->es_origPlan->nParamExec > 0)
1879 memset(epqstate->es_param_exec_vals, 0,
1880 estate->es_origPlan->nParamExec * sizeof(ParamExecData));
1881 memset(epqstate->es_evTupleNull, false, rtsize * sizeof(bool));
1882 epqstate->es_useEvalPlan = false;
1883 Assert(epqstate->es_tupleTable == NULL);
1884 epqstate->es_tupleTable =
1885 ExecCreateTupleTable(estate->es_tupleTable->size);
1887 ExecInitNode(epq->plan, epqstate, NULL);
1889 return EvalPlanQualNext(estate);
1892 static TupleTableSlot *
1893 EvalPlanQualNext(EState *estate)
1895 evalPlanQual *epq = (evalPlanQual *) estate->es_evalPlanQual;
1896 EState *epqstate = &(epq->estate);
1897 evalPlanQual *oldepq;
1898 TupleTableSlot *slot;
1900 Assert(epq->rti != 0);
1903 slot = ExecProcNode(epq->plan, NULL);
1906 * No more tuples for this PQ. Continue previous one.
1908 if (TupIsNull(slot))
1910 /* stop execution */
1911 ExecEndNode(epq->plan, NULL);
1912 ExecDropTupleTable(epqstate->es_tupleTable, true);
1913 epqstate->es_tupleTable = NULL;
1914 heap_freetuple(epqstate->es_evTuple[epq->rti - 1]);
1915 epqstate->es_evTuple[epq->rti - 1] = NULL;
1916 /* pop old PQ from the stack */
1917 oldepq = (evalPlanQual *) epqstate->es_evalPlanQual;
1918 if (oldepq == (evalPlanQual *) NULL)
1920 epq->rti = 0; /* this is the first (oldest) */
1921 estate->es_useEvalPlan = false; /* PQ - mark as free and */
1922 return (NULL); /* continue Query execution */
1924 Assert(oldepq->rti != 0);
1925 /* push current PQ to freePQ stack */
1928 epqstate = &(epq->estate);
1929 estate->es_evalPlanQual = (Pointer) epq;
1937 EndEvalPlanQual(EState *estate)
1939 evalPlanQual *epq = (evalPlanQual *) estate->es_evalPlanQual;
1940 EState *epqstate = &(epq->estate);
1941 evalPlanQual *oldepq;
1943 if (epq->rti == 0) /* plans already shutdowned */
1945 Assert(epq->estate.es_evalPlanQual == NULL);
1951 /* stop execution */
1952 ExecEndNode(epq->plan, NULL);
1953 ExecDropTupleTable(epqstate->es_tupleTable, true);
1954 epqstate->es_tupleTable = NULL;
1955 if (epqstate->es_evTuple[epq->rti - 1] != NULL)
1957 heap_freetuple(epqstate->es_evTuple[epq->rti - 1]);
1958 epqstate->es_evTuple[epq->rti - 1] = NULL;
1960 /* pop old PQ from the stack */
1961 oldepq = (evalPlanQual *) epqstate->es_evalPlanQual;
1962 if (oldepq == (evalPlanQual *) NULL)
1964 epq->rti = 0; /* this is the first (oldest) */
1965 estate->es_useEvalPlan = false; /* PQ - mark as free */
1968 Assert(oldepq->rti != 0);
1969 /* push current PQ to freePQ stack */
1972 epqstate = &(epq->estate);
1973 estate->es_evalPlanQual = (Pointer) epq;