PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
executor.h File Reference
Include dependency graph for executor.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TupOutputState
 

Macros

#define EXEC_FLAG_EXPLAIN_ONLY   0x0001 /* EXPLAIN, no ANALYZE */
 
#define EXEC_FLAG_REWIND   0x0002 /* need efficient rescan */
 
#define EXEC_FLAG_BACKWARD   0x0004 /* need backward scan */
 
#define EXEC_FLAG_MARK   0x0008 /* need mark/restore */
 
#define EXEC_FLAG_SKIP_TRIGGERS   0x0010 /* skip AfterTrigger calls */
 
#define EXEC_FLAG_WITH_OIDS   0x0020 /* force OIDs in returned tuples */
 
#define EXEC_FLAG_WITHOUT_OIDS   0x0040 /* force no OIDs in returned tuples */
 
#define EXEC_FLAG_WITH_NO_DATA   0x0080 /* rel scannability doesn't matter */
 
#define EvalPlanQualSetSlot(epqstate, slot)   ((epqstate)->origslot = (slot))
 
#define do_text_output_oneline(tstate, str_to_emit)
 
#define ResetExprContext(econtext)   MemoryContextReset((econtext)->ecxt_per_tuple_memory)
 
#define GetPerTupleExprContext(estate)
 
#define GetPerTupleMemoryContext(estate)   (GetPerTupleExprContext(estate)->ecxt_per_tuple_memory)
 
#define ResetPerTupleExprContext(estate)
 

Typedefs

typedef void(* ExecutorStart_hook_type )(QueryDesc *queryDesc, int eflags)
 
typedef void(* ExecutorRun_hook_type )(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
 
typedef void(* ExecutorFinish_hook_type )(QueryDesc *queryDesc)
 
typedef void(* ExecutorEnd_hook_type )(QueryDesc *queryDesc)
 
typedef bool(* ExecutorCheckPerms_hook_type )(List *, bool)
 
typedef TupleTableSlot *(* ExecScanAccessMtd )(ScanState *node)
 
typedef bool(* ExecScanRecheckMtd )(ScanState *node, TupleTableSlot *slot)
 
typedef struct TupOutputState TupOutputState
 

Functions

void ExecReScan (PlanState *node)
 
void ExecMarkPos (PlanState *node)
 
void ExecRestrPos (PlanState *node)
 
bool ExecSupportsMarkRestore (struct Path *pathnode)
 
bool ExecSupportsBackwardScan (Plan *node)
 
bool ExecMaterializesOutput (NodeTag plantype)
 
bool execCurrentOf (CurrentOfExpr *cexpr, ExprContext *econtext, Oid table_oid, ItemPointer current_tid)
 
bool execTuplesMatch (TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
 
bool execTuplesUnequal (TupleTableSlot *slot1, TupleTableSlot *slot2, int numCols, AttrNumber *matchColIdx, FmgrInfo *eqfunctions, MemoryContext evalContext)
 
FmgrInfoexecTuplesMatchPrepare (int numCols, Oid *eqOperators)
 
void execTuplesHashPrepare (int numCols, Oid *eqOperators, FmgrInfo **eqFunctions, FmgrInfo **hashFunctions)
 
TupleHashTable BuildTupleHashTable (int numCols, AttrNumber *keyColIdx, FmgrInfo *eqfunctions, FmgrInfo *hashfunctions, long nbuckets, Size additionalsize, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
 
TupleHashEntry LookupTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew)
 
TupleHashEntry FindTupleHashEntry (TupleHashTable hashtable, TupleTableSlot *slot, FmgrInfo *eqfunctions, FmgrInfo *hashfunctions)
 
JunkFilterExecInitJunkFilter (List *targetList, bool hasoid, TupleTableSlot *slot)
 
JunkFilterExecInitJunkFilterConversion (List *targetList, TupleDesc cleanTupType, TupleTableSlot *slot)
 
AttrNumber ExecFindJunkAttribute (JunkFilter *junkfilter, const char *attrName)
 
AttrNumber ExecFindJunkAttributeInTlist (List *targetlist, const char *attrName)
 
Datum ExecGetJunkAttribute (TupleTableSlot *slot, AttrNumber attno, bool *isNull)
 
TupleTableSlotExecFilterJunk (JunkFilter *junkfilter, TupleTableSlot *slot)
 
void ExecutorStart (QueryDesc *queryDesc, int eflags)
 
void standard_ExecutorStart (QueryDesc *queryDesc, int eflags)
 
void ExecutorRun (QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
 
void standard_ExecutorRun (QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
 
void ExecutorFinish (QueryDesc *queryDesc)
 
void standard_ExecutorFinish (QueryDesc *queryDesc)
 
void ExecutorEnd (QueryDesc *queryDesc)
 
void standard_ExecutorEnd (QueryDesc *queryDesc)
 
void ExecutorRewind (QueryDesc *queryDesc)
 
bool ExecCheckRTPerms (List *rangeTable, bool ereport_on_violation)
 
void CheckValidResultRel (Relation resultRel, CmdType operation)
 
void InitResultRelInfo (ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, Relation partition_root, int instrument_options)
 
ResultRelInfoExecGetTriggerResultRel (EState *estate, Oid relid)
 
void ExecCleanUpTriggerState (EState *estate)
 
bool ExecContextForcesOids (PlanState *planstate, bool *hasoids)
 
void ExecConstraints (ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate)
 
void ExecWithCheckOptions (WCOKind kind, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate)
 
LockTupleMode ExecUpdateLockMode (EState *estate, ResultRelInfo *relinfo)
 
ExecRowMarkExecFindRowMark (EState *estate, Index rti, bool missing_ok)
 
ExecAuxRowMarkExecBuildAuxRowMark (ExecRowMark *erm, List *targetlist)
 
TupleTableSlotEvalPlanQual (EState *estate, EPQState *epqstate, Relation relation, Index rti, int lockmode, ItemPointer tid, TransactionId priorXmax)
 
HeapTuple EvalPlanQualFetch (EState *estate, Relation relation, int lockmode, LockWaitPolicy wait_policy, ItemPointer tid, TransactionId priorXmax)
 
void EvalPlanQualInit (EPQState *epqstate, EState *estate, Plan *subplan, List *auxrowmarks, int epqParam)
 
void EvalPlanQualSetPlan (EPQState *epqstate, Plan *subplan, List *auxrowmarks)
 
void EvalPlanQualSetTuple (EPQState *epqstate, Index rti, HeapTuple tuple)
 
HeapTuple EvalPlanQualGetTuple (EPQState *epqstate, Index rti)
 
void ExecSetupPartitionTupleRouting (Relation rel, PartitionDispatch **pd, ResultRelInfo **partitions, TupleConversionMap ***tup_conv_maps, TupleTableSlot **partition_tuple_slot, int *num_parted, int *num_partitions)
 
int ExecFindPartition (ResultRelInfo *resultRelInfo, PartitionDispatch *pd, TupleTableSlot *slot, EState *estate)
 
void EvalPlanQualFetchRowMarks (EPQState *epqstate)
 
TupleTableSlotEvalPlanQualNext (EPQState *epqstate)
 
void EvalPlanQualBegin (EPQState *epqstate, EState *parentestate)
 
void EvalPlanQualEnd (EPQState *epqstate)
 
PlanStateExecInitNode (Plan *node, EState *estate, int eflags)
 
TupleTableSlotExecProcNode (PlanState *node)
 
NodeMultiExecProcNode (PlanState *node)
 
void ExecEndNode (PlanState *node)
 
bool ExecShutdownNode (PlanState *node)
 
ExprStateExecInitExpr (Expr *node, PlanState *parent)
 
ExprStateExecInitQual (List *qual, PlanState *parent)
 
ExprStateExecInitCheck (List *qual, PlanState *parent)
 
ListExecInitExprList (List *nodes, PlanState *parent)
 
ProjectionInfoExecBuildProjectionInfo (List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
 
ExprStateExecPrepareExpr (Expr *node, EState *estate)
 
ExprStateExecPrepareQual (List *qual, EState *estate)
 
ExprStateExecPrepareCheck (List *qual, EState *estate)
 
ListExecPrepareExprList (List *nodes, EState *estate)
 
static Datum ExecEvalExpr (ExprState *state, ExprContext *econtext, bool *isNull)
 
static Datum ExecEvalExprSwitchContext (ExprState *state, ExprContext *econtext, bool *isNull)
 
static TupleTableSlotExecProject (ProjectionInfo *projInfo)
 
static bool ExecQual (ExprState *state, ExprContext *econtext)
 
bool ExecCheck (ExprState *state, ExprContext *context)
 
SetExprStateExecInitTableFunctionResult (Expr *expr, ExprContext *econtext, PlanState *parent)
 
TuplestorestateExecMakeTableFunctionResult (SetExprState *setexpr, ExprContext *econtext, MemoryContext argContext, TupleDesc expectedDesc, bool randomAccess)
 
SetExprStateExecInitFunctionResultSet (Expr *expr, ExprContext *econtext, PlanState *parent)
 
Datum ExecMakeFunctionResultSet (SetExprState *fcache, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone)
 
TupleTableSlotExecScan (ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
 
void ExecAssignScanProjectionInfo (ScanState *node)
 
void ExecAssignScanProjectionInfoWithVarno (ScanState *node, Index varno)
 
void ExecScanReScan (ScanState *node)
 
void ExecInitResultTupleSlot (EState *estate, PlanState *planstate)
 
void ExecInitScanTupleSlot (EState *estate, ScanState *scanstate)
 
TupleTableSlotExecInitExtraTupleSlot (EState *estate)
 
TupleTableSlotExecInitNullTupleSlot (EState *estate, TupleDesc tupType)
 
TupleDesc ExecTypeFromTL (List *targetList, bool hasoid)
 
TupleDesc ExecCleanTypeFromTL (List *targetList, bool hasoid)
 
TupleDesc ExecTypeFromExprList (List *exprList)
 
void ExecTypeSetColNames (TupleDesc typeInfo, List *namesList)
 
void UpdateChangedParamSet (PlanState *node, Bitmapset *newchg)
 
TupOutputStatebegin_tup_output_tupdesc (DestReceiver *dest, TupleDesc tupdesc)
 
void do_tup_output (TupOutputState *tstate, Datum *values, bool *isnull)
 
void do_text_output_multiline (TupOutputState *tstate, const char *txt)
 
void end_tup_output (TupOutputState *tstate)
 
EStateCreateExecutorState (void)
 
void FreeExecutorState (EState *estate)
 
ExprContextCreateExprContext (EState *estate)
 
ExprContextCreateStandaloneExprContext (void)
 
void FreeExprContext (ExprContext *econtext, bool isCommit)
 
void ReScanExprContext (ExprContext *econtext)
 
ExprContextMakePerTupleExprContext (EState *estate)
 
void ExecAssignExprContext (EState *estate, PlanState *planstate)
 
void ExecAssignResultType (PlanState *planstate, TupleDesc tupDesc)
 
void ExecAssignResultTypeFromTL (PlanState *planstate)
 
TupleDesc ExecGetResultType (PlanState *planstate)
 
void ExecAssignProjectionInfo (PlanState *planstate, TupleDesc inputDesc)
 
void ExecFreeExprContext (PlanState *planstate)
 
void ExecAssignScanType (ScanState *scanstate, TupleDesc tupDesc)
 
void ExecAssignScanTypeFromOuterPlan (ScanState *scanstate)
 
bool ExecRelationIsTargetRelation (EState *estate, Index scanrelid)
 
Relation ExecOpenScanRelation (EState *estate, Index scanrelid, int eflags)
 
void ExecCloseScanRelation (Relation scanrel)
 
int executor_errposition (EState *estate, int location)
 
void RegisterExprContextCallback (ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
 
void UnregisterExprContextCallback (ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
 
void ExecLockNonLeafAppendTables (List *partitioned_rels, EState *estate)
 
Datum GetAttributeByName (HeapTupleHeader tuple, const char *attname, bool *isNull)
 
Datum GetAttributeByNum (HeapTupleHeader tuple, AttrNumber attrno, bool *isNull)
 
int ExecTargetListLength (List *targetlist)
 
int ExecCleanTargetListLength (List *targetlist)
 
void ExecOpenIndices (ResultRelInfo *resultRelInfo, bool speculative)
 
void ExecCloseIndices (ResultRelInfo *resultRelInfo)
 
ListExecInsertIndexTuples (TupleTableSlot *slot, ItemPointer tupleid, EState *estate, bool noDupErr, bool *specConflict, List *arbiterIndexes)
 
bool ExecCheckIndexConstraints (TupleTableSlot *slot, EState *estate, ItemPointer conflictTid, List *arbiterIndexes)
 
void check_exclusion_constraint (Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex)
 
bool RelationFindReplTupleByIndex (Relation rel, Oid idxoid, LockTupleMode lockmode, TupleTableSlot *searchslot, TupleTableSlot *outslot)
 
bool RelationFindReplTupleSeq (Relation rel, LockTupleMode lockmode, TupleTableSlot *searchslot, TupleTableSlot *outslot)
 
void ExecSimpleRelationInsert (EState *estate, TupleTableSlot *slot)
 
void ExecSimpleRelationUpdate (EState *estate, EPQState *epqstate, TupleTableSlot *searchslot, TupleTableSlot *slot)
 
void ExecSimpleRelationDelete (EState *estate, EPQState *epqstate, TupleTableSlot *searchslot)
 
void CheckCmdReplicaIdentity (Relation rel, CmdType cmd)
 
void CheckSubscriptionRelkind (char relkind, const char *nspname, const char *relname)
 

Variables

PGDLLIMPORT ExecutorStart_hook_type ExecutorStart_hook
 
PGDLLIMPORT ExecutorRun_hook_type ExecutorRun_hook
 
PGDLLIMPORT
ExecutorFinish_hook_type 
ExecutorFinish_hook
 
PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook
 
PGDLLIMPORT
ExecutorCheckPerms_hook_type 
ExecutorCheckPerms_hook
 

Macro Definition Documentation

#define do_text_output_oneline (   tstate,
  str_to_emit 
)
Value:
do { \
Datum values_[1]; \
bool isnull_[1]; \
values_[0] = PointerGetDatum(cstring_to_text(str_to_emit)); \
isnull_[0] = false; \
do_tup_output(tstate, values_, isnull_); \
pfree(DatumGetPointer(values_[0])); \
} while (0)
#define PointerGetDatum(X)
Definition: postgres.h:562
char bool
Definition: c.h:202
void pfree(void *pointer)
Definition: mcxt.c:950
uintptr_t Datum
Definition: postgres.h:372
text * cstring_to_text(const char *s)
Definition: varlena.c:149
#define DatumGetPointer(X)
Definition: postgres.h:555
void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
Definition: execTuples.c:1250

Definition at line 429 of file executor.h.

Referenced by ExplainQuery(), and ShowGUCConfigOption().

#define EvalPlanQualSetSlot (   epqstate,
  slot 
)    ((epqstate)->origslot = (slot))
#define EXEC_FLAG_SKIP_TRIGGERS   0x0010 /* skip AfterTrigger calls */
#define EXEC_FLAG_WITH_NO_DATA   0x0080 /* rel scannability doesn't matter */

Definition at line 65 of file executor.h.

Referenced by ExecOpenScanRelation(), GetIntoRelEFlags(), and InitPlan().

#define EXEC_FLAG_WITH_OIDS   0x0020 /* force OIDs in returned tuples */

Definition at line 63 of file executor.h.

Referenced by ExecContextForcesOids(), and GetIntoRelEFlags().

#define EXEC_FLAG_WITHOUT_OIDS   0x0040 /* force no OIDs in returned tuples */

Definition at line 64 of file executor.h.

Referenced by ExecContextForcesOids(), GetIntoRelEFlags(), and refresh_matview_datafill().

#define ResetPerTupleExprContext (   estate)
Value:
do { \
if ((estate)->es_per_tuple_exprcontext) \
ResetExprContext((estate)->es_per_tuple_exprcontext); \
} while (0)
#define ResetExprContext(econtext)
Definition: executor.h:450

Definition at line 465 of file executor.h.

Referenced by comparetup_cluster(), CopyFrom(), ExecModifyTable(), ExecPostprocessPlan(), and ExecutePlan().

Typedef Documentation

typedef TupleTableSlot*(* ExecScanAccessMtd)(ScanState *node)

Definition at line 389 of file executor.h.

typedef bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)

Definition at line 390 of file executor.h.

typedef bool(* ExecutorCheckPerms_hook_type)(List *, bool)

Definition at line 88 of file executor.h.

typedef void(* ExecutorEnd_hook_type)(QueryDesc *queryDesc)

Definition at line 84 of file executor.h.

typedef void(* ExecutorFinish_hook_type)(QueryDesc *queryDesc)

Definition at line 80 of file executor.h.

typedef void(* ExecutorRun_hook_type)(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)

Definition at line 73 of file executor.h.

typedef void(* ExecutorStart_hook_type)(QueryDesc *queryDesc, int eflags)

Definition at line 69 of file executor.h.

Function Documentation

TupOutputState* begin_tup_output_tupdesc ( DestReceiver dest,
TupleDesc  tupdesc 
)

Definition at line 1232 of file execTuples.c.

References CMD_SELECT, TupOutputState::dest, MakeSingleTupleTableSlot(), palloc(), _DestReceiver::rStartup, and TupOutputState::slot.

Referenced by CreateReplicationSlot(), ExplainQuery(), IdentifySystem(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

1233 {
1234  TupOutputState *tstate;
1235 
1236  tstate = (TupOutputState *) palloc(sizeof(TupOutputState));
1237 
1238  tstate->slot = MakeSingleTupleTableSlot(tupdesc);
1239  tstate->dest = dest;
1240 
1241  (*tstate->dest->rStartup) (tstate->dest, (int) CMD_SELECT, tupdesc);
1242 
1243  return tstate;
1244 }
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.h:121
TupleTableSlot * slot
Definition: executor.h:414
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:199
void * palloc(Size size)
Definition: mcxt.c:849
DestReceiver * dest
Definition: executor.h:415
TupleHashTable BuildTupleHashTable ( int  numCols,
AttrNumber keyColIdx,
FmgrInfo eqfunctions,
FmgrInfo hashfunctions,
long  nbuckets,
Size  additionalsize,
MemoryContext  tablecxt,
MemoryContext  tempcxt,
bool  use_variable_hash_iv 
)

Definition at line 290 of file execGrouping.c.

References Assert, TupleHashTableData::cur_eq_funcs, TupleHashTableData::entrysize, TupleHashTableData::hash_iv, hash_uint32(), TupleHashTableData::hashtab, TupleHashTableData::in_hash_funcs, TupleHashTableData::inputslot, TupleHashTableData::keyColIdx, MemoryContextAlloc(), Min, NULL, TupleHashTableData::numCols, ParallelWorkerNumber, TupleHashTableData::tab_eq_funcs, TupleHashTableData::tab_hash_funcs, TupleHashTableData::tablecxt, TupleHashTableData::tableslot, TupleHashTableData::tempcxt, and work_mem.

Referenced by build_hash_table(), and buildSubPlanHash().

296 {
297  TupleHashTable hashtable;
298  Size entrysize = sizeof(TupleHashEntryData) + additionalsize;
299 
300  Assert(nbuckets > 0);
301 
302  /* Limit initial table size request to not more than work_mem */
303  nbuckets = Min(nbuckets, (long) ((work_mem * 1024L) / entrysize));
304 
305  hashtable = (TupleHashTable)
306  MemoryContextAlloc(tablecxt, sizeof(TupleHashTableData));
307 
308  hashtable->numCols = numCols;
309  hashtable->keyColIdx = keyColIdx;
310  hashtable->tab_hash_funcs = hashfunctions;
311  hashtable->tab_eq_funcs = eqfunctions;
312  hashtable->tablecxt = tablecxt;
313  hashtable->tempcxt = tempcxt;
314  hashtable->entrysize = entrysize;
315  hashtable->tableslot = NULL; /* will be made on first lookup */
316  hashtable->inputslot = NULL;
317  hashtable->in_hash_funcs = NULL;
318  hashtable->cur_eq_funcs = NULL;
319 
320  /*
321  * If parallelism is in use, even if the master backend is performing the
322  * scan itself, we don't want to create the hashtable exactly the same way
323  * in all workers. As hashtables are iterated over in keyspace-order,
324  * doing so in all processes in the same way is likely to lead to
325  * "unbalanced" hashtables when the table size initially is
326  * underestimated.
327  */
328  if (use_variable_hash_iv)
330  else
331  hashtable->hash_iv = 0;
332 
333  hashtable->hashtab = tuplehash_create(tablecxt, nbuckets, hashtable);
334 
335  return hashtable;
336 }
TupleTableSlot * inputslot
Definition: execnodes.h:592
#define Min(x, y)
Definition: c.h:806
AttrNumber * keyColIdx
Definition: execnodes.h:584
FmgrInfo * tab_hash_funcs
Definition: execnodes.h:585
FmgrInfo * in_hash_funcs
Definition: execnodes.h:593
struct TupleHashEntryData TupleHashEntryData
MemoryContext tablecxt
Definition: execnodes.h:587
struct TupleHashTableData * TupleHashTable
Definition: execnodes.h:562
int ParallelWorkerNumber
Definition: parallel.c:94
Datum hash_uint32(uint32 k)
Definition: hashfunc.c:512
int work_mem
Definition: globals.c:112
tuplehash_hash * hashtab
Definition: execnodes.h:582
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
TupleTableSlot * tableslot
Definition: execnodes.h:590
size_t Size
Definition: c.h:356
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:707
FmgrInfo * cur_eq_funcs
Definition: execnodes.h:594
MemoryContext tempcxt
Definition: execnodes.h:588
FmgrInfo * tab_eq_funcs
Definition: execnodes.h:586
void check_exclusion_constraint ( Relation  heap,
Relation  index,
IndexInfo indexInfo,
ItemPointer  tupleid,
Datum values,
bool isnull,
EState estate,
bool  newIndex 
)

Definition at line 863 of file execIndexing.c.

References CEOUC_WAIT, check_exclusion_or_unique_constraint(), and NULL.

Referenced by IndexCheckExclusion(), and unique_key_recheck().

868 {
869  (void) check_exclusion_or_unique_constraint(heap, index, indexInfo, tupleid,
870  values, isnull,
871  estate, newIndex,
872  CEOUC_WAIT, false, NULL);
873 }
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex, CEOUC_WAIT_MODE waitMode, bool errorOK, ItemPointer conflictTid)
Definition: execIndexing.c:639
#define NULL
Definition: c.h:229
static Datum values[MAXATTR]
Definition: bootstrap.c:163
void CheckCmdReplicaIdentity ( Relation  rel,
CmdType  cmd 
)

Definition at line 522 of file execReplication.c.

References CMD_DELETE, CMD_UPDATE, ereport, errcode(), errhint(), errmsg(), ERROR, GetRelationPublicationActions(), OidIsValid, PublicationActions::pubdelete, PublicationActions::pubupdate, RelationData::rd_rel, RelationGetRelationName, RelationGetReplicaIndex(), and REPLICA_IDENTITY_FULL.

Referenced by CheckValidResultRel(), ExecSimpleRelationDelete(), ExecSimpleRelationInsert(), and ExecSimpleRelationUpdate().

523 {
524  PublicationActions *pubactions;
525 
526  /* We only need to do checks for UPDATE and DELETE. */
527  if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
528  return;
529 
530  /* If relation has replica identity we are always good. */
531  if (rel->rd_rel->relreplident == REPLICA_IDENTITY_FULL ||
533  return;
534 
535  /*
536  * This is either UPDATE OR DELETE and there is no replica identity.
537  *
538  * Check if the table publishes UPDATES or DELETES.
539  */
540  pubactions = GetRelationPublicationActions(rel);
541  if (cmd == CMD_UPDATE && pubactions->pubupdate)
542  ereport(ERROR,
543  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
544  errmsg("cannot update table \"%s\" because it does not have replica identity and publishes updates",
546  errhint("To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.")));
547  else if (cmd == CMD_DELETE && pubactions->pubdelete)
548  ereport(ERROR,
549  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
550  errmsg("cannot delete from table \"%s\" because it does not have replica identity and publishes deletes",
552  errhint("To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.")));
553 }
int errhint(const char *fmt,...)
Definition: elog.c:987
Oid RelationGetReplicaIndex(Relation relation)
Definition: relcache.c:4676
int errcode(int sqlerrcode)
Definition: elog.c:575
Form_pg_class rd_rel
Definition: rel.h:114
#define OidIsValid(objectId)
Definition: c.h:538
#define REPLICA_IDENTITY_FULL
Definition: pg_class.h:179
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define ereport(elevel, rest)
Definition: elog.h:122
struct PublicationActions * GetRelationPublicationActions(Relation relation)
Definition: relcache.c:5172
int errmsg(const char *fmt,...)
Definition: elog.c:797
void CheckSubscriptionRelkind ( char  relkind,
const char *  nspname,
const char *  relname 
)

Definition at line 562 of file execReplication.c.

References ereport, errcode(), errmsg(), ERROR, and RELKIND_RELATION.

Referenced by AlterSubscription_refresh(), CreateSubscription(), and logicalrep_rel_open().

564 {
565  /*
566  * We currently only support writing to regular tables.
567  */
568  if (relkind != RELKIND_RELATION)
569  ereport(ERROR,
570  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
571  errmsg("logical replication target relation \"%s.%s\" is not a table",
572  nspname, relname)));
573 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_RELATION
Definition: pg_class.h:160
void CheckValidResultRel ( Relation  resultRel,
CmdType  operation 
)

Definition at line 1097 of file execMain.c.

References CheckCmdReplicaIdentity(), CMD_DELETE, CMD_INSERT, CMD_UPDATE, elog, ereport, errcode(), errhint(), errmsg(), ERROR, FdwRoutine::ExecForeignDelete, FdwRoutine::ExecForeignInsert, FdwRoutine::ExecForeignUpdate, GetFdwRoutineForRelation(), FdwRoutine::IsForeignRelUpdatable, MatViewIncrementalMaintenanceIsEnabled(), NULL, RelationData::rd_rel, RelationGetRelationName, RELKIND_FOREIGN_TABLE, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_TOASTVALUE, RELKIND_VIEW, TriggerDesc::trig_delete_instead_row, TriggerDesc::trig_insert_instead_row, TriggerDesc::trig_update_instead_row, and RelationData::trigdesc.

Referenced by ExecInitModifyTable(), and ExecSetupPartitionTupleRouting().

1098 {
1099  TriggerDesc *trigDesc = resultRel->trigdesc;
1100  FdwRoutine *fdwroutine;
1101 
1102  switch (resultRel->rd_rel->relkind)
1103  {
1104  case RELKIND_RELATION:
1106  CheckCmdReplicaIdentity(resultRel, operation);
1107  break;
1108  case RELKIND_SEQUENCE:
1109  ereport(ERROR,
1110  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1111  errmsg("cannot change sequence \"%s\"",
1112  RelationGetRelationName(resultRel))));
1113  break;
1114  case RELKIND_TOASTVALUE:
1115  ereport(ERROR,
1116  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1117  errmsg("cannot change TOAST relation \"%s\"",
1118  RelationGetRelationName(resultRel))));
1119  break;
1120  case RELKIND_VIEW:
1121 
1122  /*
1123  * Okay only if there's a suitable INSTEAD OF trigger. Messages
1124  * here should match rewriteHandler.c's rewriteTargetView, except
1125  * that we omit errdetail because we haven't got the information
1126  * handy (and given that we really shouldn't get here anyway, it's
1127  * not worth great exertion to get).
1128  */
1129  switch (operation)
1130  {
1131  case CMD_INSERT:
1132  if (!trigDesc || !trigDesc->trig_insert_instead_row)
1133  ereport(ERROR,
1134  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1135  errmsg("cannot insert into view \"%s\"",
1136  RelationGetRelationName(resultRel)),
1137  errhint("To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.")));
1138  break;
1139  case CMD_UPDATE:
1140  if (!trigDesc || !trigDesc->trig_update_instead_row)
1141  ereport(ERROR,
1142  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1143  errmsg("cannot update view \"%s\"",
1144  RelationGetRelationName(resultRel)),
1145  errhint("To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.")));
1146  break;
1147  case CMD_DELETE:
1148  if (!trigDesc || !trigDesc->trig_delete_instead_row)
1149  ereport(ERROR,
1150  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1151  errmsg("cannot delete from view \"%s\"",
1152  RelationGetRelationName(resultRel)),
1153  errhint("To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.")));
1154  break;
1155  default:
1156  elog(ERROR, "unrecognized CmdType: %d", (int) operation);
1157  break;
1158  }
1159  break;
1160  case RELKIND_MATVIEW:
1162  ereport(ERROR,
1163  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1164  errmsg("cannot change materialized view \"%s\"",
1165  RelationGetRelationName(resultRel))));
1166  break;
1167  case RELKIND_FOREIGN_TABLE:
1168  /* Okay only if the FDW supports it */
1169  fdwroutine = GetFdwRoutineForRelation(resultRel, false);
1170  switch (operation)
1171  {
1172  case CMD_INSERT:
1173  if (fdwroutine->ExecForeignInsert == NULL)
1174  ereport(ERROR,
1175  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1176  errmsg("cannot insert into foreign table \"%s\"",
1177  RelationGetRelationName(resultRel))));
1178  if (fdwroutine->IsForeignRelUpdatable != NULL &&
1179  (fdwroutine->IsForeignRelUpdatable(resultRel) & (1 << CMD_INSERT)) == 0)
1180  ereport(ERROR,
1181  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1182  errmsg("foreign table \"%s\" does not allow inserts",
1183  RelationGetRelationName(resultRel))));
1184  break;
1185  case CMD_UPDATE:
1186  if (fdwroutine->ExecForeignUpdate == NULL)
1187  ereport(ERROR,
1188  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1189  errmsg("cannot update foreign table \"%s\"",
1190  RelationGetRelationName(resultRel))));
1191  if (fdwroutine->IsForeignRelUpdatable != NULL &&
1192  (fdwroutine->IsForeignRelUpdatable(resultRel) & (1 << CMD_UPDATE)) == 0)
1193  ereport(ERROR,
1194  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1195  errmsg("foreign table \"%s\" does not allow updates",
1196  RelationGetRelationName(resultRel))));
1197  break;
1198  case CMD_DELETE:
1199  if (fdwroutine->ExecForeignDelete == NULL)
1200  ereport(ERROR,
1201  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1202  errmsg("cannot delete from foreign table \"%s\"",
1203  RelationGetRelationName(resultRel))));
1204  if (fdwroutine->IsForeignRelUpdatable != NULL &&
1205  (fdwroutine->IsForeignRelUpdatable(resultRel) & (1 << CMD_DELETE)) == 0)
1206  ereport(ERROR,
1207  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1208  errmsg("foreign table \"%s\" does not allow deletes",
1209  RelationGetRelationName(resultRel))));
1210  break;
1211  default:
1212  elog(ERROR, "unrecognized CmdType: %d", (int) operation);
1213  break;
1214  }
1215  break;
1216  default:
1217  ereport(ERROR,
1218  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1219  errmsg("cannot change relation \"%s\"",
1220  RelationGetRelationName(resultRel))));
1221  break;
1222  }
1223 }
ExecForeignDelete_function ExecForeignDelete
Definition: fdwapi.h:199
int errhint(const char *fmt,...)
Definition: elog.c:987
bool MatViewIncrementalMaintenanceIsEnabled(void)
Definition: matview.c:860
ExecForeignInsert_function ExecForeignInsert
Definition: fdwapi.h:197
#define RELKIND_MATVIEW
Definition: pg_class.h:165
int errcode(int sqlerrcode)
Definition: elog.c:575
Form_pg_class rd_rel
Definition: rel.h:114
bool trig_insert_instead_row
Definition: reltrigger.h:57
#define ERROR
Definition: elog.h:43
TriggerDesc * trigdesc
Definition: rel.h:120
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
void CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
#define ereport(elevel, rest)
Definition: elog.h:122
bool trig_update_instead_row
Definition: reltrigger.h:62
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
bool trig_delete_instead_row
Definition: reltrigger.h:67
#define RELKIND_TOASTVALUE
Definition: pg_class.h:163
ExecForeignUpdate_function ExecForeignUpdate
Definition: fdwapi.h:198
#define NULL
Definition: c.h:229
int errmsg(const char *fmt,...)
Definition: elog.c:797
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:395
#define RELKIND_VIEW
Definition: pg_class.h:164
IsForeignRelUpdatable_function IsForeignRelUpdatable
Definition: fdwapi.h:201
#define elog
Definition: elog.h:219
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
EState* CreateExecutorState ( void  )

Definition at line 80 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), CurrentMemoryContext, EState::es_auxmodifytables, EState::es_crosscheck_snapshot, EState::es_direction, EState::es_epqScanDone, EState::es_epqTuple, EState::es_epqTupleSet, EState::es_exprcontexts, EState::es_finished, EState::es_instrument, EState::es_junkFilter, EState::es_lastoid, EState::es_num_result_relations, EState::es_output_cid, EState::es_param_exec_vals, EState::es_param_list_info, EState::es_per_tuple_exprcontext, EState::es_plannedstmt, EState::es_processed, EState::es_query_cxt, EState::es_queryEnv, EState::es_range_table, EState::es_result_relation_info, EState::es_result_relations, EState::es_rowMarks, EState::es_snapshot, EState::es_sourceText, EState::es_subplanstates, EState::es_top_eflags, EState::es_trig_newtup_slot, EState::es_trig_oldtup_slot, EState::es_trig_target_relations, EState::es_trig_tuple_slot, EState::es_tupleTable, ForwardScanDirection, InvalidOid, InvalidSnapshot, makeNode, MemoryContextSwitchTo(), NIL, and NULL.

Referenced by afterTriggerInvokeEvents(), ATRewriteTable(), compute_index_stats(), CopyFrom(), create_estate_for_relation(), EvalPlanQualStart(), evaluate_expr(), ExecuteQuery(), ExecuteTruncate(), ExplainExecuteQuery(), get_actual_variable_range(), get_qual_for_range(), IndexBuildHeapRangeScan(), IndexCheckExclusion(), operator_predicate_proof(), plpgsql_create_econtext(), plpgsql_inline_handler(), standard_ExecutorStart(), tuplesort_begin_cluster(), unique_key_recheck(), validate_index_heapscan(), validateCheckConstraint(), and validateDomainConstraint().

81 {
82  EState *estate;
83  MemoryContext qcontext;
84  MemoryContext oldcontext;
85 
86  /*
87  * Create the per-query context for this Executor run.
88  */
90  "ExecutorState",
92 
93  /*
94  * Make the EState node within the per-query context. This way, we don't
95  * need a separate pfree() operation for it at shutdown.
96  */
97  oldcontext = MemoryContextSwitchTo(qcontext);
98 
99  estate = makeNode(EState);
100 
101  /*
102  * Initialize all fields of the Executor State structure
103  */
105  estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
106  estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
107  estate->es_range_table = NIL;
108  estate->es_plannedstmt = NULL;
109 
110  estate->es_junkFilter = NULL;
111 
112  estate->es_output_cid = (CommandId) 0;
113 
114  estate->es_result_relations = NULL;
115  estate->es_num_result_relations = 0;
116  estate->es_result_relation_info = NULL;
117 
118  estate->es_trig_target_relations = NIL;
119  estate->es_trig_tuple_slot = NULL;
120  estate->es_trig_oldtup_slot = NULL;
121  estate->es_trig_newtup_slot = NULL;
122 
123  estate->es_param_list_info = NULL;
124  estate->es_param_exec_vals = NULL;
125 
126  estate->es_queryEnv = NULL;
127 
128  estate->es_query_cxt = qcontext;
129 
130  estate->es_tupleTable = NIL;
131 
132  estate->es_rowMarks = NIL;
133 
134  estate->es_processed = 0;
135  estate->es_lastoid = InvalidOid;
136 
137  estate->es_top_eflags = 0;
138  estate->es_instrument = 0;
139  estate->es_finished = false;
140 
141  estate->es_exprcontexts = NIL;
142 
143  estate->es_subplanstates = NIL;
144 
145  estate->es_auxmodifytables = NIL;
146 
147  estate->es_per_tuple_exprcontext = NULL;
148 
149  estate->es_epqTuple = NULL;
150  estate->es_epqTupleSet = NULL;
151  estate->es_epqScanDone = NULL;
152  estate->es_sourceText = NULL;
153 
154  /*
155  * Return the executor state structure
156  */
157  MemoryContextSwitchTo(oldcontext);
158 
159  return estate;
160 }
#define NIL
Definition: pg_list.h:69
uint32 CommandId
Definition: c.h:411
HeapTuple * es_epqTuple
Definition: execnodes.h:483
JunkFilter * es_junkFilter
Definition: execnodes.h:415
CommandId es_output_cid
Definition: execnodes.h:418
TupleTableSlot * es_trig_newtup_slot
Definition: execnodes.h:439
Oid es_lastoid
Definition: execnodes.h:455
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
PlannedStmt * es_plannedstmt
Definition: execnodes.h:412
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:410
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:472
Snapshot es_snapshot
Definition: execnodes.h:409
List * es_range_table
Definition: execnodes.h:411
ScanDirection es_direction
Definition: execnodes.h:408
const char * es_sourceText
Definition: execnodes.h:413
ParamExecData * es_param_exec_vals
Definition: execnodes.h:443
MemoryContext es_query_cxt
Definition: execnodes.h:448
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
ResultRelInfo * es_result_relations
Definition: execnodes.h:421
TupleTableSlot * es_trig_oldtup_slot
Definition: execnodes.h:438
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
int es_instrument
Definition: execnodes.h:458
TupleTableSlot * es_trig_tuple_slot
Definition: execnodes.h:437
QueryEnvironment * es_queryEnv
Definition: execnodes.h:445
#define InvalidSnapshot
Definition: snapshot.h:25
List * es_trig_target_relations
Definition: execnodes.h:436
List * es_tupleTable
Definition: execnodes.h:450
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
List * es_auxmodifytables
Definition: execnodes.h:465
int es_num_result_relations
Definition: execnodes.h:422
#define InvalidOid
Definition: postgres_ext.h:36
bool es_finished
Definition: execnodes.h:459
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
uint64 es_processed
Definition: execnodes.h:454
bool * es_epqTupleSet
Definition: execnodes.h:484
List * es_subplanstates
Definition: execnodes.h:463
List * es_rowMarks
Definition: execnodes.h:452
int es_top_eflags
Definition: execnodes.h:457
bool * es_epqScanDone
Definition: execnodes.h:485
ParamListInfo es_param_list_info
Definition: execnodes.h:442
List * es_exprcontexts
Definition: execnodes.h:461
ResultRelInfo * es_result_relation_info
Definition: execnodes.h:423
ExprContext* CreateExprContext ( EState estate)

Definition at line 218 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), ExprContext::caseValue_datum, ExprContext::caseValue_isNull, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_callbacks, ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_param_exec_vals, ExprContext::ecxt_param_list_info, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, EState::es_exprcontexts, EState::es_param_exec_vals, EState::es_param_list_info, EState::es_query_cxt, lcons(), makeNode, MemoryContextSwitchTo(), and NULL.

Referenced by ExecAssignExprContext(), ExecInitMergeJoin(), ExecInitSubPlan(), MakePerTupleExprContext(), and plpgsql_create_econtext().

219 {
220  ExprContext *econtext;
221  MemoryContext oldcontext;
222 
223  /* Create the ExprContext node within the per-query memory context */
224  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
225 
226  econtext = makeNode(ExprContext);
227 
228  /* Initialize fields of ExprContext */
229  econtext->ecxt_scantuple = NULL;
230  econtext->ecxt_innertuple = NULL;
231  econtext->ecxt_outertuple = NULL;
232 
233  econtext->ecxt_per_query_memory = estate->es_query_cxt;
234 
235  /*
236  * Create working memory for expression evaluation in this context.
237  */
238  econtext->ecxt_per_tuple_memory =
240  "ExprContext",
242 
243  econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
244  econtext->ecxt_param_list_info = estate->es_param_list_info;
245 
246  econtext->ecxt_aggvalues = NULL;
247  econtext->ecxt_aggnulls = NULL;
248 
249  econtext->caseValue_datum = (Datum) 0;
250  econtext->caseValue_isNull = true;
251 
252  econtext->domainValue_datum = (Datum) 0;
253  econtext->domainValue_isNull = true;
254 
255  econtext->ecxt_estate = estate;
256 
257  econtext->ecxt_callbacks = NULL;
258 
259  /*
260  * Link the ExprContext into the EState to ensure it is shut down when the
261  * EState is freed. Because we use lcons(), shutdowns will occur in
262  * reverse order of creation, which may not be essential but can't hurt.
263  */
264  estate->es_exprcontexts = lcons(econtext, estate->es_exprcontexts);
265 
266  MemoryContextSwitchTo(oldcontext);
267 
268  return econtext;
269 }
Datum * ecxt_aggvalues
Definition: execnodes.h:213
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:203
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Datum domainValue_datum
Definition: execnodes.h:221
ParamExecData * es_param_exec_vals
Definition: execnodes.h:443
MemoryContext es_query_cxt
Definition: execnodes.h:448
Datum caseValue_datum
Definition: execnodes.h:217
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:228
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:198
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:206
struct EState * ecxt_estate
Definition: execnodes.h:225
bool domainValue_isNull
Definition: execnodes.h:222
bool * ecxt_aggnulls
Definition: execnodes.h:214
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
uintptr_t Datum
Definition: postgres.h:372
List * lcons(void *datum, List *list)
Definition: list.c:259
#define makeNode(_type_)
Definition: nodes.h:557
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:199
#define NULL
Definition: c.h:229
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:197
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:202
bool caseValue_isNull
Definition: execnodes.h:218
ParamListInfo es_param_list_info
Definition: execnodes.h:442
List * es_exprcontexts
Definition: execnodes.h:461
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:207
ExprContext* CreateStandaloneExprContext ( void  )

Definition at line 290 of file execUtils.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), ExprContext::caseValue_datum, ExprContext::caseValue_isNull, CurrentMemoryContext, ExprContext::domainValue_datum, ExprContext::domainValue_isNull, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExprContext::ecxt_callbacks, ExprContext::ecxt_estate, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, ExprContext::ecxt_param_exec_vals, ExprContext::ecxt_param_list_info, ExprContext::ecxt_per_query_memory, ExprContext::ecxt_per_tuple_memory, ExprContext::ecxt_scantuple, makeNode, and NULL.

Referenced by domain_check_input().

291 {
292  ExprContext *econtext;
293 
294  /* Create the ExprContext node within the caller's memory context */
295  econtext = makeNode(ExprContext);
296 
297  /* Initialize fields of ExprContext */
298  econtext->ecxt_scantuple = NULL;
299  econtext->ecxt_innertuple = NULL;
300  econtext->ecxt_outertuple = NULL;
301 
303 
304  /*
305  * Create working memory for expression evaluation in this context.
306  */
307  econtext->ecxt_per_tuple_memory =
309  "ExprContext",
311 
312  econtext->ecxt_param_exec_vals = NULL;
313  econtext->ecxt_param_list_info = NULL;
314 
315  econtext->ecxt_aggvalues = NULL;
316  econtext->ecxt_aggnulls = NULL;
317 
318  econtext->caseValue_datum = (Datum) 0;
319  econtext->caseValue_isNull = true;
320 
321  econtext->domainValue_datum = (Datum) 0;
322  econtext->domainValue_isNull = true;
323 
324  econtext->ecxt_estate = NULL;
325 
326  econtext->ecxt_callbacks = NULL;
327 
328  return econtext;
329 }
Datum * ecxt_aggvalues
Definition: execnodes.h:213
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:203
Datum domainValue_datum
Definition: execnodes.h:221
Datum caseValue_datum
Definition: execnodes.h:217
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:228
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:198
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:206
struct EState * ecxt_estate
Definition: execnodes.h:225
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
bool domainValue_isNull
Definition: execnodes.h:222
bool * ecxt_aggnulls
Definition: execnodes.h:214
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
uintptr_t Datum
Definition: postgres.h:372
#define makeNode(_type_)
Definition: nodes.h:557
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:199
#define NULL
Definition: c.h:229
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:197
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:202
bool caseValue_isNull
Definition: execnodes.h:218
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:207
void do_text_output_multiline ( TupOutputState tstate,
const char *  txt 
)

Definition at line 1278 of file execTuples.c.

References cstring_to_text_with_len(), DatumGetPointer, do_tup_output(), pfree(), PointerGetDatum, and values.

Referenced by ExplainQuery().

1279 {
1280  Datum values[1];
1281  bool isnull[1] = {false};
1282 
1283  while (*txt)
1284  {
1285  const char *eol;
1286  int len;
1287 
1288  eol = strchr(txt, '\n');
1289  if (eol)
1290  {
1291  len = eol - txt;
1292  eol++;
1293  }
1294  else
1295  {
1296  len = strlen(txt);
1297  eol = txt + len;
1298  }
1299 
1300  values[0] = PointerGetDatum(cstring_to_text_with_len(txt, len));
1301  do_tup_output(tstate, values, isnull);
1302  pfree(DatumGetPointer(values[0]));
1303  txt = eol;
1304  }
1305 }
#define PointerGetDatum(X)
Definition: postgres.h:562
void do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
Definition: execTuples.c:1250
void pfree(void *pointer)
Definition: mcxt.c:950
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:161
uintptr_t Datum
Definition: postgres.h:372
#define DatumGetPointer(X)
Definition: postgres.h:555
static Datum values[MAXATTR]
Definition: bootstrap.c:163
void do_tup_output ( TupOutputState tstate,
Datum values,
bool isnull 
)

Definition at line 1250 of file execTuples.c.

References TupOutputState::dest, ExecClearTuple(), ExecStoreVirtualTuple(), tupleDesc::natts, _DestReceiver::receiveSlot, TupOutputState::slot, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.

Referenced by CreateReplicationSlot(), do_text_output_multiline(), IdentifySystem(), ShowAllGUCConfig(), and StartReplication().

1251 {
1252  TupleTableSlot *slot = tstate->slot;
1253  int natts = slot->tts_tupleDescriptor->natts;
1254 
1255  /* make sure the slot is clear */
1256  ExecClearTuple(slot);
1257 
1258  /* insert data */
1259  memcpy(slot->tts_values, values, natts * sizeof(Datum));
1260  memcpy(slot->tts_isnull, isnull, natts * sizeof(bool));
1261 
1262  /* mark slot as containing a virtual tuple */
1263  ExecStoreVirtualTuple(slot);
1264 
1265  /* send the tuple to the receiver */
1266  (void) (*tstate->dest->receiveSlot) (slot, tstate->dest);
1267 
1268  /* clean up */
1269  ExecClearTuple(slot);
1270 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
Datum * tts_values
Definition: tuptable.h:125
TupleTableSlot * slot
Definition: executor.h:414
int natts
Definition: tupdesc.h:73
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
uintptr_t Datum
Definition: postgres.h:372
static Datum values[MAXATTR]
Definition: bootstrap.c:163
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
DestReceiver * dest
Definition: executor.h:415
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:488
void end_tup_output ( TupOutputState tstate)

Definition at line 1308 of file execTuples.c.

References TupOutputState::dest, ExecDropSingleTupleTableSlot(), pfree(), _DestReceiver::rShutdown, and TupOutputState::slot.

Referenced by CreateReplicationSlot(), ExplainQuery(), IdentifySystem(), ShowAllGUCConfig(), ShowGUCConfigOption(), and StartReplication().

1309 {
1310  (*tstate->dest->rShutdown) (tstate->dest);
1311  /* note that destroying the dest is not ours to do */
1313  pfree(tstate);
1314 }
void(* rShutdown)(DestReceiver *self)
Definition: dest.h:124
TupleTableSlot * slot
Definition: executor.h:414
void pfree(void *pointer)
Definition: mcxt.c:950
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:216
DestReceiver * dest
Definition: executor.h:415
TupleTableSlot* EvalPlanQual ( EState estate,
EPQState epqstate,
Relation  relation,
Index  rti,
int  lockmode,
ItemPointer  tid,
TransactionId  priorXmax 
)

Definition at line 2435 of file execMain.c.

References Assert, EvalPlanQualBegin(), EvalPlanQualFetch(), EvalPlanQualFetchRowMarks(), EvalPlanQualNext(), EvalPlanQualSetTuple(), ExecMaterializeSlot(), LockWaitBlock, NULL, HeapTupleData::t_self, and TupIsNull.

Referenced by ExecDelete(), ExecUpdate(), and GetTupleForTrigger().

2438 {
2439  TupleTableSlot *slot;
2440  HeapTuple copyTuple;
2441 
2442  Assert(rti > 0);
2443 
2444  /*
2445  * Get and lock the updated version of the row; if fail, return NULL.
2446  */
2447  copyTuple = EvalPlanQualFetch(estate, relation, lockmode, LockWaitBlock,
2448  tid, priorXmax);
2449 
2450  if (copyTuple == NULL)
2451  return NULL;
2452 
2453  /*
2454  * For UPDATE/DELETE we have to return tid of actual row we're executing
2455  * PQ for.
2456  */
2457  *tid = copyTuple->t_self;
2458 
2459  /*
2460  * Need to run a recheck subquery. Initialize or reinitialize EPQ state.
2461  */
2462  EvalPlanQualBegin(epqstate, estate);
2463 
2464  /*
2465  * Free old test tuple, if any, and store new tuple where relation's scan
2466  * node will see it
2467  */
2468  EvalPlanQualSetTuple(epqstate, rti, copyTuple);
2469 
2470  /*
2471  * Fetch any non-locked source rows
2472  */
2473  EvalPlanQualFetchRowMarks(epqstate);
2474 
2475  /*
2476  * Run the EPQ query. We assume it will return at most one tuple.
2477  */
2478  slot = EvalPlanQualNext(epqstate);
2479 
2480  /*
2481  * If we got a tuple, force the slot to materialize the tuple so that it
2482  * is not dependent on any local state in the EPQ query (in particular,
2483  * it's highly likely that the slot contains references to any pass-by-ref
2484  * datums that may be present in copyTuple). As with the next step, this
2485  * is to guard against early re-use of the EPQ query.
2486  */
2487  if (!TupIsNull(slot))
2488  (void) ExecMaterializeSlot(slot);
2489 
2490  /*
2491  * Clear out the test tuple. This is needed in case the EPQ query is
2492  * re-used to test a tuple for a different relation. (Not clear that can
2493  * really happen, but let's be safe.)
2494  */
2495  EvalPlanQualSetTuple(epqstate, rti, NULL);
2496 
2497  return slot;
2498 }
void EvalPlanQualSetTuple(EPQState *epqstate, Index rti, HeapTuple tuple)
Definition: execMain.c:2786
HeapTuple EvalPlanQualFetch(EState *estate, Relation relation, int lockmode, LockWaitPolicy wait_policy, ItemPointer tid, TransactionId priorXmax)
Definition: execMain.c:2522
void EvalPlanQualFetchRowMarks(EPQState *epqstate)
Definition: execMain.c:2821
void EvalPlanQualBegin(EPQState *epqstate, EState *parentestate)
Definition: execMain.c:2972
TupleTableSlot * EvalPlanQualNext(EPQState *epqstate)
Definition: execMain.c:2956
ItemPointerData t_self
Definition: htup.h:65
#define TupIsNull(slot)
Definition: tuptable.h:138
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
HeapTuple ExecMaterializeSlot(TupleTableSlot *slot)
Definition: execTuples.c:725
void EvalPlanQualBegin ( EPQState epqstate,
EState parentestate 
)

Definition at line 2972 of file execMain.c.

References bms_add_member(), PlanState::chgParam, EPQState::epqParam, EState::es_epqScanDone, EState::es_param_exec_vals, EState::es_plannedstmt, EState::es_range_table, EPQState::estate, EvalPlanQualStart(), i, ParamExecData::isnull, list_length(), MemSet, PlannedStmt::nParamExec, NULL, EPQState::plan, EPQState::planstate, and ParamExecData::value.

Referenced by EvalPlanQual(), and ExecLockRows().

2973 {
2974  EState *estate = epqstate->estate;
2975 
2976  if (estate == NULL)
2977  {
2978  /* First time through, so create a child EState */
2979  EvalPlanQualStart(epqstate, parentestate, epqstate->plan);
2980  }
2981  else
2982  {
2983  /*
2984  * We already have a suitable child EPQ tree, so just reset it.
2985  */
2986  int rtsize = list_length(parentestate->es_range_table);
2987  PlanState *planstate = epqstate->planstate;
2988 
2989  MemSet(estate->es_epqScanDone, 0, rtsize * sizeof(bool));
2990 
2991  /* Recopy current values of parent parameters */
2992  if (parentestate->es_plannedstmt->nParamExec > 0)
2993  {
2994  int i = parentestate->es_plannedstmt->nParamExec;
2995 
2996  while (--i >= 0)
2997  {
2998  /* copy value if any, but not execPlan link */
2999  estate->es_param_exec_vals[i].value =
3000  parentestate->es_param_exec_vals[i].value;
3001  estate->es_param_exec_vals[i].isnull =
3002  parentestate->es_param_exec_vals[i].isnull;
3003  }
3004  }
3005 
3006  /*
3007  * Mark child plan tree as needing rescan at all scan nodes. The
3008  * first ExecProcNode will take care of actually doing the rescan.
3009  */
3010  planstate->chgParam = bms_add_member(planstate->chgParam,
3011  epqstate->epqParam);
3012  }
3013 }
PlannedStmt * es_plannedstmt
Definition: execnodes.h:412
#define MemSet(start, val, len)
Definition: c.h:857
List * es_range_table
Definition: execnodes.h:411
PlanState * planstate
Definition: execnodes.h:877
int nParamExec
Definition: plannodes.h:92
ParamExecData * es_param_exec_vals
Definition: execnodes.h:443
bool isnull
Definition: params.h:101
static void EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
Definition: execMain.c:3022
Bitmapset * chgParam
Definition: execnodes.h:837
Plan * plan
Definition: execnodes.h:879
#define NULL
Definition: c.h:229
static int list_length(const List *l)
Definition: pg_list.h:89
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:698
int i
bool * es_epqScanDone
Definition: execnodes.h:485
Datum value
Definition: params.h:100
int epqParam
Definition: execnodes.h:881
EState * estate
Definition: execnodes.h:876
void EvalPlanQualEnd ( EPQState epqstate)

Definition at line 3162 of file execMain.c.

References EState::es_query_cxt, EState::es_subplanstates, EState::es_tupleTable, EPQState::estate, ExecCleanUpTriggerState(), ExecEndNode(), ExecResetTupleTable(), FreeExecutorState(), lfirst, MemoryContextSwitchTo(), NULL, EPQState::origslot, and EPQState::planstate.

Referenced by apply_handle_delete(), apply_handle_update(), EvalPlanQualSetPlan(), ExecEndLockRows(), and ExecEndModifyTable().

3163 {
3164  EState *estate = epqstate->estate;
3165  MemoryContext oldcontext;
3166  ListCell *l;
3167 
3168  if (estate == NULL)
3169  return; /* idle, so nothing to do */
3170 
3171  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
3172 
3173  ExecEndNode(epqstate->planstate);
3174 
3175  foreach(l, estate->es_subplanstates)
3176  {
3177  PlanState *subplanstate = (PlanState *) lfirst(l);
3178 
3179  ExecEndNode(subplanstate);
3180  }
3181 
3182  /* throw away the per-estate tuple table */
3183  ExecResetTupleTable(estate->es_tupleTable, false);
3184 
3185  /* close any trigger target relations attached to this EState */
3186  ExecCleanUpTriggerState(estate);
3187 
3188  MemoryContextSwitchTo(oldcontext);
3189 
3190  FreeExecutorState(estate);
3191 
3192  /* Mark EPQState idle */
3193  epqstate->estate = NULL;
3194  epqstate->planstate = NULL;
3195  epqstate->origslot = NULL;
3196 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:654
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
PlanState * planstate
Definition: execnodes.h:877
void FreeExecutorState(EState *estate)
Definition: execUtils.c:178
MemoryContext es_query_cxt
Definition: execnodes.h:448
TupleTableSlot * origslot
Definition: execnodes.h:878
List * es_tupleTable
Definition: execnodes.h:450
void ExecResetTupleTable(List *tupleTable, bool shouldFree)
Definition: execTuples.c:156
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
List * es_subplanstates
Definition: execnodes.h:463
void ExecCleanUpTriggerState(EState *estate)
Definition: execMain.c:1453
EState * estate
Definition: execnodes.h:876
HeapTuple EvalPlanQualFetch ( EState estate,
Relation  relation,
int  lockmode,
LockWaitPolicy  wait_policy,
ItemPointer  tid,
TransactionId  priorXmax 
)

Definition at line 2522 of file execMain.c.

References Assert, buffer, ConditionalXactLockTableWait(), HeapUpdateFailureData::ctid, elog, ereport, errcode(), errmsg(), ERROR, EState::es_output_cid, heap_copytuple(), heap_fetch(), heap_lock_tuple(), HeapTupleHeaderGetCmin(), HeapTupleHeaderGetUpdateXid, HeapTupleHeaderGetXmin, HeapTupleHeaderIsSpeculative, HeapTupleInvisible, HeapTupleMayBeUpdated, HeapTupleSelfUpdated, HeapTupleUpdated, HeapTupleWouldBlock, InitDirtySnapshot, IsolationUsesXactSnapshot, ItemPointerEquals(), LockWaitBlock, LockWaitError, LockWaitSkip, NULL, RelationGetRelationName, ReleaseBuffer(), HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_self, test(), TransactionIdEquals, TransactionIdIsCurrentTransactionId(), TransactionIdIsValid, XactLockTableWait(), XLTW_FetchUpdated, SnapshotData::xmax, HeapUpdateFailureData::xmax, and SnapshotData::xmin.

Referenced by EvalPlanQual(), and ExecLockRows().

2525 {
2526  HeapTuple copyTuple = NULL;
2527  HeapTupleData tuple;
2528  SnapshotData SnapshotDirty;
2529 
2530  /*
2531  * fetch target tuple
2532  *
2533  * Loop here to deal with updated or busy tuples
2534  */
2535  InitDirtySnapshot(SnapshotDirty);
2536  tuple.t_self = *tid;
2537  for (;;)
2538  {
2539  Buffer buffer;
2540 
2541  if (heap_fetch(relation, &SnapshotDirty, &tuple, &buffer, true, NULL))
2542  {
2543  HTSU_Result test;
2544  HeapUpdateFailureData hufd;
2545 
2546  /*
2547  * If xmin isn't what we're expecting, the slot must have been
2548  * recycled and reused for an unrelated tuple. This implies that
2549  * the latest version of the row was deleted, so we need do
2550  * nothing. (Should be safe to examine xmin without getting
2551  * buffer's content lock. We assume reading a TransactionId to be
2552  * atomic, and Xmin never changes in an existing tuple, except to
2553  * invalid or frozen, and neither of those can match priorXmax.)
2554  */
2556  priorXmax))
2557  {
2558  ReleaseBuffer(buffer);
2559  return NULL;
2560  }
2561 
2562  /* otherwise xmin should not be dirty... */
2563  if (TransactionIdIsValid(SnapshotDirty.xmin))
2564  elog(ERROR, "t_xmin is uncommitted in tuple to be updated");
2565 
2566  /*
2567  * If tuple is being updated by other transaction then we have to
2568  * wait for its commit/abort, or die trying.
2569  */
2570  if (TransactionIdIsValid(SnapshotDirty.xmax))
2571  {
2572  ReleaseBuffer(buffer);
2573  switch (wait_policy)
2574  {
2575  case LockWaitBlock:
2576  XactLockTableWait(SnapshotDirty.xmax,
2577  relation, &tuple.t_self,
2579  break;
2580  case LockWaitSkip:
2581  if (!ConditionalXactLockTableWait(SnapshotDirty.xmax))
2582  return NULL; /* skip instead of waiting */
2583  break;
2584  case LockWaitError:
2585  if (!ConditionalXactLockTableWait(SnapshotDirty.xmax))
2586  ereport(ERROR,
2587  (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
2588  errmsg("could not obtain lock on row in relation \"%s\"",
2589  RelationGetRelationName(relation))));
2590  break;
2591  }
2592  continue; /* loop back to repeat heap_fetch */
2593  }
2594 
2595  /*
2596  * If tuple was inserted by our own transaction, we have to check
2597  * cmin against es_output_cid: cmin >= current CID means our
2598  * command cannot see the tuple, so we should ignore it. Otherwise
2599  * heap_lock_tuple() will throw an error, and so would any later
2600  * attempt to update or delete the tuple. (We need not check cmax
2601  * because HeapTupleSatisfiesDirty will consider a tuple deleted
2602  * by our transaction dead, regardless of cmax.) We just checked
2603  * that priorXmax == xmin, so we can test that variable instead of
2604  * doing HeapTupleHeaderGetXmin again.
2605  */
2606  if (TransactionIdIsCurrentTransactionId(priorXmax) &&
2607  HeapTupleHeaderGetCmin(tuple.t_data) >= estate->es_output_cid)
2608  {
2609  ReleaseBuffer(buffer);
2610  return NULL;
2611  }
2612 
2613  /*
2614  * This is a live tuple, so now try to lock it.
2615  */
2616  test = heap_lock_tuple(relation, &tuple,
2617  estate->es_output_cid,
2618  lockmode, wait_policy,
2619  false, &buffer, &hufd);
2620  /* We now have two pins on the buffer, get rid of one */
2621  ReleaseBuffer(buffer);
2622 
2623  switch (test)
2624  {
2625  case HeapTupleSelfUpdated:
2626 
2627  /*
2628  * The target tuple was already updated or deleted by the
2629  * current command, or by a later command in the current
2630  * transaction. We *must* ignore the tuple in the former
2631  * case, so as to avoid the "Halloween problem" of
2632  * repeated update attempts. In the latter case it might
2633  * be sensible to fetch the updated tuple instead, but
2634  * doing so would require changing heap_update and
2635  * heap_delete to not complain about updating "invisible"
2636  * tuples, which seems pretty scary (heap_lock_tuple will
2637  * not complain, but few callers expect
2638  * HeapTupleInvisible, and we're not one of them). So for
2639  * now, treat the tuple as deleted and do not process.
2640  */
2641  ReleaseBuffer(buffer);
2642  return NULL;
2643 
2644  case HeapTupleMayBeUpdated:
2645  /* successfully locked */
2646  break;
2647 
2648  case HeapTupleUpdated:
2649  ReleaseBuffer(buffer);
2651  ereport(ERROR,
2652  (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
2653  errmsg("could not serialize access due to concurrent update")));
2654 
2655  /* Should not encounter speculative tuple on recheck */
2657  if (!ItemPointerEquals(&hufd.ctid, &tuple.t_self))
2658  {
2659  /* it was updated, so look at the updated version */
2660  tuple.t_self = hufd.ctid;
2661  /* updated row should have xmin matching this xmax */
2662  priorXmax = hufd.xmax;
2663  continue;
2664  }
2665  /* tuple was deleted, so give up */
2666  return NULL;
2667 
2668  case HeapTupleWouldBlock:
2669  ReleaseBuffer(buffer);
2670  return NULL;
2671 
2672  case HeapTupleInvisible:
2673  elog(ERROR, "attempted to lock invisible tuple");
2674 
2675  default:
2676  ReleaseBuffer(buffer);
2677  elog(ERROR, "unrecognized heap_lock_tuple status: %u",
2678  test);
2679  return NULL; /* keep compiler quiet */
2680  }
2681 
2682  /*
2683  * We got tuple - now copy it for use by recheck query.
2684  */
2685  copyTuple = heap_copytuple(&tuple);
2686  ReleaseBuffer(buffer);
2687  break;
2688  }
2689 
2690  /*
2691  * If the referenced slot was actually empty, the latest version of
2692  * the row must have been deleted, so we need do nothing.
2693  */
2694  if (tuple.t_data == NULL)
2695  {
2696  ReleaseBuffer(buffer);
2697  return NULL;
2698  }
2699 
2700  /*
2701  * As above, if xmin isn't what we're expecting, do nothing.
2702  */
2704  priorXmax))
2705  {
2706  ReleaseBuffer(buffer);
2707  return NULL;
2708  }
2709 
2710  /*
2711  * If we get here, the tuple was found but failed SnapshotDirty.
2712  * Assuming the xmin is either a committed xact or our own xact (as it
2713  * certainly should be if we're trying to modify the tuple), this must
2714  * mean that the row was updated or deleted by either a committed xact
2715  * or our own xact. If it was deleted, we can ignore it; if it was
2716  * updated then chain up to the next version and repeat the whole
2717  * process.
2718  *
2719  * As above, it should be safe to examine xmax and t_ctid without the
2720  * buffer content lock, because they can't be changing.
2721  */
2722  if (ItemPointerEquals(&tuple.t_self, &tuple.t_data->t_ctid))
2723  {
2724  /* deleted, so forget about it */
2725  ReleaseBuffer(buffer);
2726  return NULL;
2727  }
2728 
2729  /* updated, so look at the updated row */
2730  tuple.t_self = tuple.t_data->t_ctid;
2731  /* updated row should have xmin matching this xmax */
2732  priorXmax = HeapTupleHeaderGetUpdateXid(tuple.t_data);
2733  ReleaseBuffer(buffer);
2734  /* loop back to fetch next in chain */
2735  }
2736 
2737  /*
2738  * Return the copied tuple
2739  */
2740  return copyTuple;
2741 }
#define HeapTupleHeaderGetUpdateXid(tup)
Definition: htup_details.h:359
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
CommandId es_output_cid
Definition: execnodes.h:418
static void test(void)
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition: xact.c:773
HTSU_Result heap_lock_tuple(Relation relation, HeapTuple tuple, CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy, bool follow_updates, Buffer *buffer, HeapUpdateFailureData *hufd)
Definition: heapam.c:4540
CommandId HeapTupleHeaderGetCmin(HeapTupleHeader tup)
Definition: combocid.c:105
bool heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation)
Definition: heapam.c:1862
#define IsolationUsesXactSnapshot()
Definition: xact.h:43
#define HeapTupleHeaderIsSpeculative(tup)
Definition: htup_details.h:423
int errcode(int sqlerrcode)
Definition: elog.c:575
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
bool ConditionalXactLockTableWait(TransactionId xid)
Definition: lmgr.c:607
HeapTupleHeader t_data
Definition: htup.h:67
#define ERROR
Definition: elog.h:43
#define InitDirtySnapshot(snapshotdata)
Definition: tqual.h:100
ItemPointerData t_ctid
Definition: htup_details.h:150
ItemPointerData t_self
Definition: htup.h:65
HTSU_Result
Definition: snapshot.h:119
#define RelationGetRelationName(relation)
Definition: rel.h:437
TransactionId xmax
Definition: snapshot.h:67
TransactionId xmin
Definition: snapshot.h:66
#define ereport(elevel, rest)
Definition: elog.h:122
TransactionId xmax
Definition: heapam.h:71
void XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid, XLTW_Oper oper)
Definition: lmgr.c:554
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:211
#define HeapTupleHeaderGetXmin(tup)
Definition: htup_details.h:307
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:29
int errmsg(const char *fmt,...)
Definition: elog.c:797
ItemPointerData ctid
Definition: heapam.h:70
#define elog
Definition: elog.h:219
#define TransactionIdIsValid(xid)
Definition: transam.h:41
int Buffer
Definition: buf.h:23
void EvalPlanQualFetchRowMarks ( EPQState epqstate)

Definition at line 2821 of file execMain.c.

References EPQState::arowMarks, Assert, buffer, ExecAuxRowMark::ctidAttNo, DatumGetHeapTupleHeader, DatumGetObjectId, DatumGetPointer, elog, ereport, errcode(), errmsg(), ERROR, EPQState::estate, EvalPlanQualSetTuple(), ExecGetJunkAttribute(), GetFdwRoutineForRelation(), heap_copytuple(), heap_fetch(), HeapTupleHeaderGetDatumLength, lfirst, ExecRowMark::markType, NULL, OidIsValid, EPQState::origslot, ExecRowMark::prti, RelationData::rd_rel, FdwRoutine::RefetchForeignRow, ExecRowMark::relation, RelationGetRelationName, ReleaseBuffer(), ExecRowMark::relid, RELKIND_FOREIGN_TABLE, ROW_MARK_COPY, ROW_MARK_REFERENCE, ExecAuxRowMark::rowmark, RowMarkRequiresRowShareLock, ExecRowMark::rti, SnapshotAny, HeapTupleHeaderData::t_ctid, HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, ExecAuxRowMark::toidAttNo, and ExecAuxRowMark::wholeAttNo.

Referenced by EvalPlanQual(), and ExecLockRows().

2822 {
2823  ListCell *l;
2824 
2825  Assert(epqstate->origslot != NULL);
2826 
2827  foreach(l, epqstate->arowMarks)
2828  {
2829  ExecAuxRowMark *aerm = (ExecAuxRowMark *) lfirst(l);
2830  ExecRowMark *erm = aerm->rowmark;
2831  Datum datum;
2832  bool isNull;
2833  HeapTupleData tuple;
2834 
2836  elog(ERROR, "EvalPlanQual doesn't support locking rowmarks");
2837 
2838  /* clear any leftover test tuple for this rel */
2839  EvalPlanQualSetTuple(epqstate, erm->rti, NULL);
2840 
2841  /* if child rel, must check whether it produced this row */
2842  if (erm->rti != erm->prti)
2843  {
2844  Oid tableoid;
2845 
2846  datum = ExecGetJunkAttribute(epqstate->origslot,
2847  aerm->toidAttNo,
2848  &isNull);
2849  /* non-locked rels could be on the inside of outer joins */
2850  if (isNull)
2851  continue;
2852  tableoid = DatumGetObjectId(datum);
2853 
2854  Assert(OidIsValid(erm->relid));
2855  if (tableoid != erm->relid)
2856  {
2857  /* this child is inactive right now */
2858  continue;
2859  }
2860  }
2861 
2862  if (erm->markType == ROW_MARK_REFERENCE)
2863  {
2864  HeapTuple copyTuple;
2865 
2866  Assert(erm->relation != NULL);
2867 
2868  /* fetch the tuple's ctid */
2869  datum = ExecGetJunkAttribute(epqstate->origslot,
2870  aerm->ctidAttNo,
2871  &isNull);
2872  /* non-locked rels could be on the inside of outer joins */
2873  if (isNull)
2874  continue;
2875 
2876  /* fetch requests on foreign tables must be passed to their FDW */
2877  if (erm->relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2878  {
2879  FdwRoutine *fdwroutine;
2880  bool updated = false;
2881 
2882  fdwroutine = GetFdwRoutineForRelation(erm->relation, false);
2883  /* this should have been checked already, but let's be safe */
2884  if (fdwroutine->RefetchForeignRow == NULL)
2885  ereport(ERROR,
2886  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2887  errmsg("cannot lock rows in foreign table \"%s\"",
2889  copyTuple = fdwroutine->RefetchForeignRow(epqstate->estate,
2890  erm,
2891  datum,
2892  &updated);
2893  if (copyTuple == NULL)
2894  elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
2895 
2896  /*
2897  * Ideally we'd insist on updated == false here, but that
2898  * assumes that FDWs can track that exactly, which they might
2899  * not be able to. So just ignore the flag.
2900  */
2901  }
2902  else
2903  {
2904  /* ordinary table, fetch the tuple */
2905  Buffer buffer;
2906 
2907  tuple.t_self = *((ItemPointer) DatumGetPointer(datum));
2908  if (!heap_fetch(erm->relation, SnapshotAny, &tuple, &buffer,
2909  false, NULL))
2910  elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
2911 
2912  /* successful, copy tuple */
2913  copyTuple = heap_copytuple(&tuple);
2914  ReleaseBuffer(buffer);
2915  }
2916 
2917  /* store tuple */
2918  EvalPlanQualSetTuple(epqstate, erm->rti, copyTuple);
2919  }
2920  else
2921  {
2922  HeapTupleHeader td;
2923 
2924  Assert(erm->markType == ROW_MARK_COPY);
2925 
2926  /* fetch the whole-row Var for the relation */
2927  datum = ExecGetJunkAttribute(epqstate->origslot,
2928  aerm->wholeAttNo,
2929  &isNull);
2930  /* non-locked rels could be on the inside of outer joins */
2931  if (isNull)
2932  continue;
2933  td = DatumGetHeapTupleHeader(datum);
2934 
2935  /* build a temporary HeapTuple control structure */
2937  tuple.t_data = td;
2938  /* relation might be a foreign table, if so provide tableoid */
2939  tuple.t_tableOid = erm->relid;
2940  /* also copy t_ctid in case there's valid data there */
2941  tuple.t_self = td->t_ctid;
2942 
2943  /* copy and store tuple */
2944  EvalPlanQualSetTuple(epqstate, erm->rti,
2945  heap_copytuple(&tuple));
2946  }
2947  }
2948 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void EvalPlanQualSetTuple(EPQState *epqstate, Index rti, HeapTuple tuple)
Definition: execMain.c:2786
Relation relation
Definition: execnodes.h:511
bool heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tuple, Buffer *userbuf, bool keep_buf, Relation stats_relation)
Definition: heapam.c:1862
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3309
Form_pg_class rd_rel
Definition: rel.h:114
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:259
#define RowMarkRequiresRowShareLock(marktype)
Definition: plannodes.h:962
ItemPointerData * ItemPointer
Definition: itemptr.h:48
ExecRowMark * rowmark
Definition: execnodes.h:538
HeapTupleHeader t_data
Definition: htup.h:67
#define ERROR
Definition: elog.h:43
ItemPointerData t_ctid
Definition: htup_details.h:150
ItemPointerData t_self
Definition: htup.h:65
List * arowMarks
Definition: execnodes.h:880
uint32 t_len
Definition: htup.h:64
Index rti
Definition: execnodes.h:513
AttrNumber wholeAttNo
Definition: execnodes.h:541
Index prti
Definition: execnodes.h:514
#define RelationGetRelationName(relation)
Definition: rel.h:437
Oid t_tableOid
Definition: htup.h:66
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
TupleTableSlot * origslot
Definition: execnodes.h:878
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
#define SnapshotAny
Definition: tqual.h:28
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:211
RowMarkType markType
Definition: execnodes.h:516
AttrNumber toidAttNo
Definition: execnodes.h:540
#define DatumGetPointer(X)
Definition: postgres.h:555
int errmsg(const char *fmt,...)
Definition: elog.c:797
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:395
Datum ExecGetJunkAttribute(TupleTableSlot *slot, AttrNumber attno, bool *isNull)
Definition: execJunk.c:248
#define elog
Definition: elog.h:219
EState * estate
Definition: execnodes.h:876
int Buffer
Definition: buf.h:23
AttrNumber ctidAttNo
Definition: execnodes.h:539
RefetchForeignRow_function RefetchForeignRow
Definition: fdwapi.h:209
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:439
HeapTuple EvalPlanQualGetTuple ( EPQState epqstate,
Index  rti 
)

Definition at line 2806 of file execMain.c.

References Assert, EState::es_epqTuple, and EPQState::estate.

2807 {
2808  EState *estate = epqstate->estate;
2809 
2810  Assert(rti > 0);
2811 
2812  return estate->es_epqTuple[rti - 1];
2813 }
HeapTuple * es_epqTuple
Definition: execnodes.h:483
#define Assert(condition)
Definition: c.h:675
EState * estate
Definition: execnodes.h:876
void EvalPlanQualInit ( EPQState epqstate,
EState estate,
Plan subplan,
List auxrowmarks,
int  epqParam 
)

Definition at line 2751 of file execMain.c.

References EPQState::arowMarks, EPQState::epqParam, EPQState::estate, NULL, EPQState::origslot, EPQState::plan, and EPQState::planstate.

Referenced by apply_handle_delete(), apply_handle_update(), ExecInitLockRows(), and ExecInitModifyTable().

2753 {
2754  /* Mark the EPQ state inactive */
2755  epqstate->estate = NULL;
2756  epqstate->planstate = NULL;
2757  epqstate->origslot = NULL;
2758  /* ... and remember data that EvalPlanQualBegin will need */
2759  epqstate->plan = subplan;
2760  epqstate->arowMarks = auxrowmarks;
2761  epqstate->epqParam = epqParam;
2762 }
PlanState * planstate
Definition: execnodes.h:877
List * arowMarks
Definition: execnodes.h:880
TupleTableSlot * origslot
Definition: execnodes.h:878
Plan * plan
Definition: execnodes.h:879
#define NULL
Definition: c.h:229
int epqParam
Definition: execnodes.h:881
EState * estate
Definition: execnodes.h:876
TupleTableSlot* EvalPlanQualNext ( EPQState epqstate)

Definition at line 2956 of file execMain.c.

References EState::es_query_cxt, EPQState::estate, ExecProcNode(), MemoryContextSwitchTo(), and EPQState::planstate.

Referenced by EvalPlanQual(), and ExecLockRows().

2957 {
2958  MemoryContext oldcontext;
2959  TupleTableSlot *slot;
2960 
2961  oldcontext = MemoryContextSwitchTo(epqstate->estate->es_query_cxt);
2962  slot = ExecProcNode(epqstate->planstate);
2963  MemoryContextSwitchTo(oldcontext);
2964 
2965  return slot;
2966 }
TupleTableSlot * ExecProcNode(PlanState *node)
Definition: execProcnode.c:398
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
PlanState * planstate
Definition: execnodes.h:877
MemoryContext es_query_cxt
Definition: execnodes.h:448
EState * estate
Definition: execnodes.h:876
void EvalPlanQualSetPlan ( EPQState epqstate,
Plan subplan,
List auxrowmarks 
)

Definition at line 2770 of file execMain.c.

References EPQState::arowMarks, EvalPlanQualEnd(), and EPQState::plan.

Referenced by ExecInitModifyTable(), and ExecModifyTable().

2771 {
2772  /* If we have a live EPQ query, shut it down */
2773  EvalPlanQualEnd(epqstate);
2774  /* And set/change the plan pointer */
2775  epqstate->plan = subplan;
2776  /* The rowmarks depend on the plan, too */
2777  epqstate->arowMarks = auxrowmarks;
2778 }
void EvalPlanQualEnd(EPQState *epqstate)
Definition: execMain.c:3162
List * arowMarks
Definition: execnodes.h:880
Plan * plan
Definition: execnodes.h:879
void EvalPlanQualSetTuple ( EPQState epqstate,
Index  rti,
HeapTuple  tuple 
)

Definition at line 2786 of file execMain.c.

References Assert, EState::es_epqTuple, EState::es_epqTupleSet, EPQState::estate, heap_freetuple(), and NULL.

Referenced by EvalPlanQual(), EvalPlanQualFetchRowMarks(), and ExecLockRows().

2787 {
2788  EState *estate = epqstate->estate;
2789 
2790  Assert(rti > 0);
2791 
2792  /*
2793  * free old test tuple, if any, and store new tuple where relation's scan
2794  * node will see it
2795  */
2796  if (estate->es_epqTuple[rti - 1] != NULL)
2797  heap_freetuple(estate->es_epqTuple[rti - 1]);
2798  estate->es_epqTuple[rti - 1] = tuple;
2799  estate->es_epqTupleSet[rti - 1] = true;
2800 }
HeapTuple * es_epqTuple
Definition: execnodes.h:483
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1372
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
bool * es_epqTupleSet
Definition: execnodes.h:484
EState * estate
Definition: execnodes.h:876
void ExecAssignProjectionInfo ( PlanState planstate,
TupleDesc  inputDesc 
)

Definition at line 487 of file execUtils.c.

References ExecBuildProjectionInfo(), PlanState::plan, PlanState::ps_ExprContext, PlanState::ps_ProjInfo, PlanState::ps_ResultTupleSlot, and Plan::targetlist.

Referenced by ExecAssignScanProjectionInfoWithVarno(), ExecInitAgg(), ExecInitGather(), ExecInitGatherMerge(), ExecInitGroup(), ExecInitHashJoin(), ExecInitMergeJoin(), ExecInitNestLoop(), ExecInitResult(), and ExecInitWindowAgg().

489 {
490  planstate->ps_ProjInfo =
492  planstate->ps_ExprContext,
493  planstate->ps_ResultTupleSlot,
494  planstate,
495  inputDesc);
496 }
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:844
ExprContext * ps_ExprContext
Definition: execnodes.h:843
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:842
Plan * plan
Definition: execnodes.h:813
List * targetlist
Definition: plannodes.h:144
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:301
void ExecAssignResultType ( PlanState planstate,
TupleDesc  tupDesc 
)

Definition at line 428 of file execUtils.c.

References ExecSetSlotDescriptor(), and PlanState::ps_ResultTupleSlot.

Referenced by ExecAssignResultTypeFromTL(), and ExecInitModifyTable().

429 {
430  TupleTableSlot *slot = planstate->ps_ResultTupleSlot;
431 
432  ExecSetSlotDescriptor(slot, tupDesc);
433 }
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:842
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:247
void ExecAssignResultTypeFromTL ( PlanState planstate)

Definition at line 440 of file execUtils.c.

References ExecAssignResultType(), ExecContextForcesOids(), ExecTypeFromTL(), PlanState::plan, and Plan::targetlist.

Referenced by ExecInitAgg(), ExecInitAppend(), ExecInitBitmapHeapScan(), ExecInitCteScan(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitGather(), ExecInitGatherMerge(), ExecInitGroup(), ExecInitHash(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitNamedTuplestoreScan(), ExecInitNestLoop(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitTableFuncScan(), ExecInitTidScan(), ExecInitUnique(), ExecInitValuesScan(), ExecInitWindowAgg(), and ExecInitWorkTableScan().

441 {
442  bool hasoid;
443  TupleDesc tupDesc;
444 
445  if (ExecContextForcesOids(planstate, &hasoid))
446  {
447  /* context forces OID choice; hasoid is now set correctly */
448  }
449  else
450  {
451  /* given free choice, don't leave space for OIDs in result tuples */
452  hasoid = false;
453  }
454 
455  /*
456  * ExecTypeFromTL needs the parse-time representation of the tlist, not a
457  * list of ExprStates. This is good because some plan nodes don't bother
458  * to set up planstate->targetlist ...
459  */
460  tupDesc = ExecTypeFromTL(planstate->plan->targetlist, hasoid);
461  ExecAssignResultType(planstate, tupDesc);
462 }
void ExecAssignResultType(PlanState *planstate, TupleDesc tupDesc)
Definition: execUtils.c:428
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:888
Plan * plan
Definition: execnodes.h:813
List * targetlist
Definition: plannodes.h:144
bool ExecContextForcesOids(PlanState *planstate, bool *hasoids)
Definition: execMain.c:1500
void ExecAssignScanProjectionInfo ( ScanState node)
void ExecAssignScanProjectionInfoWithVarno ( ScanState node,
Index  varno 
)

Definition at line 247 of file execScan.c.

References ExecAssignProjectionInfo(), NULL, Scan::plan, PlanState::plan, ScanState::ps, PlanState::ps_ProjInfo, ScanState::ss_ScanTupleSlot, Plan::targetlist, tlist_matches_tupdesc(), and TupleTableSlot::tts_tupleDescriptor.

Referenced by ExecAssignScanProjectionInfo(), ExecInitCustomScan(), ExecInitForeignScan(), and ExecInitIndexOnlyScan().

248 {
249  Scan *scan = (Scan *) node->ps.plan;
250 
251  if (tlist_matches_tupdesc(&node->ps,
252  scan->plan.targetlist,
253  varno,
255  node->ps.ps_ProjInfo = NULL;
256  else
259 }
Plan plan
Definition: plannodes.h:328
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:844
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1061
PlanState ps
Definition: execnodes.h:1058
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:487
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:121
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc)
Definition: execScan.c:262
Plan * plan
Definition: execnodes.h:813
#define NULL
Definition: c.h:229
List * targetlist
Definition: plannodes.h:144
void ExecAssignScanTypeFromOuterPlan ( ScanState scanstate)

Definition at line 552 of file execUtils.c.

References ExecAssignScanType(), ExecGetResultType(), outerPlan, and outerPlanState.

Referenced by ExecInitAgg(), ExecInitGroup(), ExecInitMaterial(), ExecInitSort(), and ExecInitWindowAgg().

553 {
555  TupleDesc tupDesc;
556 
557  outerPlan = outerPlanState(scanstate);
558  tupDesc = ExecGetResultType(outerPlan);
559 
560  ExecAssignScanType(scanstate, tupDesc);
561 }
#define outerPlanState(node)
Definition: execnodes.h:855
#define outerPlan(node)
Definition: plannodes.h:174
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:469
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:540
ExecAuxRowMark* ExecBuildAuxRowMark ( ExecRowMark erm,
List targetlist 
)

Definition at line 2364 of file execMain.c.

References AttributeNumberIsValid, ExecAuxRowMark::ctidAttNo, elog, ERROR, ExecFindJunkAttributeInTlist(), ExecRowMark::markType, palloc0(), ExecRowMark::prti, ROW_MARK_COPY, ExecAuxRowMark::rowmark, ExecRowMark::rowmarkId, ExecRowMark::rti, snprintf(), ExecAuxRowMark::toidAttNo, and ExecAuxRowMark::wholeAttNo.

Referenced by ExecInitLockRows(), and ExecInitModifyTable().

2365 {
2366  ExecAuxRowMark *aerm = (ExecAuxRowMark *) palloc0(sizeof(ExecAuxRowMark));
2367  char resname[32];
2368 
2369  aerm->rowmark = erm;
2370 
2371  /* Look up the resjunk columns associated with this rowmark */
2372  if (erm->markType != ROW_MARK_COPY)
2373  {
2374  /* need ctid for all methods other than COPY */
2375  snprintf(resname, sizeof(resname), "ctid%u", erm->rowmarkId);
2376  aerm->ctidAttNo = ExecFindJunkAttributeInTlist(targetlist,
2377  resname);
2378  if (!AttributeNumberIsValid(aerm->ctidAttNo))
2379  elog(ERROR, "could not find junk %s column", resname);
2380  }
2381  else
2382  {
2383  /* need wholerow if COPY */
2384  snprintf(resname, sizeof(resname), "wholerow%u", erm->rowmarkId);
2385  aerm->wholeAttNo = ExecFindJunkAttributeInTlist(targetlist,
2386  resname);
2387  if (!AttributeNumberIsValid(aerm->wholeAttNo))
2388  elog(ERROR, "could not find junk %s column", resname);
2389  }
2390 
2391  /* if child rel, need tableoid */
2392  if (erm->rti != erm->prti)
2393  {
2394  snprintf(resname, sizeof(resname), "tableoid%u", erm->rowmarkId);
2395  aerm->toidAttNo = ExecFindJunkAttributeInTlist(targetlist,
2396  resname);
2397  if (!AttributeNumberIsValid(aerm->toidAttNo))
2398  elog(ERROR, "could not find junk %s column", resname);
2399  }
2400 
2401  return aerm;
2402 }
AttrNumber ExecFindJunkAttributeInTlist(List *targetlist, const char *attrName)
Definition: execJunk.c:221
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
ExecRowMark * rowmark
Definition: execnodes.h:538
#define ERROR
Definition: elog.h:43
Index rti
Definition: execnodes.h:513
AttrNumber wholeAttNo
Definition: execnodes.h:541
Index prti
Definition: execnodes.h:514
Index rowmarkId
Definition: execnodes.h:515
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
void * palloc0(Size size)
Definition: mcxt.c:878
RowMarkType markType
Definition: execnodes.h:516
AttrNumber toidAttNo
Definition: execnodes.h:540
#define elog
Definition: elog.h:219
AttrNumber ctidAttNo
Definition: execnodes.h:539
ProjectionInfo* ExecBuildProjectionInfo ( List targetList,
ExprContext econtext,
TupleTableSlot slot,
PlanState parent,
TupleDesc  inputDesc 
)

Definition at line 301 of file execExpr.c.

References ExprEvalStep::assign_tmp, ExprEvalStep::assign_var, tupleDesc::attrs, ExprEvalStep::d, EEOP_ASSIGN_INNER_VAR, EEOP_ASSIGN_OUTER_VAR, EEOP_ASSIGN_SCAN_VAR, EEOP_ASSIGN_TMP, EEOP_ASSIGN_TMP_MAKE_RO, EEOP_DONE, ExecInitExprRec(), ExecInitExprSlots(), ExecReadyExpr(), ExprState::expr, TargetEntry::expr, ExprEvalPushStep(), exprType(), get_typlen(), INNER_VAR, IsA, lfirst_node, makeNode, NULL, ExprEvalStep::opcode, OUTER_VAR, ProjectionInfo::pi_exprContext, ProjectionInfo::pi_state, TargetEntry::resno, ExprState::resnull, ExprState::resultslot, ExprState::resvalue, T_ExprState, ExprState::tag, Node::type, Var::varattno, Var::varno, and Var::vartype.

Referenced by ExecAssignProjectionInfo(), ExecInitAgg(), ExecInitModifyTable(), and ExecInitSubPlan().

306 {
308  ExprState *state;
309  ExprEvalStep scratch;
310  ListCell *lc;
311 
312  projInfo->pi_exprContext = econtext;
313  /* We embed ExprState into ProjectionInfo instead of doing extra palloc */
314  projInfo->pi_state.tag.type = T_ExprState;
315  state = &projInfo->pi_state;
316  state->expr = (Expr *) targetList;
317  state->resultslot = slot;
318 
319  /* Insert EEOP_*_FETCHSOME steps as needed */
320  ExecInitExprSlots(state, (Node *) targetList);
321 
322  /* Now compile each tlist column */
323  foreach(lc, targetList)
324  {
325  TargetEntry *tle = lfirst_node(TargetEntry, lc);
326  Var *variable = NULL;
327  AttrNumber attnum = 0;
328  bool isSafeVar = false;
329 
330  /*
331  * If tlist expression is a safe non-system Var, use the fast-path
332  * ASSIGN_*_VAR opcodes. "Safe" means that we don't need to apply
333  * CheckVarSlotCompatibility() during plan startup. If a source slot
334  * was provided, we make the equivalent tests here; if a slot was not
335  * provided, we assume that no check is needed because we're dealing
336  * with a non-relation-scan-level expression.
337  */
338  if (tle->expr != NULL &&
339  IsA(tle->expr, Var) &&
340  ((Var *) tle->expr)->varattno > 0)
341  {
342  /* Non-system Var, but how safe is it? */
343  variable = (Var *) tle->expr;
344  attnum = variable->varattno;
345 
346  if (inputDesc == NULL)
347  isSafeVar = true; /* can't check, just assume OK */
348  else if (attnum <= inputDesc->natts)
349  {
350  Form_pg_attribute attr = inputDesc->attrs[attnum - 1];
351 
352  /*
353  * If user attribute is dropped or has a type mismatch, don't
354  * use ASSIGN_*_VAR. Instead let the normal expression
355  * machinery handle it (which'll possibly error out).
356  */
357  if (!attr->attisdropped && variable->vartype == attr->atttypid)
358  {
359  isSafeVar = true;
360  }
361  }
362  }
363 
364  if (isSafeVar)
365  {
366  /* Fast-path: just generate an EEOP_ASSIGN_*_VAR step */
367  switch (variable->varno)
368  {
369  case INNER_VAR:
370  /* get the tuple from the inner node */
371  scratch.opcode = EEOP_ASSIGN_INNER_VAR;
372  break;
373 
374  case OUTER_VAR:
375  /* get the tuple from the outer node */
376  scratch.opcode = EEOP_ASSIGN_OUTER_VAR;
377  break;
378 
379  /* INDEX_VAR is handled by default case */
380 
381  default:
382  /* get the tuple from the relation being scanned */
383  scratch.opcode = EEOP_ASSIGN_SCAN_VAR;
384  break;
385  }
386 
387  scratch.d.assign_var.attnum = attnum - 1;
388  scratch.d.assign_var.resultnum = tle->resno - 1;
389  ExprEvalPushStep(state, &scratch);
390  }
391  else
392  {
393  /*
394  * Otherwise, compile the column expression normally.
395  *
396  * We can't tell the expression to evaluate directly into the
397  * result slot, as the result slot (and the exprstate for that
398  * matter) can change between executions. We instead evaluate
399  * into the ExprState's resvalue/resnull and then move.
400  */
401  ExecInitExprRec(tle->expr, parent, state,
402  &state->resvalue, &state->resnull);
403 
404  /*
405  * Column might be referenced multiple times in upper nodes, so
406  * force value to R/O - but only if it could be an expanded datum.
407  */
408  if (get_typlen(exprType((Node *) tle->expr)) == -1)
410  else
411  scratch.opcode = EEOP_ASSIGN_TMP;
412  scratch.d.assign_tmp.resultnum = tle->resno - 1;
413  ExprEvalPushStep(state, &scratch);
414  }
415  }
416 
417  scratch.opcode = EEOP_DONE;
418  ExprEvalPushStep(state, &scratch);
419 
420  ExecReadyExpr(state);
421 
422  return projInfo;
423 }
Node tag
Definition: execnodes.h:55
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Form_pg_attribute * attrs
Definition: tupdesc.h:74
Definition: nodes.h:509
AttrNumber varattno
Definition: primnodes.h:168
TupleTableSlot * resultslot
Definition: execnodes.h:69
union ExprEvalStep::@52 d
Definition: primnodes.h:163
bool resnull
Definition: execnodes.h:63
Expr * expr
Definition: execnodes.h:83
Oid vartype
Definition: primnodes.h:170
static void ExecInitExprSlots(ExprState *state, Node *node)
Definition: execExpr.c:2157
#define lfirst_node(type, lc)
Definition: pg_list.h:109
NodeTag type
Definition: nodes.h:511
AttrNumber resno
Definition: primnodes.h:1368
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
Index varno
Definition: primnodes.h:166
static void ExecReadyExpr(ExprState *state)
Definition: execExpr.c:574
struct ExprEvalStep::@52::@56 assign_var
#define INNER_VAR
Definition: primnodes.h:153
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
Definition: regguts.h:298
intptr_t opcode
Definition: execExpr.h:227
Expr * expr
Definition: primnodes.h:1367
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
static void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s)
Definition: execExpr.c:2028
int16 get_typlen(Oid typid)
Definition: lsyscache.c:1947
ExprState pi_state
Definition: execnodes.h:296
static void ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state, Datum *resv, bool *resnull)
Definition: execExpr.c:589
ExprContext * pi_exprContext
Definition: execnodes.h:298
Datum resvalue
Definition: execnodes.h:64
int16 AttrNumber
Definition: attnum.h:21
#define OUTER_VAR
Definition: primnodes.h:154
struct ExprEvalStep::@52::@57 assign_tmp
bool ExecCheck ( ExprState state,
ExprContext context 
)

Definition at line 544 of file execExpr.c.

References Assert, DatumGetBool, EEO_FLAG_IS_QUAL, ExecEvalExprSwitchContext(), ExprState::flags, and NULL.

Referenced by ATRewriteTable(), domain_check_input(), ExecPartitionCheck(), ExecRelCheck(), and validateCheckConstraint().

545 {
546  Datum ret;
547  bool isnull;
548 
549  /* short-circuit (here and in ExecInitCheck) for empty restriction list */
550  if (state == NULL)
551  return true;
552 
553  /* verify that expression was not compiled using ExecInitQual */
554  Assert(!(state->flags & EEO_FLAG_IS_QUAL));
555 
556  ret = ExecEvalExprSwitchContext(state, econtext, &isnull);
557 
558  if (isnull)
559  return true;
560 
561  return DatumGetBool(ret);
562 }
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:281
#define EEO_FLAG_IS_QUAL
Definition: execnodes.h:51
#define DatumGetBool(X)
Definition: postgres.h:399
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
uint8 flags
Definition: execnodes.h:57
bool ExecCheckIndexConstraints ( TupleTableSlot slot,
EState estate,
ItemPointer  conflictTid,
List arbiterIndexes 
)

Definition at line 475 of file execIndexing.c.

References CEOUC_WAIT, check_exclusion_or_unique_constraint(), ExprContext::ecxt_scantuple, elog, ereport, errcode(), errmsg(), ERROR, errtableconstraint(), EState::es_result_relation_info, ExecPrepareQual(), ExecQual(), FormIndexDatum(), GetPerTupleExprContext, i, IndexInfo::ii_ExclusionOps, IndexInfo::ii_Predicate, IndexInfo::ii_PredicateState, IndexInfo::ii_ReadyForInserts, IndexInfo::ii_Unique, INDEX_MAX_KEYS, ItemPointerSetInvalid, list_member_oid(), NIL, NULL, RelationData::rd_index, RelationGetRelationName, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_IndexRelationInfo, ResultRelInfo::ri_NumIndices, ResultRelInfo::ri_RelationDesc, and values.

Referenced by ExecInsert().

478 {
479  ResultRelInfo *resultRelInfo;
480  int i;
481  int numIndices;
482  RelationPtr relationDescs;
483  Relation heapRelation;
484  IndexInfo **indexInfoArray;
485  ExprContext *econtext;
487  bool isnull[INDEX_MAX_KEYS];
488  ItemPointerData invalidItemPtr;
489  bool checkedIndex = false;
490 
491  ItemPointerSetInvalid(conflictTid);
492  ItemPointerSetInvalid(&invalidItemPtr);
493 
494  /*
495  * Get information from the result relation info structure.
496  */
497  resultRelInfo = estate->es_result_relation_info;
498  numIndices = resultRelInfo->ri_NumIndices;
499  relationDescs = resultRelInfo->ri_IndexRelationDescs;
500  indexInfoArray = resultRelInfo->ri_IndexRelationInfo;
501  heapRelation = resultRelInfo->ri_RelationDesc;
502 
503  /*
504  * We will use the EState's per-tuple context for evaluating predicates
505  * and index expressions (creating it if it's not already there).
506  */
507  econtext = GetPerTupleExprContext(estate);
508 
509  /* Arrange for econtext's scan tuple to be the tuple under test */
510  econtext->ecxt_scantuple = slot;
511 
512  /*
513  * For each index, form index tuple and check if it satisfies the
514  * constraint.
515  */
516  for (i = 0; i < numIndices; i++)
517  {
518  Relation indexRelation = relationDescs[i];
519  IndexInfo *indexInfo;
520  bool satisfiesConstraint;
521 
522  if (indexRelation == NULL)
523  continue;
524 
525  indexInfo = indexInfoArray[i];
526 
527  if (!indexInfo->ii_Unique && !indexInfo->ii_ExclusionOps)
528  continue;
529 
530  /* If the index is marked as read-only, ignore it */
531  if (!indexInfo->ii_ReadyForInserts)
532  continue;
533 
534  /* When specific arbiter indexes requested, only examine them */
535  if (arbiterIndexes != NIL &&
536  !list_member_oid(arbiterIndexes,
537  indexRelation->rd_index->indexrelid))
538  continue;
539 
540  if (!indexRelation->rd_index->indimmediate)
541  ereport(ERROR,
542  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
543  errmsg("ON CONFLICT does not support deferrable unique constraints/exclusion constraints as arbiters"),
544  errtableconstraint(heapRelation,
545  RelationGetRelationName(indexRelation))));
546 
547  checkedIndex = true;
548 
549  /* Check for partial index */
550  if (indexInfo->ii_Predicate != NIL)
551  {
552  ExprState *predicate;
553 
554  /*
555  * If predicate state not set up yet, create it (in the estate's
556  * per-query context)
557  */
558  predicate = indexInfo->ii_PredicateState;
559  if (predicate == NULL)
560  {
561  predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
562  indexInfo->ii_PredicateState = predicate;
563  }
564 
565  /* Skip this index-update if the predicate isn't satisfied */
566  if (!ExecQual(predicate, econtext))
567  continue;
568  }
569 
570  /*
571  * FormIndexDatum fills in its values and isnull parameters with the
572  * appropriate values for the column(s) of the index.
573  */
574  FormIndexDatum(indexInfo,
575  slot,
576  estate,
577  values,
578  isnull);
579 
580  satisfiesConstraint =
581  check_exclusion_or_unique_constraint(heapRelation, indexRelation,
582  indexInfo, &invalidItemPtr,
583  values, isnull, estate, false,
584  CEOUC_WAIT, true,
585  conflictTid);
586  if (!satisfiesConstraint)
587  return false;
588  }
589 
590  if (arbiterIndexes != NIL && !checkedIndex)
591  elog(ERROR, "unexpected failure to find arbiter index");
592 
593  return true;
594 }
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:1765
int ri_NumIndices
Definition: execnodes.h:375
#define NIL
Definition: pg_list.h:69
Relation ri_RelationDesc
Definition: execnodes.h:374
List * ii_Predicate
Definition: execnodes.h:138
ExprState * ii_PredicateState
Definition: execnodes.h:139
int errcode(int sqlerrcode)
Definition: elog.c:575
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:346
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, Datum *values, bool *isnull, EState *estate, bool newIndex, CEOUC_WAIT_MODE waitMode, bool errorOK, ItemPointer conflictTid)
Definition: execIndexing.c:639
#define GetPerTupleExprContext(estate)
Definition: executor.h:456
int errtableconstraint(Relation rel, const char *conname)
Definition: relcache.c:5297
Form_pg_index rd_index
Definition: rel.h:159
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:437
ExprState * ExecPrepareQual(List *qual, EState *estate)
Definition: execExpr.c:465
bool ii_ReadyForInserts
Definition: execnodes.h:147
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
bool ii_Unique
Definition: execnodes.h:146
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:505
#define NULL
Definition: c.h:229
#define INDEX_MAX_KEYS
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:197
static Datum values[MAXATTR]
Definition: bootstrap.c:163
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:149
Oid * ii_ExclusionOps
Definition: execnodes.h:140
int errmsg(const char *fmt,...)
Definition: elog.c:797
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:377
int i
#define elog
Definition: elog.h:219
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:376
ResultRelInfo * es_result_relation_info
Definition: execnodes.h:423
bool ExecCheckRTPerms ( List rangeTable,
bool  ereport_on_violation 
)

Definition at line 567 of file execMain.c.

References ACL_KIND_CLASS, aclcheck_error(), ACLCHECK_NO_PRIV, Assert, ExecCheckRTEPerms(), ExecutorCheckPerms_hook, get_rel_name(), lfirst, RangeTblEntry::relid, result, RTE_RELATION, and RangeTblEntry::rtekind.

Referenced by DoCopy(), InitPlan(), intorel_startup(), and RI_Initial_Check().

568 {
569  ListCell *l;
570  bool result = true;
571 
572  foreach(l, rangeTable)
573  {
574  RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
575 
576  result = ExecCheckRTEPerms(rte);
577  if (!result)
578  {
579  Assert(rte->rtekind == RTE_RELATION);
580  if (ereport_on_violation)
582  get_rel_name(rte->relid));
583  return false;
584  }
585  }
586 
588  result = (*ExecutorCheckPerms_hook) (rangeTable,
589  ereport_on_violation);
590  return result;
591 }
return result
Definition: formatting.c:1632
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
static bool ExecCheckRTEPerms(RangeTblEntry *rte)
Definition: execMain.c:598
ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook
Definition: execMain.c:75
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
RTEKind rtekind
Definition: parsenodes.h:929
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
int ExecCleanTargetListLength ( List targetlist)

Definition at line 1007 of file execUtils.c.

References lfirst_node, and TargetEntry::resjunk.

Referenced by check_sql_fn_retval(), and ExecTypeFromTLInternal().

1008 {
1009  int len = 0;
1010  ListCell *tl;
1011 
1012  foreach(tl, targetlist)
1013  {
1014  TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1015 
1016  if (!curTle->resjunk)
1017  len++;
1018  }
1019  return len;
1020 }
bool resjunk
Definition: primnodes.h:1374
#define lfirst_node(type, lc)
Definition: pg_list.h:109
TupleDesc ExecCleanTypeFromTL ( List targetList,
bool  hasoid 
)

Definition at line 900 of file execTuples.c.

References ExecTypeFromTLInternal().

Referenced by ExecInitJunkFilter(), PlanCacheComputeResultDesc(), and PortalStart().

901 {
902  return ExecTypeFromTLInternal(targetList, hasoid, true);
903 }
static TupleDesc ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
Definition: execTuples.c:906
void ExecCleanUpTriggerState ( EState estate)

Definition at line 1453 of file execMain.c.

References EState::es_trig_target_relations, ExecCloseIndices(), heap_close, lfirst, NoLock, and ResultRelInfo::ri_RelationDesc.

Referenced by afterTriggerInvokeEvents(), CopyFrom(), EvalPlanQualEnd(), and ExecEndPlan().

1454 {
1455  ListCell *l;
1456 
1457  foreach(l, estate->es_trig_target_relations)
1458  {
1459  ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(l);
1460 
1461  /* Close indices and then the relation itself */
1462  ExecCloseIndices(resultRelInfo);
1463  heap_close(resultRelInfo->ri_RelationDesc, NoLock);
1464  }
1465 }
Relation ri_RelationDesc
Definition: execnodes.h:374
#define heap_close(r, l)
Definition: heapam.h:97
#define NoLock
Definition: lockdefs.h:34
List * es_trig_target_relations
Definition: execnodes.h:436
#define lfirst(lc)
Definition: pg_list.h:106
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
Definition: execIndexing.c:224
void ExecCloseIndices ( ResultRelInfo resultRelInfo)

Definition at line 224 of file execIndexing.c.

References i, index_close(), NULL, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_NumIndices, and RowExclusiveLock.

Referenced by apply_handle_delete(), apply_handle_insert(), apply_handle_update(), CatalogCloseIndexes(), CopyFrom(), ExecCleanUpTriggerState(), ExecEndModifyTable(), and ExecEndPlan().

225 {
226  int i;
227  int numIndices;
228  RelationPtr indexDescs;
229 
230  numIndices = resultRelInfo->ri_NumIndices;
231  indexDescs = resultRelInfo->ri_IndexRelationDescs;
232 
233  for (i = 0; i < numIndices; i++)
234  {
235  if (indexDescs[i] == NULL)
236  continue; /* shouldn't happen? */
237 
238  /* Drop lock acquired by ExecOpenIndices */
239  index_close(indexDescs[i], RowExclusiveLock);
240  }
241 
242  /*
243  * XXX should free indexInfo array here too? Currently we assume that
244  * such stuff will be cleaned up automatically in FreeExecutorState.
245  */
246 }
int ri_NumIndices
Definition: execnodes.h:375
#define RowExclusiveLock
Definition: lockdefs.h:38
#define NULL
Definition: c.h:229
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:176
int i
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:376
void ExecCloseScanRelation ( Relation  scanrel)

Definition at line 661 of file execUtils.c.

References heap_close, and NoLock.

Referenced by ExecEndBitmapHeapScan(), ExecEndCustomScan(), ExecEndForeignScan(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndSampleScan(), ExecEndSeqScan(), and ExecEndTidScan().

662 {
663  heap_close(scanrel, NoLock);
664 }
#define heap_close(r, l)
Definition: heapam.h:97
#define NoLock
Definition: lockdefs.h:34
void ExecConstraints ( ResultRelInfo resultRelInfo,
TupleTableSlot slot,
EState estate 
)

Definition at line 1886 of file execMain.c.

References Assert, tupleDesc::attrs, bms_union(), tupleDesc::constr, convert_tuples_by_name(), do_convert_tuple(), ereport, errcode(), errdetail(), errmsg(), ERROR, errtablecol(), errtableconstraint(), ExecBuildSlotValueDescription(), ExecFetchSlotTuple(), ExecPartitionCheck(), ExecRelCheck(), ExecStoreTuple(), GetInsertedColumns, gettext_noop, GetUpdatedColumns, tupleConstr::has_not_null, InvalidBuffer, NameStr, tupleDesc::natts, NULL, tupleConstr::num_check, RelationGetDescr, RelationGetRelationName, RelationGetRelid, ResultRelInfo::ri_PartitionCheck, ResultRelInfo::ri_PartitionRoot, ResultRelInfo::ri_RelationDesc, and slot_attisnull().

Referenced by CopyFrom(), ExecInsert(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), and ExecUpdate().

1888 {
1889  Relation rel = resultRelInfo->ri_RelationDesc;
1890  TupleDesc tupdesc = RelationGetDescr(rel);
1891  TupleConstr *constr = tupdesc->constr;
1892  Bitmapset *modifiedCols;
1893  Bitmapset *insertedCols;
1894  Bitmapset *updatedCols;
1895 
1896  Assert(constr || resultRelInfo->ri_PartitionCheck);
1897 
1898  if (constr && constr->has_not_null)
1899  {
1900  int natts = tupdesc->natts;
1901  int attrChk;
1902 
1903  for (attrChk = 1; attrChk <= natts; attrChk++)
1904  {
1905  if (tupdesc->attrs[attrChk - 1]->attnotnull &&
1906  slot_attisnull(slot, attrChk))
1907  {
1908  char *val_desc;
1909  Relation orig_rel = rel;
1910  TupleDesc orig_tupdesc = RelationGetDescr(rel);
1911 
1912  /*
1913  * If the tuple has been routed, it's been converted to the
1914  * partition's rowtype, which might differ from the root
1915  * table's. We must convert it back to the root table's
1916  * rowtype so that val_desc shown error message matches the
1917  * input tuple.
1918  */
1919  if (resultRelInfo->ri_PartitionRoot)
1920  {
1921  HeapTuple tuple = ExecFetchSlotTuple(slot);
1922  TupleConversionMap *map;
1923 
1924  rel = resultRelInfo->ri_PartitionRoot;
1925  tupdesc = RelationGetDescr(rel);
1926  /* a reverse map */
1927  map = convert_tuples_by_name(orig_tupdesc, tupdesc,
1928  gettext_noop("could not convert row type"));
1929  if (map != NULL)
1930  {
1931  tuple = do_convert_tuple(tuple, map);
1932  ExecStoreTuple(tuple, slot, InvalidBuffer, false);
1933  }
1934  }
1935 
1936  insertedCols = GetInsertedColumns(resultRelInfo, estate);
1937  updatedCols = GetUpdatedColumns(resultRelInfo, estate);
1938  modifiedCols = bms_union(insertedCols, updatedCols);
1940  slot,
1941  tupdesc,
1942  modifiedCols,
1943  64);
1944 
1945  ereport(ERROR,
1946  (errcode(ERRCODE_NOT_NULL_VIOLATION),
1947  errmsg("null value in column \"%s\" violates not-null constraint",
1948  NameStr(orig_tupdesc->attrs[attrChk - 1]->attname)),
1949  val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
1950  errtablecol(orig_rel, attrChk)));
1951  }
1952  }
1953  }
1954 
1955  if (constr && constr->num_check > 0)
1956  {
1957  const char *failed;
1958 
1959  if ((failed = ExecRelCheck(resultRelInfo, slot, estate)) != NULL)
1960  {
1961  char *val_desc;
1962  Relation orig_rel = rel;
1963 
1964  /* See the comment above. */
1965  if (resultRelInfo->ri_PartitionRoot)
1966  {
1967  HeapTuple tuple = ExecFetchSlotTuple(slot);
1968  TupleDesc old_tupdesc = RelationGetDescr(rel);
1969  TupleConversionMap *map;
1970 
1971  rel = resultRelInfo->ri_PartitionRoot;
1972  tupdesc = RelationGetDescr(rel);
1973  /* a reverse map */
1974  map = convert_tuples_by_name(old_tupdesc, tupdesc,
1975  gettext_noop("could not convert row type"));
1976  if (map != NULL)
1977  {
1978  tuple = do_convert_tuple(tuple, map);
1979  ExecStoreTuple(tuple, slot, InvalidBuffer, false);
1980  }
1981  }
1982 
1983  insertedCols = GetInsertedColumns(resultRelInfo, estate);
1984  updatedCols = GetUpdatedColumns(resultRelInfo, estate);
1985  modifiedCols = bms_union(insertedCols, updatedCols);
1987  slot,
1988  tupdesc,
1989  modifiedCols,
1990  64);
1991  ereport(ERROR,
1992  (errcode(ERRCODE_CHECK_VIOLATION),
1993  errmsg("new row for relation \"%s\" violates check constraint \"%s\"",
1994  RelationGetRelationName(orig_rel), failed),
1995  val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,
1996  errtableconstraint(orig_rel, failed)));
1997  }
1998  }
1999 
2000  if (resultRelInfo->ri_PartitionCheck &&
2001  !ExecPartitionCheck(resultRelInfo, slot, estate))
2002  {
2003  char *val_desc;
2004  Relation orig_rel = rel;
2005 
2006  /* See the comment above. */
2007  if (resultRelInfo->ri_PartitionRoot)
2008  {
2009  HeapTuple tuple = ExecFetchSlotTuple(slot);
2010  TupleDesc old_tupdesc = RelationGetDescr(rel);
2011  TupleConversionMap *map;
2012 
2013  rel = resultRelInfo->ri_PartitionRoot;
2014  tupdesc = RelationGetDescr(rel);
2015  /* a reverse map */
2016  map = convert_tuples_by_name(old_tupdesc, tupdesc,
2017  gettext_noop("could not convert row type"));
2018  if (map != NULL)
2019  {
2020  tuple = do_convert_tuple(tuple, map);
2021  ExecStoreTuple(tuple, slot, InvalidBuffer, false);
2022  }
2023  }
2024 
2025  insertedCols = GetInsertedColumns(resultRelInfo, estate);
2026  updatedCols = GetUpdatedColumns(resultRelInfo, estate);
2027  modifiedCols = bms_union(insertedCols, updatedCols);
2029  slot,
2030  tupdesc,
2031  modifiedCols,
2032  64);
2033  ereport(ERROR,
2034  (errcode(ERRCODE_CHECK_VIOLATION),
2035  errmsg("new row for relation \"%s\" violates partition constraint",
2036  RelationGetRelationName(orig_rel)),
2037  val_desc ? errdetail("Failing row contains %s.", val_desc) : 0));
2038  }
2039 }
#define GetUpdatedColumns(relinfo, estate)
Definition: execMain.c:115
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:320
Relation ri_RelationDesc
Definition: execnodes.h:374
#define RelationGetDescr(relation)
Definition: rel.h:429
Relation ri_PartitionRoot
Definition: execnodes.h:394
Form_pg_attribute * attrs
Definition: tupdesc.h:74
#define InvalidBuffer
Definition: buf.h:25
#define gettext_noop(x)
Definition: c.h:139
int errcode(int sqlerrcode)
Definition: elog.c:575
int natts
Definition: tupdesc.h:73
int errtableconstraint(Relation rel, const char *conname)
Definition: relcache.c:5297
static bool ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate)
Definition: execMain.c:1842
#define ERROR
Definition: elog.h:43
static char * ExecBuildSlotValueDescription(Oid reloid, TupleTableSlot *slot, TupleDesc tupdesc, Bitmapset *modifiedCols, int maxfieldlen)
Definition: execMain.c:2178
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define ereport(elevel, rest)
Definition: elog.h:122
bool has_not_null
Definition: tupdesc.h:43
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc, const char *msg)
Definition: tupconvert.c:205
List * ri_PartitionCheck
Definition: execnodes.h:392
static const char * ExecRelCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate)
Definition: execMain.c:1778
bool slot_attisnull(TupleTableSlot *slot, int attnum)
Definition: heaptuple.c:1328
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
int errtablecol(Relation rel, int attnum)
Definition: relcache.c:5260
TupleConstr * constr
Definition: tupdesc.h:76
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
HeapTuple do_convert_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:343
HeapTuple ExecFetchSlotTuple(TupleTableSlot *slot)
Definition: execTuples.c:618
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define NameStr(name)
Definition: c.h:499
uint16 num_check
Definition: tupdesc.h:42
#define RelationGetRelid(relation)
Definition: rel.h:417
#define GetInsertedColumns(relinfo, estate)
Definition: execMain.c:113
bool ExecContextForcesOids ( PlanState planstate,
bool hasoids 
)

Definition at line 1500 of file execMain.c.

References EState::es_result_relation_info, EState::es_top_eflags, EXEC_FLAG_WITH_OIDS, EXEC_FLAG_WITHOUT_OIDS, NULL, RelationData::rd_rel, ResultRelInfo::ri_RelationDesc, and PlanState::state.

Referenced by ExecAssignResultTypeFromTL(), ExecInitGather(), ExecInitGatherMerge(), and tlist_matches_tupdesc().

1501 {
1502  ResultRelInfo *ri = planstate->state->es_result_relation_info;
1503 
1504  if (ri != NULL)
1505  {
1506  Relation rel = ri->ri_RelationDesc;
1507 
1508  if (rel != NULL)
1509  {
1510  *hasoids = rel->rd_rel->relhasoids;
1511  return true;
1512  }
1513  }
1514 
1515  if (planstate->state->es_top_eflags & EXEC_FLAG_WITH_OIDS)
1516  {
1517  *hasoids = true;
1518  return true;
1519  }
1520  if (planstate->state->es_top_eflags & EXEC_FLAG_WITHOUT_OIDS)
1521  {
1522  *hasoids = false;
1523  return true;
1524  }
1525 
1526  return false;
1527 }
Relation ri_RelationDesc
Definition: execnodes.h:374
EState * state
Definition: execnodes.h:815
Form_pg_class rd_rel
Definition: rel.h:114
#define EXEC_FLAG_WITHOUT_OIDS
Definition: executor.h:64
#define NULL
Definition: c.h:229
#define EXEC_FLAG_WITH_OIDS
Definition: executor.h:63
int es_top_eflags
Definition: execnodes.h:457
ResultRelInfo * es_result_relation_info
Definition: execnodes.h:423
bool execCurrentOf ( CurrentOfExpr cexpr,
ExprContext econtext,
Oid  table_oid,
ItemPointer  current_tid 
)

Definition at line 41 of file execCurrent.c.

References Assert, PortalData::atEnd, PortalData::atStart, ExecRowMark::curCtid, CurrentOfExpr::cursor_name, CurrentOfExpr::cursor_param, DatumGetObjectId, DatumGetPointer, elog, ereport, errcode(), errmsg(), ERROR, EState::es_rowMarks, QueryDesc::estate, fetch_cursor_param_value(), get_rel_name(), GetPortalByName(), ItemPointerIsValid, lfirst, ExecRowMark::markType, NULL, PG_USED_FOR_ASSERTS_ONLY, QueryDesc::planstate, PORTAL_ONE_SELECT, PortalGetQueryDesc, PortalIsValid, ExecRowMark::relid, RowMarkRequiresRowShareLock, search_plan_tree(), SelfItemPointerAttributeNumber, slot_getattr(), ScanState::ss_ScanTupleSlot, PortalData::strategy, TableOidAttributeNumber, and TupIsNull.

Referenced by TidListEval().

45 {
46  char *cursor_name;
47  char *table_name;
48  Portal portal;
49  QueryDesc *queryDesc;
50 
51  /* Get the cursor name --- may have to look up a parameter reference */
52  if (cexpr->cursor_name)
53  cursor_name = cexpr->cursor_name;
54  else
55  cursor_name = fetch_cursor_param_value(econtext, cexpr->cursor_param);
56 
57  /* Fetch table name for possible use in error messages */
58  table_name = get_rel_name(table_oid);
59  if (table_name == NULL)
60  elog(ERROR, "cache lookup failed for relation %u", table_oid);
61 
62  /* Find the cursor's portal */
63  portal = GetPortalByName(cursor_name);
64  if (!PortalIsValid(portal))
65  ereport(ERROR,
66  (errcode(ERRCODE_UNDEFINED_CURSOR),
67  errmsg("cursor \"%s\" does not exist", cursor_name)));
68 
69  /*
70  * We have to watch out for non-SELECT queries as well as held cursors,
71  * both of which may have null queryDesc.
72  */
73  if (portal->strategy != PORTAL_ONE_SELECT)
74  ereport(ERROR,
75  (errcode(ERRCODE_INVALID_CURSOR_STATE),
76  errmsg("cursor \"%s\" is not a SELECT query",
77  cursor_name)));
78  queryDesc = PortalGetQueryDesc(portal);
79  if (queryDesc == NULL || queryDesc->estate == NULL)
80  ereport(ERROR,
81  (errcode(ERRCODE_INVALID_CURSOR_STATE),
82  errmsg("cursor \"%s\" is held from a previous transaction",
83  cursor_name)));
84 
85  /*
86  * We have two different strategies depending on whether the cursor uses
87  * FOR UPDATE/SHARE or not. The reason for supporting both is that the
88  * FOR UPDATE code is able to identify a target table in many cases where
89  * the other code can't, while the non-FOR-UPDATE case allows use of WHERE
90  * CURRENT OF with an insensitive cursor.
91  */
92  if (queryDesc->estate->es_rowMarks)
93  {
94  ExecRowMark *erm;
95  ListCell *lc;
96 
97  /*
98  * Here, the query must have exactly one FOR UPDATE/SHARE reference to
99  * the target table, and we dig the ctid info out of that.
100  */
101  erm = NULL;
102  foreach(lc, queryDesc->estate->es_rowMarks)
103  {
104  ExecRowMark *thiserm = (ExecRowMark *) lfirst(lc);
105 
106  if (!RowMarkRequiresRowShareLock(thiserm->markType))
107  continue; /* ignore non-FOR UPDATE/SHARE items */
108 
109  if (thiserm->relid == table_oid)
110  {
111  if (erm)
112  ereport(ERROR,
113  (errcode(ERRCODE_INVALID_CURSOR_STATE),
114  errmsg("cursor \"%s\" has multiple FOR UPDATE/SHARE references to table \"%s\"",
115  cursor_name, table_name)));
116  erm = thiserm;
117  }
118  }
119 
120  if (erm == NULL)
121  ereport(ERROR,
122  (errcode(ERRCODE_INVALID_CURSOR_STATE),
123  errmsg("cursor \"%s\" does not have a FOR UPDATE/SHARE reference to table \"%s\"",
124  cursor_name, table_name)));
125 
126  /*
127  * The cursor must have a current result row: per the SQL spec, it's
128  * an error if not.
129  */
130  if (portal->atStart || portal->atEnd)
131  ereport(ERROR,
132  (errcode(ERRCODE_INVALID_CURSOR_STATE),
133  errmsg("cursor \"%s\" is not positioned on a row",
134  cursor_name)));
135 
136  /* Return the currently scanned TID, if there is one */
137  if (ItemPointerIsValid(&(erm->curCtid)))
138  {
139  *current_tid = erm->curCtid;
140  return true;
141  }
142 
143  /*
144  * This table didn't produce the cursor's current row; some other
145  * inheritance child of the same parent must have. Signal caller to
146  * do nothing on this table.
147  */
148  return false;
149  }
150  else
151  {
152  ScanState *scanstate;
153  bool lisnull;
154  Oid tuple_tableoid PG_USED_FOR_ASSERTS_ONLY;
155  ItemPointer tuple_tid;
156 
157  /*
158  * Without FOR UPDATE, we dig through the cursor's plan to find the
159  * scan node. Fail if it's not there or buried underneath
160  * aggregation.
161  */
162  scanstate = search_plan_tree(queryDesc->planstate, table_oid);
163  if (!scanstate)
164  ereport(ERROR,
165  (errcode(ERRCODE_INVALID_CURSOR_STATE),
166  errmsg("cursor \"%s\" is not a simply updatable scan of table \"%s\"",
167  cursor_name, table_name)));
168 
169  /*
170  * The cursor must have a current result row: per the SQL spec, it's
171  * an error if not. We test this at the top level, rather than at the
172  * scan node level, because in inheritance cases any one table scan
173  * could easily not be on a row. We want to return false, not raise
174  * error, if the passed-in table OID is for one of the inactive scans.
175  */
176  if (portal->atStart || portal->atEnd)
177  ereport(ERROR,
178  (errcode(ERRCODE_INVALID_CURSOR_STATE),
179  errmsg("cursor \"%s\" is not positioned on a row",
180  cursor_name)));
181 
182  /* Now OK to return false if we found an inactive scan */
183  if (TupIsNull(scanstate->ss_ScanTupleSlot))
184  return false;
185 
186  /* Use slot_getattr to catch any possible mistakes */
187  tuple_tableoid =
190  &lisnull));
191  Assert(!lisnull);
192  tuple_tid = (ItemPointer)
195  &lisnull));
196  Assert(!lisnull);
197 
198  Assert(tuple_tableoid == table_oid);
199 
200  *current_tid = *tuple_tid;
201 
202  return true;
203  }
204 }
#define ItemPointerIsValid(pointer)
Definition: itemptr.h:59
bool atEnd
Definition: portal.h:187
EState * estate
Definition: execdesc.h:48
Portal GetPortalByName(const char *name)
Definition: portalmem.c:129
#define DatumGetObjectId(X)
Definition: postgres.h:506
int errcode(int sqlerrcode)
Definition: elog.c:575
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1061
unsigned int Oid
Definition: postgres_ext.h:31
#define RowMarkRequiresRowShareLock(marktype)
Definition: plannodes.h:962
ItemPointerData * ItemPointer
Definition: itemptr.h:48
ItemPointerData curCtid
Definition: execnodes.h:520
#define ERROR
Definition: elog.h:43
PlanState * planstate
Definition: execdesc.h:49
#define TupIsNull(slot)
Definition: tuptable.h:138
#define TableOidAttributeNumber
Definition: sysattr.h:27
char * cursor_name
Definition: primnodes.h:1277
PortalStrategy strategy
Definition: portal.h:143
#define ereport(elevel, rest)
Definition: elog.h:122
#define PortalIsValid(p)
Definition: portal.h:199
static ScanState * search_plan_tree(PlanState *node, Oid table_oid)
Definition: execCurrent.c:254
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
RowMarkType markType
Definition: execnodes.h:516
List * es_rowMarks
Definition: execnodes.h:452
#define DatumGetPointer(X)
Definition: postgres.h:555
#define PortalGetQueryDesc(portal)
Definition: portal.h:204
bool atStart
Definition: portal.h:186
int errmsg(const char *fmt,...)
Definition: elog.c:797
static char * fetch_cursor_param_value(ExprContext *econtext, int paramId)
Definition: execCurrent.c:212
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1141
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21
#define elog
Definition: elog.h:219
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:990
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1726
void ExecEndNode ( PlanState node)

Definition at line 654 of file execProcnode.c.

References bms_free(), PlanState::chgParam, elog, ERROR, ExecEndAgg(), ExecEndAppend(), ExecEndBitmapAnd(), ExecEndBitmapHeapScan(), ExecEndBitmapIndexScan(), ExecEndBitmapOr(), ExecEndCteScan(), ExecEndCustomScan(), ExecEndForeignScan(), ExecEndFunctionScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHash(), ExecEndHashJoin(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndLimit(), ExecEndLockRows(), ExecEndMaterial(), ExecEndMergeAppend(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNamedTuplestoreScan(), ExecEndNestLoop(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTableFuncScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), nodeTag, NULL, T_AggState, T_AppendState, T_BitmapAndState, T_BitmapHeapScanState, T_BitmapIndexScanState, T_BitmapOrState, T_CteScanState, T_CustomScanState, T_ForeignScanState, T_FunctionScanState, T_GatherMergeState, T_GatherState, T_GroupState, T_HashJoinState, T_HashState, T_IndexOnlyScanState, T_IndexScanState, T_LimitState, T_LockRowsState, T_MaterialState, T_MergeAppendState, T_MergeJoinState, T_ModifyTableState, T_NamedTuplestoreScanState, T_NestLoopState, T_ProjectSetState, T_RecursiveUnionState, T_ResultState, T_SampleScanState, T_SeqScanState, T_SetOpState, T_SortState, T_SubqueryScanState, T_TableFuncScanState, T_TidScanState, T_UniqueState, T_ValuesScanState, T_WindowAggState, and T_WorkTableScanState.

Referenced by EvalPlanQualEnd(), ExecEndAgg(), ExecEndAppend(), ExecEndBitmapAnd(), ExecEndBitmapHeapScan(), ExecEndBitmapOr(), ExecEndForeignScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHash(), ExecEndHashJoin(), ExecEndLimit(), ExecEndLockRows(), ExecEndMaterial(), ExecEndMergeAppend(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNestLoop(), ExecEndPlan(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndUnique(), and ExecEndWindowAgg().

655 {
656  /*
657  * do nothing when we get to the end of a leaf on tree.
658  */
659  if (node == NULL)
660  return;
661 
662  if (node->chgParam != NULL)
663  {
664  bms_free(node->chgParam);
665  node->chgParam = NULL;
666  }
667 
668  switch (nodeTag(node))
669  {
670  /*
671  * control nodes
672  */
673  case T_ResultState:
674  ExecEndResult((ResultState *) node);
675  break;
676 
677  case T_ProjectSetState:
679  break;
680 
681  case T_ModifyTableState:
683  break;
684 
685  case T_AppendState:
686  ExecEndAppend((AppendState *) node);
687  break;
688 
689  case T_MergeAppendState:
691  break;
692 
695  break;
696 
697  case T_BitmapAndState:
699  break;
700 
701  case T_BitmapOrState:
702  ExecEndBitmapOr((BitmapOrState *) node);
703  break;
704 
705  /*
706  * scan nodes
707  */
708  case T_SeqScanState:
709  ExecEndSeqScan((SeqScanState *) node);
710  break;
711 
712  case T_SampleScanState:
714  break;
715 
716  case T_GatherState:
717  ExecEndGather((GatherState *) node);
718  break;
719 
720  case T_GatherMergeState:
722  break;
723 
724  case T_IndexScanState:
726  break;
727 
730  break;
731 
734  break;
735 
738  break;
739 
740  case T_TidScanState:
741  ExecEndTidScan((TidScanState *) node);
742  break;
743 
744  case T_SubqueryScanState:
746  break;
747 
748  case T_FunctionScanState:
750  break;
751 
754  break;
755 
756  case T_ValuesScanState:
758  break;
759 
760  case T_CteScanState:
761  ExecEndCteScan((CteScanState *) node);
762  break;
763 
766  break;
767 
770  break;
771 
772  case T_ForeignScanState:
774  break;
775 
776  case T_CustomScanState:
778  break;
779 
780  /*
781  * join nodes
782  */
783  case T_NestLoopState:
784  ExecEndNestLoop((NestLoopState *) node);
785  break;
786 
787  case T_MergeJoinState:
789  break;
790 
791  case T_HashJoinState:
792  ExecEndHashJoin((HashJoinState *) node);
793  break;
794 
795  /*
796  * materialization nodes
797  */
798  case T_MaterialState:
799  ExecEndMaterial((MaterialState *) node);
800  break;
801 
802  case T_SortState:
803  ExecEndSort((SortState *) node);
804  break;
805 
806  case T_GroupState:
807  ExecEndGroup((GroupState *) node);
808  break;
809 
810  case T_AggState:
811  ExecEndAgg((AggState *) node);
812  break;
813 
814  case T_WindowAggState:
816  break;
817 
818  case T_UniqueState:
819  ExecEndUnique((UniqueState *) node);
820  break;
821 
822  case T_HashState:
823  ExecEndHash((HashState *) node);
824  break;
825 
826  case T_SetOpState:
827  ExecEndSetOp((SetOpState *) node);
828  break;
829 
830  case T_LockRowsState:
831  ExecEndLockRows((LockRowsState *) node);
832  break;
833 
834  case T_LimitState:
835  ExecEndLimit((LimitState *) node);
836  break;
837 
838  default:
839  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
840  break;
841  }
842 }
void ExecEndGroup(GroupState *node)
Definition: nodeGroup.c:226
void ExecEndSetOp(SetOpState *node)
Definition: nodeSetOp.c:575
void ExecEndFunctionScan(FunctionScanState *node)
void ExecEndNestLoop(NestLoopState *node)
Definition: nodeNestloop.c:361
void ExecEndIndexScan(IndexScanState *node)
void ExecEndLimit(LimitState *node)
Definition: nodeLimit.c:426
void ExecEndUnique(UniqueState *node)
Definition: nodeUnique.c:173
void ExecEndGatherMerge(GatherMergeState *node)
void ExecEndWorkTableScan(WorkTableScanState *node)
void ExecEndLockRows(LockRowsState *node)
Definition: nodeLockRows.c:446
void ExecEndNamedTuplestoreScan(NamedTuplestoreScanState *node)
void ExecEndBitmapAnd(BitmapAndState *node)
void ExecEndRecursiveUnion(RecursiveUnionState *node)
void ExecEndSubqueryScan(SubqueryScanState *node)
void ExecEndHashJoin(HashJoinState *node)
Definition: nodeHashjoin.c:548
void ExecEndTableFuncScan(TableFuncScanState *node)
void ExecEndResult(ResultState *node)
Definition: nodeResult.c:241
#define ERROR
Definition: elog.h:43
void ExecEndAppend(AppendState *node)
Definition: nodeAppend.c:252
void ExecEndForeignScan(ForeignScanState *node)
void ExecEndSort(SortState *node)
Definition: nodeSort.c:224
void ExecEndBitmapIndexScan(BitmapIndexScanState *node)
void ExecEndValuesScan(ValuesScanState *node)
void ExecEndMergeJoin(MergeJoinState *node)
void ExecEndSeqScan(SeqScanState *node)
Definition: nodeSeqscan.c:221
void ExecEndIndexOnlyScan(IndexOnlyScanState *node)
void ExecEndTidScan(TidScanState *node)
Definition: nodeTidscan.c:477
Bitmapset * chgParam
Definition: execnodes.h:837
void ExecEndCteScan(CteScanState *node)
Definition: nodeCtescan.c:277
void ExecEndCustomScan(CustomScanState *node)
Definition: nodeCustom.c:112
void ExecEndBitmapOr(BitmapOrState *node)
Definition: nodeBitmapOr.c:182
void ExecEndSampleScan(SampleScanState *node)
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
void ExecEndWindowAgg(WindowAggState *node)
#define NULL
Definition: c.h:229
void ExecEndMergeAppend(MergeAppendState *node)
#define nodeTag(nodeptr)
Definition: nodes.h:514
void ExecEndHash(HashState *node)
Definition: nodeHash.c:218
void ExecEndProjectSet(ProjectSetState *node)
void ExecEndMaterial(MaterialState *node)
Definition: nodeMaterial.c:240
#define elog
Definition: elog.h:219
void ExecEndBitmapHeapScan(BitmapHeapScanState *node)
void ExecEndAgg(AggState *node)
Definition: nodeAgg.c:3837
void ExecEndModifyTable(ModifyTableState *node)
void ExecEndGather(GatherState *node)
Definition: nodeGather.c:226
static Datum ExecEvalExprSwitchContext ( ExprState state,
ExprContext econtext,
bool isNull 
)
inlinestatic

Definition at line 281 of file executor.h.

References ExprContext::ecxt_per_tuple_memory, ExprState::evalfunc, and MemoryContextSwitchTo().

Referenced by advance_aggregates(), evaluate_expr(), EvaluateParams(), ExecCheck(), ExecProject(), ExecQual(), ExecScanSubPlan(), ExecSetParamPlan(), ExecWindowAgg(), FormIndexDatum(), FormPartitionKeyDatum(), get_qual_for_range(), operator_predicate_proof(), recompute_limits(), tablesample_init(), TidListEval(), and validateDomainConstraint().

284 {
285  Datum retDatum;
286  MemoryContext oldContext;
287 
288  oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
289  retDatum = (*state->evalfunc) (state, econtext, isNull);
290  MemoryContextSwitchTo(oldContext);
291  return retDatum;
292 }
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:203
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ExprStateEvalFunc evalfunc
Definition: execnodes.h:80
uintptr_t Datum
Definition: postgres.h:372
TupleTableSlot* ExecFilterJunk ( JunkFilter junkfilter,
TupleTableSlot slot 
)

Definition at line 262 of file execJunk.c.

References ExecClearTuple(), ExecStoreVirtualTuple(), i, JunkFilter::jf_cleanMap, JunkFilter::jf_cleanTupType, JunkFilter::jf_resultSlot, tupleDesc::natts, slot_getallattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, and values.

Referenced by ExecBRUpdateTriggers(), ExecEvalWholeRowVar(), ExecModifyTable(), ExecUpdate(), ExecutePlan(), and sqlfunction_receive().

263 {
264  TupleTableSlot *resultSlot;
265  AttrNumber *cleanMap;
266  TupleDesc cleanTupType;
267  int cleanLength;
268  int i;
269  Datum *values;
270  bool *isnull;
271  Datum *old_values;
272  bool *old_isnull;
273 
274  /*
275  * Extract all the values of the old tuple.
276  */
277  slot_getallattrs(slot);
278  old_values = slot->tts_values;
279  old_isnull = slot->tts_isnull;
280 
281  /*
282  * get info from the junk filter
283  */
284  cleanTupType = junkfilter->jf_cleanTupType;
285  cleanLength = cleanTupType->natts;
286  cleanMap = junkfilter->jf_cleanMap;
287  resultSlot = junkfilter->jf_resultSlot;
288 
289  /*
290  * Prepare to build a virtual result tuple.
291  */
292  ExecClearTuple(resultSlot);
293  values = resultSlot->tts_values;
294  isnull = resultSlot->tts_isnull;
295 
296  /*
297  * Transpose data into proper fields of the new tuple.
298  */
299  for (i = 0; i < cleanLength; i++)
300  {
301  int j = cleanMap[i];
302 
303  if (j == 0)
304  {
305  values[i] = (Datum) 0;
306  isnull[i] = true;
307  }
308  else
309  {
310  values[i] = old_values[j - 1];
311  isnull[i] = old_isnull[j - 1];
312  }
313  }
314 
315  /*
316  * And return the virtual tuple.
317  */
318  return ExecStoreVirtualTuple(resultSlot);
319 }
AttrNumber * jf_cleanMap
Definition: execnodes.h:334
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * jf_resultSlot
Definition: execnodes.h:335
Datum * tts_values
Definition: tuptable.h:125
int natts
Definition: tupdesc.h:73
bool * tts_isnull
Definition: tuptable.h:126
TupleDesc jf_cleanTupType
Definition: execnodes.h:333
void slot_getallattrs(TupleTableSlot *slot)
Definition: heaptuple.c:1237
uintptr_t Datum
Definition: postgres.h:372
static Datum values[MAXATTR]
Definition: bootstrap.c:163
int i
int16 AttrNumber
Definition: attnum.h:21
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:488
AttrNumber ExecFindJunkAttribute ( JunkFilter junkfilter,
const char *  attrName 
)

Definition at line 209 of file execJunk.c.

References ExecFindJunkAttributeInTlist(), and JunkFilter::jf_targetList.

Referenced by ExecInitModifyTable().

210 {
211  return ExecFindJunkAttributeInTlist(junkfilter->jf_targetList, attrName);
212 }
AttrNumber ExecFindJunkAttributeInTlist(List *targetlist, const char *attrName)
Definition: execJunk.c:221
List * jf_targetList
Definition: execnodes.h:332
AttrNumber ExecFindJunkAttributeInTlist ( List targetlist,
const char *  attrName 
)

Definition at line 221 of file execJunk.c.

References InvalidAttrNumber, lfirst, TargetEntry::resjunk, TargetEntry::resname, and TargetEntry::resno.

Referenced by ExecBuildAuxRowMark(), ExecFindJunkAttribute(), and postgresBeginForeignModify().

222 {
223  ListCell *t;
224 
225  foreach(t, targetlist)
226  {
227  TargetEntry *tle = lfirst(t);
228 
229  if (tle->resjunk && tle->resname &&
230  (strcmp(tle->resname, attrName) == 0))
231  {
232  /* We found it ! */
233  return tle->resno;
234  }
235  }
236 
237  return InvalidAttrNumber;
238 }
char * resname
Definition: primnodes.h:1369
bool resjunk
Definition: primnodes.h:1374
AttrNumber resno
Definition: primnodes.h:1368
#define lfirst(lc)
Definition: pg_list.h:106
#define InvalidAttrNumber
Definition: attnum.h:23
int ExecFindPartition ( ResultRelInfo resultRelInfo,
PartitionDispatch pd,
TupleTableSlot slot,
EState estate 
)

Definition at line 3313 of file execMain.c.

References Assert, ExprContext::ecxt_scantuple, ereport, errcode(), errdetail(), errmsg(), ERROR, ExecBuildSlotPartitionKeyDescription(), FormPartitionKeyDatum(), get_partition_for_tuple(), GetPerTupleExprContext, OidIsValid, PARTITION_MAX_KEYS, RelationGetRelationName, RelationGetRelid, PartitionDispatchData::reldesc, and result.

Referenced by CopyFrom(), and ExecInsert().

3315 {
3316  int result;
3317  PartitionDispatchData *failed_at;
3318  TupleTableSlot *failed_slot;
3319 
3320  result = get_partition_for_tuple(pd, slot, estate,
3321  &failed_at, &failed_slot);
3322  if (result < 0)
3323  {
3324  Relation failed_rel;
3325  Datum key_values[PARTITION_MAX_KEYS];
3326  bool key_isnull[PARTITION_MAX_KEYS];
3327  char *val_desc;
3328  ExprContext *ecxt = GetPerTupleExprContext(estate);
3329 
3330  failed_rel = failed_at->reldesc;
3331  ecxt->ecxt_scantuple = failed_slot;
3332  FormPartitionKeyDatum(failed_at, failed_slot, estate,
3333  key_values, key_isnull);
3334  val_desc = ExecBuildSlotPartitionKeyDescription(failed_rel,
3335  key_values,
3336  key_isnull,
3337  64);
3338  Assert(OidIsValid(RelationGetRelid(failed_rel)));
3339  ereport(ERROR,
3340  (errcode(ERRCODE_CHECK_VIOLATION),
3341  errmsg("no partition of relation \"%s\" found for row",
3342  RelationGetRelationName(failed_rel)),
3343  val_desc ? errdetail("Partition key of the failing row contains %s.", val_desc) : 0));
3344  }
3345 
3346  return result;
3347 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PARTITION_MAX_KEYS
int get_partition_for_tuple(PartitionDispatch *pd, TupleTableSlot *slot, EState *estate, PartitionDispatchData **failed_at, TupleTableSlot **failed_slot)
Definition: partition.c:1916
return result
Definition: formatting.c:1632
#define OidIsValid(objectId)
Definition: c.h:538
#define GetPerTupleExprContext(estate)
Definition: executor.h:456
#define ERROR
Definition: elog.h:43
static char * ExecBuildSlotPartitionKeyDescription(Relation rel, Datum *values, bool *isnull, int maxfieldlen)
Definition: execMain.c:3357
void FormPartitionKeyDatum(PartitionDispatch pd, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: partition.c:1857
int errdetail(const char *fmt,...)
Definition: elog.c:873
#define RelationGetRelationName(relation)
Definition: rel.h:437
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
#define Assert(condition)
Definition: c.h:675
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:197
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RelationGetRelid(relation)
Definition: rel.h:417
ExecRowMark* ExecFindRowMark ( EState estate,
Index  rti,
bool  missing_ok 
)

Definition at line 2340 of file execMain.c.

References elog, ERROR, EState::es_rowMarks, lfirst, NULL, and ExecRowMark::rti.

Referenced by ExecInitLockRows(), ExecInitModifyTable(), and ExecOpenScanRelation().

2341 {
2342  ListCell *lc;
2343 
2344  foreach(lc, estate->es_rowMarks)
2345  {
2346  ExecRowMark *erm = (ExecRowMark *) lfirst(lc);
2347 
2348  if (erm->rti == rti)
2349  return erm;
2350  }
2351  if (!missing_ok)
2352  elog(ERROR, "failed to find ExecRowMark for rangetable index %u", rti);
2353  return NULL;
2354 }
#define ERROR
Definition: elog.h:43
Index rti
Definition: execnodes.h:513
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
List * es_rowMarks
Definition: execnodes.h:452
#define elog
Definition: elog.h:219
Datum ExecGetJunkAttribute ( TupleTableSlot slot,
AttrNumber  attno,
bool isNull 
)

Definition at line 248 of file execJunk.c.

References Assert, and slot_getattr().

Referenced by EvalPlanQualFetchRowMarks(), ExecLockRows(), ExecModifyTable(), postgresExecForeignDelete(), and postgresExecForeignUpdate().

250 {
251  Assert(attno > 0);
252 
253  return slot_getattr(slot, attno, isNull);
254 }
#define Assert(condition)
Definition: c.h:675
Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: heaptuple.c:1141
ResultRelInfo* ExecGetTriggerResultRel ( EState estate,
Oid  relid 
)

Definition at line 1392 of file execMain.c.

References EState::es_instrument, EState::es_num_result_relations, EState::es_query_cxt, EState::es_result_relations, EState::es_trig_target_relations, heap_open(), InitResultRelInfo(), lappend(), lfirst, makeNode, MemoryContextSwitchTo(), NoLock, NULL, RelationGetRelid, and ResultRelInfo::ri_RelationDesc.

Referenced by afterTriggerInvokeEvents().

1393 {
1394  ResultRelInfo *rInfo;
1395  int nr;
1396  ListCell *l;
1397  Relation rel;
1398  MemoryContext oldcontext;
1399 
1400  /* First, search through the query result relations */
1401  rInfo = estate->es_result_relations;
1402  nr = estate->es_num_result_relations;
1403  while (nr > 0)
1404  {
1405  if (RelationGetRelid(rInfo->ri_RelationDesc) == relid)
1406  return rInfo;
1407  rInfo++;
1408  nr--;
1409  }
1410  /* Nope, but maybe we already made an extra ResultRelInfo for it */
1411  foreach(l, estate->es_trig_target_relations)
1412  {
1413  rInfo = (ResultRelInfo *) lfirst(l);
1414  if (RelationGetRelid(rInfo->ri_RelationDesc) == relid)
1415  return rInfo;
1416  }
1417  /* Nope, so we need a new one */
1418 
1419  /*
1420  * Open the target relation's relcache entry. We assume that an
1421  * appropriate lock is still held by the backend from whenever the trigger
1422  * event got queued, so we need take no new lock here. Also, we need not
1423  * recheck the relkind, so no need for CheckValidResultRel.
1424  */
1425  rel = heap_open(relid, NoLock);
1426 
1427  /*
1428  * Make the new entry in the right context.
1429  */
1430  oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1431  rInfo = makeNode(ResultRelInfo);
1432  InitResultRelInfo(rInfo,
1433  rel,
1434  0, /* dummy rangetable index */
1435  NULL,
1436  estate->es_instrument);
1437  estate->es_trig_target_relations =
1438  lappend(estate->es_trig_target_relations, rInfo);
1439  MemoryContextSwitchTo(oldcontext);
1440 
1441  /*
1442  * Currently, we don't need any index information in ResultRelInfos used
1443  * only for triggers, so no need to call ExecOpenIndices.
1444  */
1445 
1446  return rInfo;
1447 }
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, Relation partition_root, int instrument_options)
Definition: execMain.c:1297
Relation ri_RelationDesc
Definition: execnodes.h:374
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
MemoryContext es_query_cxt
Definition: execnodes.h:448
#define NoLock
Definition: lockdefs.h:34
ResultRelInfo * es_result_relations
Definition: execnodes.h:421
int es_instrument
Definition: execnodes.h:458
List * lappend(List *list, void *datum)
Definition: list.c:128
List * es_trig_target_relations
Definition: execnodes.h:436
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
int es_num_result_relations
Definition: execnodes.h:422
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
#define RelationGetRelid(relation)
Definition: rel.h:417
ExprState* ExecInitCheck ( List qual,
PlanState parent 
)

Definition at line 246 of file execExpr.c.

References Assert, ExecInitExpr(), IsA, make_ands_explicit(), NIL, and NULL.

Referenced by ExecPrepareCheck().

247 {
248  /* short-circuit (here and in ExecCheck) for empty restriction list */
249  if (qual == NIL)
250  return NULL;
251 
252  Assert(IsA(qual, List));
253 
254  /*
255  * Just convert the implicit-AND list to an explicit AND (if there's more
256  * than one entry), and compile normally. Unlike ExecQual, we can't
257  * short-circuit on NULL results, so the regular AND behavior is needed.
258  */
259  return ExecInitExpr(make_ands_explicit(qual), parent);
260 }
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
Expr * make_ands_explicit(List *andclauses)
Definition: clauses.c:367
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:113
Definition: pg_list.h:45
ExprState* ExecInitExpr ( Expr node,
PlanState parent 
)

Definition at line 113 of file execExpr.c.

References EEOP_DONE, ExecInitExprRec(), ExecInitExprSlots(), ExecReadyExpr(), ExprState::expr, ExprEvalPushStep(), makeNode, NULL, ExprEvalStep::opcode, ExprState::resnull, and ExprState::resvalue.

Referenced by ATRewriteTable(), BeginCopyFrom(), build_pertrans_for_aggref(), evaluate_expr(), exec_eval_simple_expr(), ExecIndexBuildScanKeys(), ExecInitCheck(), ExecInitExprList(), ExecInitExprRec(), ExecInitHashJoin(), ExecInitLimit(), ExecInitProjectSet(), ExecInitSampleScan(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitTableFunctionResult(), ExecInitWindowAgg(), ExecPrepareExpr(), get_cast_hashentry(), get_qual_for_range(), MJExamineQuals(), operator_predicate_proof(), prep_domain_constraints(), slot_fill_defaults(), and TidExprListCreate().

114 {
115  ExprState *state;
116  ExprEvalStep scratch;
117 
118  /* Special case: NULL expression produces a NULL ExprState pointer */
119  if (node == NULL)
120  return NULL;
121 
122  /* Initialize ExprState with empty step list */
123  state = makeNode(ExprState);
124  state->expr = node;
125 
126  /* Insert EEOP_*_FETCHSOME steps as needed */
127  ExecInitExprSlots(state, (Node *) node);
128 
129  /* Compile the expression proper */
130  ExecInitExprRec(node, parent, state, &state->resvalue, &state->resnull);
131 
132  /* Finally, append a DONE step */
133  scratch.opcode = EEOP_DONE;
134  ExprEvalPushStep(state, &scratch);
135 
136  ExecReadyExpr(state);
137 
138  return state;
139 }
Definition: nodes.h:509
bool resnull
Definition: execnodes.h:63
Expr * expr
Definition: execnodes.h:83
static void ExecInitExprSlots(ExprState *state, Node *node)
Definition: execExpr.c:2157
static void ExecReadyExpr(ExprState *state)
Definition: execExpr.c:574
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
Definition: regguts.h:298
intptr_t opcode
Definition: execExpr.h:227
static void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s)
Definition: execExpr.c:2028
static void ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state, Datum *resv, bool *resnull)
Definition: execExpr.c:589
Datum resvalue
Definition: execnodes.h:64
List* ExecInitExprList ( List nodes,
PlanState parent 
)

Definition at line 266 of file execExpr.c.

References ExecInitExpr(), lappend(), lfirst, NIL, and result.

Referenced by build_pertrans_for_aggref(), ExecInitExprRec(), ExecInitFunctionResultSet(), ExecInitIndexScan(), ExecInitSampleScan(), ExecInitSubPlan(), ExecInitTableFuncScan(), ExecInitTableFunctionResult(), prepare_query_params(), and ValuesNext().

267 {
268  List *result = NIL;
269  ListCell *lc;
270 
271  foreach(lc, nodes)
272  {
273  Expr *e = lfirst(lc);
274 
275  result = lappend(result, ExecInitExpr(e, parent));
276  }
277 
278  return result;
279 }
#define NIL
Definition: pg_list.h:69
return result
Definition: formatting.c:1632
List * lappend(List *list, void *datum)
Definition: list.c:128
#define lfirst(lc)
Definition: pg_list.h:106
e
Definition: preproc-init.c:82
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:113
Definition: pg_list.h:45
SetExprState* ExecInitFunctionResultSet ( Expr expr,
ExprContext econtext,
PlanState parent 
)

Definition at line 424 of file execSRF.c.

References FuncExpr::args, OpExpr::args, SetExprState::args, Assert, ExprContext::ecxt_per_query_memory, elog, ERROR, ExecInitExprList(), SetExprState::expr, FmgrInfo::fn_oid, FmgrInfo::fn_retset, SetExprState::func, FuncExpr::funcid, SetExprState::funcReturnsSet, init_sexpr(), FuncExpr::inputcollid, OpExpr::inputcollid, InvalidOid, IsA, makeNode, nodeTag, and OpExpr::opfuncid.

Referenced by ExecInitProjectSet().

426 {
428 
429  state->funcReturnsSet = true;
430  state->expr = expr;
431  state->func.fn_oid = InvalidOid;
432 
433  /*
434  * Initialize metadata. The expression node could be either a FuncExpr or
435  * an OpExpr.
436  */
437  if (IsA(expr, FuncExpr))
438  {
439  FuncExpr *func = (FuncExpr *) expr;
440 
441  state->args = ExecInitExprList(func->args, parent);
442  init_sexpr(func->funcid, func->inputcollid, expr, state, parent,
443  econtext->ecxt_per_query_memory, true, true);
444  }
445  else if (IsA(expr, OpExpr))
446  {
447  OpExpr *op = (OpExpr *) expr;
448 
449  state->args = ExecInitExprList(op->args, parent);
450  init_sexpr(op->opfuncid, op->inputcollid, expr, state, parent,
451  econtext->ecxt_per_query_memory, true, true);
452  }
453  else
454  elog(ERROR, "unrecognized node type: %d",
455  (int) nodeTag(expr));
456 
457  /* shouldn't get here unless the selected function returns set */
458  Assert(state->func.fn_retset);
459 
460  return state;
461 }
FmgrInfo func
Definition: execnodes.h:679
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
List * args
Definition: primnodes.h:456
List * args
Definition: execnodes.h:665
static void init_sexpr(Oid foid, Oid input_collation, Expr *node, SetExprState *sexpr, PlanState *parent, MemoryContext sexprCxt, bool allowSRF, bool needDescForSRF)
Definition: execSRF.c:649
bool fn_retset
Definition: fmgr.h:62
Oid funcid
Definition: primnodes.h:448
#define ERROR
Definition: elog.h:43
bool funcReturnsSet
Definition: execnodes.h:701
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:266
Oid opfuncid
Definition: primnodes.h:496
Expr * expr
Definition: execnodes.h:664
#define InvalidOid
Definition: postgres_ext.h:36
Oid fn_oid
Definition: fmgr.h:59
#define makeNode(_type_)
Definition: nodes.h:557
Oid inputcollid
Definition: primnodes.h:455
#define Assert(condition)
Definition: c.h:675
Definition: regguts.h:298
Oid inputcollid
Definition: primnodes.h:500
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:202
#define nodeTag(nodeptr)
Definition: nodes.h:514
#define elog
Definition: elog.h:219
List * args
Definition: primnodes.h:501