PostgreSQL Source Code git master
execUtils.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * execUtils.c
4 * miscellaneous executor utility routines
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/executor/execUtils.c
12 *
13 *-------------------------------------------------------------------------
14 */
15/*
16 * INTERFACE ROUTINES
17 * CreateExecutorState Create/delete executor working state
18 * FreeExecutorState
19 * CreateExprContext
20 * CreateStandaloneExprContext
21 * FreeExprContext
22 * ReScanExprContext
23 *
24 * ExecAssignExprContext Common code for plan node init routines.
25 * etc
26 *
27 * ExecOpenScanRelation Common code for scan node init routines.
28 *
29 * ExecInitRangeTable Set up executor's range-table-related data.
30 *
31 * ExecGetRangeTableRelation Fetch Relation for a rangetable entry.
32 *
33 * executor_errposition Report syntactic position of an error.
34 *
35 * RegisterExprContextCallback Register function shutdown callback
36 * UnregisterExprContextCallback Deregister function shutdown callback
37 *
38 * GetAttributeByName Runtime extraction of columns from tuples.
39 * GetAttributeByNum
40 *
41 * NOTES
42 * This file has traditionally been the place to stick misc.
43 * executor support stuff that doesn't really go anyplace else.
44 */
45
46#include "postgres.h"
47
48#include "access/parallel.h"
49#include "access/table.h"
50#include "access/tableam.h"
51#include "executor/executor.h"
53#include "jit/jit.h"
54#include "mb/pg_wchar.h"
55#include "miscadmin.h"
58#include "storage/lmgr.h"
59#include "utils/builtins.h"
60#include "utils/memutils.h"
61#include "utils/rel.h"
62#include "utils/typcache.h"
63
64
65static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc);
66static void ShutdownExprContext(ExprContext *econtext, bool isCommit);
68
69
70/* ----------------------------------------------------------------
71 * Executor state and memory management functions
72 * ----------------------------------------------------------------
73 */
74
75/* ----------------
76 * CreateExecutorState
77 *
78 * Create and initialize an EState node, which is the root of
79 * working storage for an entire Executor invocation.
80 *
81 * Principally, this creates the per-query memory context that will be
82 * used to hold all working data that lives till the end of the query.
83 * Note that the per-query context will become a child of the caller's
84 * CurrentMemoryContext.
85 * ----------------
86 */
87EState *
89{
90 EState *estate;
91 MemoryContext qcontext;
92 MemoryContext oldcontext;
93
94 /*
95 * Create the per-query context for this Executor run.
96 */
98 "ExecutorState",
100
101 /*
102 * Make the EState node within the per-query context. This way, we don't
103 * need a separate pfree() operation for it at shutdown.
104 */
105 oldcontext = MemoryContextSwitchTo(qcontext);
106
107 estate = makeNode(EState);
108
109 /*
110 * Initialize all fields of the Executor State structure
111 */
113 estate->es_snapshot = InvalidSnapshot; /* caller must initialize this */
114 estate->es_crosscheck_snapshot = InvalidSnapshot; /* no crosscheck */
115 estate->es_range_table = NIL;
116 estate->es_range_table_size = 0;
117 estate->es_relations = NULL;
118 estate->es_rowmarks = NULL;
119 estate->es_rteperminfos = NIL;
120 estate->es_plannedstmt = NULL;
121 estate->es_part_prune_infos = NIL;
122
123 estate->es_junkFilter = NULL;
124
125 estate->es_output_cid = (CommandId) 0;
126
127 estate->es_result_relations = NULL;
131
134
135 estate->es_param_list_info = NULL;
136 estate->es_param_exec_vals = NULL;
137
138 estate->es_queryEnv = NULL;
139
140 estate->es_query_cxt = qcontext;
141
142 estate->es_tupleTable = NIL;
143
144 estate->es_processed = 0;
145 estate->es_total_processed = 0;
146
147 estate->es_top_eflags = 0;
148 estate->es_instrument = 0;
149 estate->es_finished = false;
150
151 estate->es_exprcontexts = NIL;
152
153 estate->es_subplanstates = NIL;
154
155 estate->es_auxmodifytables = NIL;
156
157 estate->es_per_tuple_exprcontext = NULL;
158
159 estate->es_sourceText = NULL;
160
161 estate->es_use_parallel_mode = false;
164
165 estate->es_jit_flags = 0;
166 estate->es_jit = NULL;
167
168 /*
169 * Return the executor state structure
170 */
171 MemoryContextSwitchTo(oldcontext);
172
173 return estate;
174}
175
176/* ----------------
177 * FreeExecutorState
178 *
179 * Release an EState along with all remaining working storage.
180 *
181 * Note: this is not responsible for releasing non-memory resources, such as
182 * open relations or buffer pins. But it will shut down any still-active
183 * ExprContexts within the EState and deallocate associated JITed expressions.
184 * That is sufficient cleanup for situations where the EState has only been
185 * used for expression evaluation, and not to run a complete Plan.
186 *
187 * This can be called in any memory context ... so long as it's not one
188 * of the ones to be freed.
189 * ----------------
190 */
191void
193{
194 /*
195 * Shut down and free any remaining ExprContexts. We do this explicitly
196 * to ensure that any remaining shutdown callbacks get called (since they
197 * might need to release resources that aren't simply memory within the
198 * per-query memory context).
199 */
200 while (estate->es_exprcontexts)
201 {
202 /*
203 * XXX: seems there ought to be a faster way to implement this than
204 * repeated list_delete(), no?
205 */
207 true);
208 /* FreeExprContext removed the list link for us */
209 }
210
211 /* release JIT context, if allocated */
212 if (estate->es_jit)
213 {
215 estate->es_jit = NULL;
216 }
217
218 /* release partition directory, if allocated */
219 if (estate->es_partition_directory)
220 {
222 estate->es_partition_directory = NULL;
223 }
224
225 /*
226 * Free the per-query memory context, thereby releasing all working
227 * memory, including the EState node itself.
228 */
230}
231
232/*
233 * Internal implementation for CreateExprContext() and CreateWorkExprContext()
234 * that allows control over the AllocSet parameters.
235 */
236static ExprContext *
237CreateExprContextInternal(EState *estate, Size minContextSize,
238 Size initBlockSize, Size maxBlockSize)
239{
240 ExprContext *econtext;
241 MemoryContext oldcontext;
242
243 /* Create the ExprContext node within the per-query memory context */
244 oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
245
246 econtext = makeNode(ExprContext);
247
248 /* Initialize fields of ExprContext */
249 econtext->ecxt_scantuple = NULL;
250 econtext->ecxt_innertuple = NULL;
251 econtext->ecxt_outertuple = NULL;
252
253 econtext->ecxt_per_query_memory = estate->es_query_cxt;
254
255 /*
256 * Create working memory for expression evaluation in this context.
257 */
258 econtext->ecxt_per_tuple_memory =
260 "ExprContext",
261 minContextSize,
262 initBlockSize,
263 maxBlockSize);
264
265 econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
266 econtext->ecxt_param_list_info = estate->es_param_list_info;
267
268 econtext->ecxt_aggvalues = NULL;
269 econtext->ecxt_aggnulls = NULL;
270
271 econtext->caseValue_datum = (Datum) 0;
272 econtext->caseValue_isNull = true;
273
274 econtext->domainValue_datum = (Datum) 0;
275 econtext->domainValue_isNull = true;
276
277 econtext->ecxt_estate = estate;
278
279 econtext->ecxt_callbacks = NULL;
280
281 /*
282 * Link the ExprContext into the EState to ensure it is shut down when the
283 * EState is freed. Because we use lcons(), shutdowns will occur in
284 * reverse order of creation, which may not be essential but can't hurt.
285 */
286 estate->es_exprcontexts = lcons(econtext, estate->es_exprcontexts);
287
288 MemoryContextSwitchTo(oldcontext);
289
290 return econtext;
291}
292
293/* ----------------
294 * CreateExprContext
295 *
296 * Create a context for expression evaluation within an EState.
297 *
298 * An executor run may require multiple ExprContexts (we usually make one
299 * for each Plan node, and a separate one for per-output-tuple processing
300 * such as constraint checking). Each ExprContext has its own "per-tuple"
301 * memory context.
302 *
303 * Note we make no assumption about the caller's memory context.
304 * ----------------
305 */
308{
310}
311
312
313/* ----------------
314 * CreateWorkExprContext
315 *
316 * Like CreateExprContext, but specifies the AllocSet sizes to be reasonable
317 * in proportion to work_mem. If the maximum block allocation size is too
318 * large, it's easy to skip right past work_mem with a single allocation.
319 * ----------------
320 */
323{
324 Size minContextSize = ALLOCSET_DEFAULT_MINSIZE;
325 Size initBlockSize = ALLOCSET_DEFAULT_INITSIZE;
326 Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
327
328 /* choose the maxBlockSize to be no larger than 1/16 of work_mem */
329 while (maxBlockSize > work_mem * (Size) 1024 / 16)
330 maxBlockSize >>= 1;
331
332 if (maxBlockSize < ALLOCSET_DEFAULT_INITSIZE)
333 maxBlockSize = ALLOCSET_DEFAULT_INITSIZE;
334
335 return CreateExprContextInternal(estate, minContextSize,
336 initBlockSize, maxBlockSize);
337}
338
339/* ----------------
340 * CreateStandaloneExprContext
341 *
342 * Create a context for standalone expression evaluation.
343 *
344 * An ExprContext made this way can be used for evaluation of expressions
345 * that contain no Params, subplans, or Var references (it might work to
346 * put tuple references into the scantuple field, but it seems unwise).
347 *
348 * The ExprContext struct is allocated in the caller's current memory
349 * context, which also becomes its "per query" context.
350 *
351 * It is caller's responsibility to free the ExprContext when done,
352 * or at least ensure that any shutdown callbacks have been called
353 * (ReScanExprContext() is suitable). Otherwise, non-memory resources
354 * might be leaked.
355 * ----------------
356 */
359{
360 ExprContext *econtext;
361
362 /* Create the ExprContext node within the caller's memory context */
363 econtext = makeNode(ExprContext);
364
365 /* Initialize fields of ExprContext */
366 econtext->ecxt_scantuple = NULL;
367 econtext->ecxt_innertuple = NULL;
368 econtext->ecxt_outertuple = NULL;
369
371
372 /*
373 * Create working memory for expression evaluation in this context.
374 */
375 econtext->ecxt_per_tuple_memory =
377 "ExprContext",
379
380 econtext->ecxt_param_exec_vals = NULL;
381 econtext->ecxt_param_list_info = NULL;
382
383 econtext->ecxt_aggvalues = NULL;
384 econtext->ecxt_aggnulls = NULL;
385
386 econtext->caseValue_datum = (Datum) 0;
387 econtext->caseValue_isNull = true;
388
389 econtext->domainValue_datum = (Datum) 0;
390 econtext->domainValue_isNull = true;
391
392 econtext->ecxt_estate = NULL;
393
394 econtext->ecxt_callbacks = NULL;
395
396 return econtext;
397}
398
399/* ----------------
400 * FreeExprContext
401 *
402 * Free an expression context, including calling any remaining
403 * shutdown callbacks.
404 *
405 * Since we free the temporary context used for expression evaluation,
406 * any previously computed pass-by-reference expression result will go away!
407 *
408 * If isCommit is false, we are being called in error cleanup, and should
409 * not call callbacks but only release memory. (It might be better to call
410 * the callbacks and pass the isCommit flag to them, but that would require
411 * more invasive code changes than currently seems justified.)
412 *
413 * Note we make no assumption about the caller's memory context.
414 * ----------------
415 */
416void
417FreeExprContext(ExprContext *econtext, bool isCommit)
418{
419 EState *estate;
420
421 /* Call any registered callbacks */
422 ShutdownExprContext(econtext, isCommit);
423 /* And clean up the memory used */
425 /* Unlink self from owning EState, if any */
426 estate = econtext->ecxt_estate;
427 if (estate)
429 econtext);
430 /* And delete the ExprContext node */
431 pfree(econtext);
432}
433
434/*
435 * ReScanExprContext
436 *
437 * Reset an expression context in preparation for a rescan of its
438 * plan node. This requires calling any registered shutdown callbacks,
439 * since any partially complete set-returning-functions must be canceled.
440 *
441 * Note we make no assumption about the caller's memory context.
442 */
443void
445{
446 /* Call any registered callbacks */
447 ShutdownExprContext(econtext, true);
448 /* And clean up the memory used */
450}
451
452/*
453 * Build a per-output-tuple ExprContext for an EState.
454 *
455 * This is normally invoked via GetPerTupleExprContext() macro,
456 * not directly.
457 */
460{
461 if (estate->es_per_tuple_exprcontext == NULL)
463
464 return estate->es_per_tuple_exprcontext;
465}
466
467
468/* ----------------------------------------------------------------
469 * miscellaneous node-init support functions
470 *
471 * Note: all of these are expected to be called with CurrentMemoryContext
472 * equal to the per-query memory context.
473 * ----------------------------------------------------------------
474 */
475
476/* ----------------
477 * ExecAssignExprContext
478 *
479 * This initializes the ps_ExprContext field. It is only necessary
480 * to do this for nodes which use ExecQual or ExecProject
481 * because those routines require an econtext. Other nodes that
482 * don't have to evaluate expressions don't need to do this.
483 * ----------------
484 */
485void
487{
488 planstate->ps_ExprContext = CreateExprContext(estate);
489}
490
491/* ----------------
492 * ExecGetResultType
493 * ----------------
494 */
497{
498 return planstate->ps_ResultTupleDesc;
499}
500
501/*
502 * ExecGetResultSlotOps - information about node's type of result slot
503 */
504const TupleTableSlotOps *
505ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
506{
507 if (planstate->resultopsset && planstate->resultops)
508 {
509 if (isfixed)
510 *isfixed = planstate->resultopsfixed;
511 return planstate->resultops;
512 }
513
514 if (isfixed)
515 {
516 if (planstate->resultopsset)
517 *isfixed = planstate->resultopsfixed;
518 else if (planstate->ps_ResultTupleSlot)
519 *isfixed = TTS_FIXED(planstate->ps_ResultTupleSlot);
520 else
521 *isfixed = false;
522 }
523
524 if (!planstate->ps_ResultTupleSlot)
525 return &TTSOpsVirtual;
526
527 return planstate->ps_ResultTupleSlot->tts_ops;
528}
529
530/*
531 * ExecGetCommonSlotOps - identify common result slot type, if any
532 *
533 * If all the given PlanState nodes return the same fixed tuple slot type,
534 * return the slot ops struct for that slot type. Else, return NULL.
535 */
536const TupleTableSlotOps *
537ExecGetCommonSlotOps(PlanState **planstates, int nplans)
538{
539 const TupleTableSlotOps *result;
540 bool isfixed;
541
542 if (nplans <= 0)
543 return NULL;
544 result = ExecGetResultSlotOps(planstates[0], &isfixed);
545 if (!isfixed)
546 return NULL;
547 for (int i = 1; i < nplans; i++)
548 {
549 const TupleTableSlotOps *thisops;
550
551 thisops = ExecGetResultSlotOps(planstates[i], &isfixed);
552 if (!isfixed)
553 return NULL;
554 if (result != thisops)
555 return NULL;
556 }
557 return result;
558}
559
560/*
561 * ExecGetCommonChildSlotOps - as above, for the PlanState's standard children
562 */
563const TupleTableSlotOps *
565{
566 PlanState *planstates[2];
567
568 planstates[0] = outerPlanState(ps);
569 planstates[1] = innerPlanState(ps);
570 return ExecGetCommonSlotOps(planstates, 2);
571}
572
573
574/* ----------------
575 * ExecAssignProjectionInfo
576 *
577 * forms the projection information from the node's targetlist
578 *
579 * Notes for inputDesc are same as for ExecBuildProjectionInfo: supply it
580 * for a relation-scan node, can pass NULL for upper-level nodes
581 * ----------------
582 */
583void
585 TupleDesc inputDesc)
586{
587 planstate->ps_ProjInfo =
589 planstate->ps_ExprContext,
590 planstate->ps_ResultTupleSlot,
591 planstate,
592 inputDesc);
593}
594
595
596/* ----------------
597 * ExecConditionalAssignProjectionInfo
598 *
599 * as ExecAssignProjectionInfo, but store NULL rather than building projection
600 * info if no projection is required
601 * ----------------
602 */
603void
605 int varno)
606{
607 if (tlist_matches_tupdesc(planstate,
608 planstate->plan->targetlist,
609 varno,
610 inputDesc))
611 {
612 planstate->ps_ProjInfo = NULL;
613 planstate->resultopsset = planstate->scanopsset;
614 planstate->resultopsfixed = planstate->scanopsfixed;
615 planstate->resultops = planstate->scanops;
616 }
617 else
618 {
619 if (!planstate->ps_ResultTupleSlot)
620 {
622 planstate->resultops = &TTSOpsVirtual;
623 planstate->resultopsfixed = true;
624 planstate->resultopsset = true;
625 }
626 ExecAssignProjectionInfo(planstate, inputDesc);
627 }
628}
629
630static bool
631tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
632{
633 int numattrs = tupdesc->natts;
634 int attrno;
635 ListCell *tlist_item = list_head(tlist);
636
637 /* Check the tlist attributes */
638 for (attrno = 1; attrno <= numattrs; attrno++)
639 {
640 Form_pg_attribute att_tup = TupleDescAttr(tupdesc, attrno - 1);
641 Var *var;
642
643 if (tlist_item == NULL)
644 return false; /* tlist too short */
645 var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr;
646 if (!var || !IsA(var, Var))
647 return false; /* tlist item not a Var */
648 /* if these Asserts fail, planner messed up */
649 Assert(var->varno == varno);
650 Assert(var->varlevelsup == 0);
651 if (var->varattno != attrno)
652 return false; /* out of order */
653 if (att_tup->attisdropped)
654 return false; /* table contains dropped columns */
655 if (att_tup->atthasmissing)
656 return false; /* table contains cols with missing values */
657
658 /*
659 * Note: usually the Var's type should match the tupdesc exactly, but
660 * in situations involving unions of columns that have different
661 * typmods, the Var may have come from above the union and hence have
662 * typmod -1. This is a legitimate situation since the Var still
663 * describes the column, just not as exactly as the tupdesc does. We
664 * could change the planner to prevent it, but it'd then insert
665 * projection steps just to convert from specific typmod to typmod -1,
666 * which is pretty silly.
667 */
668 if (var->vartype != att_tup->atttypid ||
669 (var->vartypmod != att_tup->atttypmod &&
670 var->vartypmod != -1))
671 return false; /* type mismatch */
672
673 tlist_item = lnext(tlist, tlist_item);
674 }
675
676 if (tlist_item)
677 return false; /* tlist too long */
678
679 return true;
680}
681
682
683/* ----------------------------------------------------------------
684 * Scan node support
685 * ----------------------------------------------------------------
686 */
687
688/* ----------------
689 * ExecAssignScanType
690 * ----------------
691 */
692void
694{
695 TupleTableSlot *slot = scanstate->ss_ScanTupleSlot;
696
697 ExecSetSlotDescriptor(slot, tupDesc);
698}
699
700/* ----------------
701 * ExecCreateScanSlotFromOuterPlan
702 * ----------------
703 */
704void
706 ScanState *scanstate,
707 const TupleTableSlotOps *tts_ops)
708{
710 TupleDesc tupDesc;
711
712 outerPlan = outerPlanState(scanstate);
713 tupDesc = ExecGetResultType(outerPlan);
714
715 ExecInitScanTupleSlot(estate, scanstate, tupDesc, tts_ops);
716}
717
718/* ----------------------------------------------------------------
719 * ExecRelationIsTargetRelation
720 *
721 * Detect whether a relation (identified by rangetable index)
722 * is one of the target relations of the query.
723 *
724 * Note: This is currently no longer used in core. We keep it around
725 * because FDWs may wish to use it to determine if their foreign table
726 * is a target relation.
727 * ----------------------------------------------------------------
728 */
729bool
731{
732 return list_member_int(estate->es_plannedstmt->resultRelations, scanrelid);
733}
734
735/* ----------------------------------------------------------------
736 * ExecOpenScanRelation
737 *
738 * Open the heap relation to be scanned by a base-level scan plan node.
739 * This should be called during the node's ExecInit routine.
740 * ----------------------------------------------------------------
741 */
743ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
744{
745 Relation rel;
746
747 /* Open the relation. */
748 rel = ExecGetRangeTableRelation(estate, scanrelid);
749
750 /*
751 * Complain if we're attempting a scan of an unscannable relation, except
752 * when the query won't actually be run. This is a slightly klugy place
753 * to do this, perhaps, but there is no better place.
754 */
755 if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 &&
758 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
759 errmsg("materialized view \"%s\" has not been populated",
761 errhint("Use the REFRESH MATERIALIZED VIEW command.")));
762
763 return rel;
764}
765
766/*
767 * ExecInitRangeTable
768 * Set up executor's range-table-related data
769 *
770 * In addition to the range table proper, initialize arrays that are
771 * indexed by rangetable index.
772 */
773void
774ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos,
775 Bitmapset *unpruned_relids)
776{
777 /* Remember the range table List as-is */
778 estate->es_range_table = rangeTable;
779
780 /* ... and the RTEPermissionInfo List too */
781 estate->es_rteperminfos = permInfos;
782
783 /* Set size of associated arrays */
784 estate->es_range_table_size = list_length(rangeTable);
785
786 /*
787 * Initialize the bitmapset of RT indexes (es_unpruned_relids)
788 * representing relations that will be scanned during execution. This set
789 * is initially populated by the caller and may be extended later by
790 * ExecDoInitialPruning() to include RT indexes of unpruned leaf
791 * partitions.
792 */
793 estate->es_unpruned_relids = unpruned_relids;
794
795 /*
796 * Allocate an array to store an open Relation corresponding to each
797 * rangetable entry, and initialize entries to NULL. Relations are opened
798 * and stored here as needed.
799 */
800 estate->es_relations = (Relation *)
801 palloc0(estate->es_range_table_size * sizeof(Relation));
802
803 /*
804 * es_result_relations and es_rowmarks are also parallel to
805 * es_range_table, but are allocated only if needed.
806 */
807 estate->es_result_relations = NULL;
808 estate->es_rowmarks = NULL;
809}
810
811/*
812 * ExecGetRangeTableRelation
813 * Open the Relation for a range table entry, if not already done
814 *
815 * The Relations will be closed in ExecEndPlan().
816 */
819{
820 Relation rel;
821
822 Assert(rti > 0 && rti <= estate->es_range_table_size);
823
824 rel = estate->es_relations[rti - 1];
825 if (rel == NULL)
826 {
827 /* First time through, so open the relation */
828 RangeTblEntry *rte = exec_rt_fetch(rti, estate);
829
830 Assert(rte->rtekind == RTE_RELATION);
831
832 if (!IsParallelWorker())
833 {
834 /*
835 * In a normal query, we should already have the appropriate lock,
836 * but verify that through an Assert. Since there's already an
837 * Assert inside table_open that insists on holding some lock, it
838 * seems sufficient to check this only when rellockmode is higher
839 * than the minimum.
840 */
841 rel = table_open(rte->relid, NoLock);
842 Assert(rte->rellockmode == AccessShareLock ||
843 CheckRelationLockedByMe(rel, rte->rellockmode, false));
844 }
845 else
846 {
847 /*
848 * If we are a parallel worker, we need to obtain our own local
849 * lock on the relation. This ensures sane behavior in case the
850 * parent process exits before we do.
851 */
852 rel = table_open(rte->relid, rte->rellockmode);
853 }
854
855 estate->es_relations[rti - 1] = rel;
856 }
857
858 return rel;
859}
860
861/*
862 * ExecInitResultRelation
863 * Open relation given by the passed-in RT index and fill its
864 * ResultRelInfo node
865 *
866 * Here, we also save the ResultRelInfo in estate->es_result_relations array
867 * such that it can be accessed later using the RT index.
868 */
869void
871 Index rti)
872{
873 Relation resultRelationDesc;
874
875 resultRelationDesc = ExecGetRangeTableRelation(estate, rti);
876 InitResultRelInfo(resultRelInfo,
877 resultRelationDesc,
878 rti,
879 NULL,
880 estate->es_instrument);
881
882 if (estate->es_result_relations == NULL)
884 palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
885 estate->es_result_relations[rti - 1] = resultRelInfo;
886
887 /*
888 * Saving in the list allows to avoid needlessly traversing the whole
889 * array when only a few of its entries are possibly non-NULL.
890 */
892 lappend(estate->es_opened_result_relations, resultRelInfo);
893}
894
895/*
896 * UpdateChangedParamSet
897 * Add changed parameters to a plan node's chgParam set
898 */
899void
901{
902 Bitmapset *parmset;
903
904 /*
905 * The plan node only depends on params listed in its allParam set. Don't
906 * include anything else into its chgParam set.
907 */
908 parmset = bms_intersect(node->plan->allParam, newchg);
909 node->chgParam = bms_join(node->chgParam, parmset);
910}
911
912/*
913 * executor_errposition
914 * Report an execution-time cursor position, if possible.
915 *
916 * This is expected to be used within an ereport() call. The return value
917 * is a dummy (always 0, in fact).
918 *
919 * The locations stored in parsetrees are byte offsets into the source string.
920 * We have to convert them to 1-based character indexes for reporting to
921 * clients. (We do things this way to avoid unnecessary overhead in the
922 * normal non-error case: computing character indexes would be much more
923 * expensive than storing token offsets.)
924 */
925int
926executor_errposition(EState *estate, int location)
927{
928 int pos;
929
930 /* No-op if location was not provided */
931 if (location < 0)
932 return 0;
933 /* Can't do anything if source text is not available */
934 if (estate == NULL || estate->es_sourceText == NULL)
935 return 0;
936 /* Convert offset to character number */
937 pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
938 /* And pass it to the ereport mechanism */
939 return errposition(pos);
940}
941
942/*
943 * Register a shutdown callback in an ExprContext.
944 *
945 * Shutdown callbacks will be called (in reverse order of registration)
946 * when the ExprContext is deleted or rescanned. This provides a hook
947 * for functions called in the context to do any cleanup needed --- it's
948 * particularly useful for functions returning sets. Note that the
949 * callback will *not* be called in the event that execution is aborted
950 * by an error.
951 */
952void
955 Datum arg)
956{
957 ExprContext_CB *ecxt_callback;
958
959 /* Save the info in appropriate memory context */
960 ecxt_callback = (ExprContext_CB *)
962 sizeof(ExprContext_CB));
963
964 ecxt_callback->function = function;
965 ecxt_callback->arg = arg;
966
967 /* link to front of list for appropriate execution order */
968 ecxt_callback->next = econtext->ecxt_callbacks;
969 econtext->ecxt_callbacks = ecxt_callback;
970}
971
972/*
973 * Deregister a shutdown callback in an ExprContext.
974 *
975 * Any list entries matching the function and arg will be removed.
976 * This can be used if it's no longer necessary to call the callback.
977 */
978void
981 Datum arg)
982{
983 ExprContext_CB **prev_callback;
984 ExprContext_CB *ecxt_callback;
985
986 prev_callback = &econtext->ecxt_callbacks;
987
988 while ((ecxt_callback = *prev_callback) != NULL)
989 {
990 if (ecxt_callback->function == function && ecxt_callback->arg == arg)
991 {
992 *prev_callback = ecxt_callback->next;
993 pfree(ecxt_callback);
994 }
995 else
996 prev_callback = &ecxt_callback->next;
997 }
998}
999
1000/*
1001 * Call all the shutdown callbacks registered in an ExprContext.
1002 *
1003 * The callback list is emptied (important in case this is only a rescan
1004 * reset, and not deletion of the ExprContext).
1005 *
1006 * If isCommit is false, just clean the callback list but don't call 'em.
1007 * (See comment for FreeExprContext.)
1008 */
1009static void
1010ShutdownExprContext(ExprContext *econtext, bool isCommit)
1011{
1012 ExprContext_CB *ecxt_callback;
1013 MemoryContext oldcontext;
1014
1015 /* Fast path in normal case where there's nothing to do. */
1016 if (econtext->ecxt_callbacks == NULL)
1017 return;
1018
1019 /*
1020 * Call the callbacks in econtext's per-tuple context. This ensures that
1021 * any memory they might leak will get cleaned up.
1022 */
1023 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
1024
1025 /*
1026 * Call each callback function in reverse registration order.
1027 */
1028 while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
1029 {
1030 econtext->ecxt_callbacks = ecxt_callback->next;
1031 if (isCommit)
1032 ecxt_callback->function(ecxt_callback->arg);
1033 pfree(ecxt_callback);
1034 }
1035
1036 MemoryContextSwitchTo(oldcontext);
1037}
1038
1039/*
1040 * GetAttributeByName
1041 * GetAttributeByNum
1042 *
1043 * These functions return the value of the requested attribute
1044 * out of the given tuple Datum.
1045 * C functions which take a tuple as an argument are expected
1046 * to use these. Ex: overpaid(EMP) might call GetAttributeByNum().
1047 * Note: these are actually rather slow because they do a typcache
1048 * lookup on each call.
1049 */
1050Datum
1051GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
1052{
1053 AttrNumber attrno;
1054 Datum result;
1055 Oid tupType;
1056 int32 tupTypmod;
1057 TupleDesc tupDesc;
1058 HeapTupleData tmptup;
1059 int i;
1060
1061 if (attname == NULL)
1062 elog(ERROR, "invalid attribute name");
1063
1064 if (isNull == NULL)
1065 elog(ERROR, "a NULL isNull pointer was passed");
1066
1067 if (tuple == NULL)
1068 {
1069 /* Kinda bogus but compatible with old behavior... */
1070 *isNull = true;
1071 return (Datum) 0;
1072 }
1073
1074 tupType = HeapTupleHeaderGetTypeId(tuple);
1075 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1076 tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1077
1078 attrno = InvalidAttrNumber;
1079 for (i = 0; i < tupDesc->natts; i++)
1080 {
1081 Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1082
1083 if (namestrcmp(&(att->attname), attname) == 0)
1084 {
1085 attrno = att->attnum;
1086 break;
1087 }
1088 }
1089
1090 if (attrno == InvalidAttrNumber)
1091 elog(ERROR, "attribute \"%s\" does not exist", attname);
1092
1093 /*
1094 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1095 * the fields in the struct just in case user tries to inspect system
1096 * columns.
1097 */
1098 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1099 ItemPointerSetInvalid(&(tmptup.t_self));
1100 tmptup.t_tableOid = InvalidOid;
1101 tmptup.t_data = tuple;
1102
1103 result = heap_getattr(&tmptup,
1104 attrno,
1105 tupDesc,
1106 isNull);
1107
1108 ReleaseTupleDesc(tupDesc);
1109
1110 return result;
1111}
1112
1113Datum
1115 AttrNumber attrno,
1116 bool *isNull)
1117{
1118 Datum result;
1119 Oid tupType;
1120 int32 tupTypmod;
1121 TupleDesc tupDesc;
1122 HeapTupleData tmptup;
1123
1124 if (!AttributeNumberIsValid(attrno))
1125 elog(ERROR, "invalid attribute number %d", attrno);
1126
1127 if (isNull == NULL)
1128 elog(ERROR, "a NULL isNull pointer was passed");
1129
1130 if (tuple == NULL)
1131 {
1132 /* Kinda bogus but compatible with old behavior... */
1133 *isNull = true;
1134 return (Datum) 0;
1135 }
1136
1137 tupType = HeapTupleHeaderGetTypeId(tuple);
1138 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1139 tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1140
1141 /*
1142 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1143 * the fields in the struct just in case user tries to inspect system
1144 * columns.
1145 */
1146 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1147 ItemPointerSetInvalid(&(tmptup.t_self));
1148 tmptup.t_tableOid = InvalidOid;
1149 tmptup.t_data = tuple;
1150
1151 result = heap_getattr(&tmptup,
1152 attrno,
1153 tupDesc,
1154 isNull);
1155
1156 ReleaseTupleDesc(tupDesc);
1157
1158 return result;
1159}
1160
1161/*
1162 * Number of items in a tlist (including any resjunk items!)
1163 */
1164int
1166{
1167 /* This used to be more complex, but fjoins are dead */
1168 return list_length(targetlist);
1169}
1170
1171/*
1172 * Number of items in a tlist, not including any resjunk items
1173 */
1174int
1176{
1177 int len = 0;
1178 ListCell *tl;
1179
1180 foreach(tl, targetlist)
1181 {
1182 TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1183
1184 if (!curTle->resjunk)
1185 len++;
1186 }
1187 return len;
1188}
1189
1190/*
1191 * Return a relInfo's tuple slot for a trigger's OLD tuples.
1192 */
1195{
1196 if (relInfo->ri_TrigOldSlot == NULL)
1197 {
1198 Relation rel = relInfo->ri_RelationDesc;
1199 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1200
1201 relInfo->ri_TrigOldSlot =
1203 RelationGetDescr(rel),
1205
1206 MemoryContextSwitchTo(oldcontext);
1207 }
1208
1209 return relInfo->ri_TrigOldSlot;
1210}
1211
1212/*
1213 * Return a relInfo's tuple slot for a trigger's NEW tuples.
1214 */
1217{
1218 if (relInfo->ri_TrigNewSlot == NULL)
1219 {
1220 Relation rel = relInfo->ri_RelationDesc;
1221 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1222
1223 relInfo->ri_TrigNewSlot =
1225 RelationGetDescr(rel),
1227
1228 MemoryContextSwitchTo(oldcontext);
1229 }
1230
1231 return relInfo->ri_TrigNewSlot;
1232}
1233
1234/*
1235 * Return a relInfo's tuple slot for processing returning tuples.
1236 */
1239{
1240 if (relInfo->ri_ReturningSlot == NULL)
1241 {
1242 Relation rel = relInfo->ri_RelationDesc;
1243 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1244
1245 relInfo->ri_ReturningSlot =
1247 RelationGetDescr(rel),
1249
1250 MemoryContextSwitchTo(oldcontext);
1251 }
1252
1253 return relInfo->ri_ReturningSlot;
1254}
1255
1256/*
1257 * Return a relInfo's all-NULL tuple slot for processing returning tuples.
1258 *
1259 * Note: this slot is intentionally filled with NULLs in every column, and
1260 * should be considered read-only --- the caller must not update it.
1261 */
1264{
1265 if (relInfo->ri_AllNullSlot == NULL)
1266 {
1267 Relation rel = relInfo->ri_RelationDesc;
1268 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1269 TupleTableSlot *slot;
1270
1271 slot = ExecInitExtraTupleSlot(estate,
1272 RelationGetDescr(rel),
1275
1276 relInfo->ri_AllNullSlot = slot;
1277
1278 MemoryContextSwitchTo(oldcontext);
1279 }
1280
1281 return relInfo->ri_AllNullSlot;
1282}
1283
1284/*
1285 * Return the map needed to convert given child result relation's tuples to
1286 * the rowtype of the query's main target ("root") relation. Note that a
1287 * NULL result is valid and means that no conversion is needed.
1288 */
1291{
1292 /* If we didn't already do so, compute the map for this child. */
1293 if (!resultRelInfo->ri_ChildToRootMapValid)
1294 {
1295 ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1296
1297 if (rootRelInfo)
1298 resultRelInfo->ri_ChildToRootMap =
1300 RelationGetDescr(rootRelInfo->ri_RelationDesc));
1301 else /* this isn't a child result rel */
1302 resultRelInfo->ri_ChildToRootMap = NULL;
1303
1304 resultRelInfo->ri_ChildToRootMapValid = true;
1305 }
1306
1307 return resultRelInfo->ri_ChildToRootMap;
1308}
1309
1310/*
1311 * Returns the map needed to convert given root result relation's tuples to
1312 * the rowtype of the given child relation. Note that a NULL result is valid
1313 * and means that no conversion is needed.
1314 */
1317{
1318 /* Mustn't get called for a non-child result relation. */
1319 Assert(resultRelInfo->ri_RootResultRelInfo);
1320
1321 /* If we didn't already do so, compute the map for this child. */
1322 if (!resultRelInfo->ri_RootToChildMapValid)
1323 {
1324 ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1325 TupleDesc indesc = RelationGetDescr(rootRelInfo->ri_RelationDesc);
1326 TupleDesc outdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
1327 Relation childrel = resultRelInfo->ri_RelationDesc;
1328 AttrMap *attrMap;
1329 MemoryContext oldcontext;
1330
1331 /*
1332 * When this child table is not a partition (!relispartition), it may
1333 * have columns that are not present in the root table, which we ask
1334 * to ignore by passing true for missing_ok.
1335 */
1336 oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1337 attrMap = build_attrmap_by_name_if_req(indesc, outdesc,
1338 !childrel->rd_rel->relispartition);
1339 if (attrMap)
1340 resultRelInfo->ri_RootToChildMap =
1341 convert_tuples_by_name_attrmap(indesc, outdesc, attrMap);
1342 MemoryContextSwitchTo(oldcontext);
1343 resultRelInfo->ri_RootToChildMapValid = true;
1344 }
1345
1346 return resultRelInfo->ri_RootToChildMap;
1347}
1348
1349/* Return a bitmap representing columns being inserted */
1350Bitmapset *
1352{
1353 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1354
1355 if (perminfo == NULL)
1356 return NULL;
1357
1358 /* Map the columns to child's attribute numbers if needed. */
1359 if (relinfo->ri_RootResultRelInfo)
1360 {
1361 TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1362
1363 if (map)
1364 return execute_attr_map_cols(map->attrMap, perminfo->insertedCols);
1365 }
1366
1367 return perminfo->insertedCols;
1368}
1369
1370/* Return a bitmap representing columns being updated */
1371Bitmapset *
1373{
1374 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1375
1376 if (perminfo == NULL)
1377 return NULL;
1378
1379 /* Map the columns to child's attribute numbers if needed. */
1380 if (relinfo->ri_RootResultRelInfo)
1381 {
1382 TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1383
1384 if (map)
1385 return execute_attr_map_cols(map->attrMap, perminfo->updatedCols);
1386 }
1387
1388 return perminfo->updatedCols;
1389}
1390
1391/* Return a bitmap representing generated columns being updated */
1392Bitmapset *
1394{
1395 /* Compute the info if we didn't already */
1396 if (!relinfo->ri_extraUpdatedCols_valid)
1397 ExecInitGenerated(relinfo, estate, CMD_UPDATE);
1398 return relinfo->ri_extraUpdatedCols;
1399}
1400
1401/*
1402 * Return columns being updated, including generated columns
1403 *
1404 * The bitmap is allocated in per-tuple memory context. It's up to the caller to
1405 * copy it into a different context with the appropriate lifespan, if needed.
1406 */
1407Bitmapset *
1409{
1410 Bitmapset *ret;
1411 MemoryContext oldcxt;
1412
1414
1415 ret = bms_union(ExecGetUpdatedCols(relinfo, estate),
1416 ExecGetExtraUpdatedCols(relinfo, estate));
1417
1418 MemoryContextSwitchTo(oldcxt);
1419
1420 return ret;
1421}
1422
1423/*
1424 * GetResultRTEPermissionInfo
1425 * Looks up RTEPermissionInfo for ExecGet*Cols() routines
1426 */
1427static RTEPermissionInfo *
1429{
1430 Index rti;
1431 RangeTblEntry *rte;
1432 RTEPermissionInfo *perminfo = NULL;
1433
1434 if (relinfo->ri_RootResultRelInfo)
1435 {
1436 /*
1437 * For inheritance child result relations (a partition routing target
1438 * of an INSERT or a child UPDATE target), this returns the root
1439 * parent's RTE to fetch the RTEPermissionInfo because that's the only
1440 * one that has one assigned.
1441 */
1443 }
1444 else if (relinfo->ri_RangeTableIndex != 0)
1445 {
1446 /*
1447 * Non-child result relation should have their own RTEPermissionInfo.
1448 */
1449 rti = relinfo->ri_RangeTableIndex;
1450 }
1451 else
1452 {
1453 /*
1454 * The relation isn't in the range table and it isn't a partition
1455 * routing target. This ResultRelInfo must've been created only for
1456 * firing triggers and the relation is not being inserted into. (See
1457 * ExecGetTriggerResultRel.)
1458 */
1459 rti = 0;
1460 }
1461
1462 if (rti > 0)
1463 {
1464 rte = exec_rt_fetch(rti, estate);
1465 perminfo = getRTEPermissionInfo(estate->es_rteperminfos, rte);
1466 }
1467
1468 return perminfo;
1469}
1470
1471/*
1472 * ExecGetResultRelCheckAsUser
1473 * Returns the user to modify passed-in result relation as
1474 *
1475 * The user is chosen by looking up the relation's or, if a child table, its
1476 * root parent's RTEPermissionInfo.
1477 */
1478Oid
1480{
1481 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relInfo, estate);
1482
1483 /* XXX - maybe ok to return GetUserId() in this case? */
1484 if (perminfo == NULL)
1485 elog(ERROR, "no RTEPermissionInfo found for result relation with OID %u",
1487
1488 return perminfo->checkAsUser ? perminfo->checkAsUser : GetUserId();
1489}
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
Definition: attmap.c:263
int16 AttrNumber
Definition: attnum.h:21
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
#define InvalidAttrNumber
Definition: attnum.h:23
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:292
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:251
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Definition: bitmapset.c:1230
#define Assert(condition)
Definition: c.h:815
int32_t int32
Definition: c.h:484
unsigned int Index
Definition: c.h:571
uint32 CommandId
Definition: c.h:623
size_t Size
Definition: c.h:562
int errhint(const char *fmt,...)
Definition: elog.c:1317
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
int errposition(int cursorpos)
Definition: elog.c:1446
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:370
void InitResultRelInfo(ResultRelInfo *resultRelInfo, Relation resultRelationDesc, Index resultRelationIndex, ResultRelInfo *partition_root_rri, int instrument_options)
Definition: execMain.c:1222
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1966
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1998
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:2018
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1476
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:1763
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:496
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition: execUtils.c:1316
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1393
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:1010
Bitmapset * ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1351
TupleTableSlot * ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1216
void ReScanExprContext(ExprContext *econtext)
Definition: execUtils.c:444
ExprContext * CreateExprContext(EState *estate)
Definition: execUtils.c:307
static RTEPermissionInfo * GetResultRTEPermissionInfo(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1428
TupleConversionMap * ExecGetChildToRootMap(ResultRelInfo *resultRelInfo)
Definition: execUtils.c:1290
ExprContext * CreateStandaloneExprContext(void)
Definition: execUtils.c:358
TupleTableSlot * ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1194
int executor_errposition(EState *estate, int location)
Definition: execUtils.c:926
Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno, bool *isNull)
Definition: execUtils.c:1114
void FreeExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:417
void ExecInitRangeTable(EState *estate, List *rangeTable, List *permInfos, Bitmapset *unpruned_relids)
Definition: execUtils.c:774
static bool tlist_matches_tupdesc(PlanState *ps, List *tlist, int varno, TupleDesc tupdesc)
Definition: execUtils.c:631
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1372
const TupleTableSlotOps * ExecGetCommonSlotOps(PlanState **planstates, int nplans)
Definition: execUtils.c:537
void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo, Index rti)
Definition: execUtils.c:870
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:705
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
Relation ExecGetRangeTableRelation(EState *estate, Index rti)
Definition: execUtils.c:818
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:584
ExprContext * MakePerTupleExprContext(EState *estate)
Definition: execUtils.c:459
void UnregisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
Definition: execUtils.c:979
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:693
const TupleTableSlotOps * ExecGetCommonChildSlotOps(PlanState *ps)
Definition: execUtils.c:564
void ExecConditionalAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc, int varno)
Definition: execUtils.c:604
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
Definition: execUtils.c:953
int ExecTargetListLength(List *targetlist)
Definition: execUtils.c:1165
void FreeExecutorState(EState *estate)
Definition: execUtils.c:192
bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid)
Definition: execUtils.c:730
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:237
TupleTableSlot * ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1263
int ExecCleanTargetListLength(List *targetlist)
Definition: execUtils.c:1175
ExprContext * CreateWorkExprContext(EState *estate)
Definition: execUtils.c:322
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:900
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:505
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:1051
Bitmapset * ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1408
TupleTableSlot * ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1238
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:743
Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate)
Definition: execUtils.c:1479
EState * CreateExecutorState(void)
Definition: execUtils.c:88
void(* ExprContextCallbackFunction)(Datum arg)
Definition: execnodes.h:229
#define outerPlanState(node)
Definition: execnodes.h:1246
#define innerPlanState(node)
Definition: execnodes.h:1245
#define EXEC_FLAG_WITH_NO_DATA
Definition: executor.h:71
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:604
#define GetPerTupleMemoryContext(estate)
Definition: executor.h:568
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:65
int work_mem
Definition: globals.c:130
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:903
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
Definition: htup_details.h:516
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
Definition: htup_details.h:492
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
Definition: htup_details.h:504
#define IsParallelWorker()
Definition: parallel.h:60
struct parser_state ps
int i
Definition: isn.c:72
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
void jit_release_context(JitContext *context)
Definition: jit.c:137
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:872
List * lappend(List *list, void *datum)
Definition: list.c:339
List * lcons(void *datum, List *list)
Definition: list.c:495
bool list_member_int(const List *list, int datum)
Definition: list.c:702
bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:329
#define NoLock
Definition: lockdefs.h:34
#define AccessShareLock
Definition: lockdefs.h:36
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1057
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1181
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc0(Size size)
Definition: mcxt.c:1347
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_MAXSIZE
Definition: memutils.h:159
#define ALLOCSET_DEFAULT_MINSIZE
Definition: memutils.h:157
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
#define ALLOCSET_DEFAULT_INITSIZE
Definition: memutils.h:158
Oid GetUserId(void)
Definition: miscinit.c:517
int namestrcmp(Name name, const char *str)
Definition: name.c:247
void ExecInitGenerated(ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
@ CMD_UPDATE
Definition: nodes.h:266
#define makeNode(_type_)
Definition: nodes.h:155
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
@ RTE_RELATION
Definition: parsenodes.h:1026
void DestroyPartitionDirectory(PartitionDirectory pdir)
Definition: partdesc.c:484
NameData attname
Definition: pg_attribute.h:41
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
on_exit_nicely_callback function
void * arg
const void size_t len
#define lfirst(lc)
Definition: pg_list.h:172
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define linitial(l)
Definition: pg_list.h:178
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
#define outerPlan(node)
Definition: plannodes.h:231
uintptr_t Datum
Definition: postgres.h:69
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetRelid(relation)
Definition: rel.h:512
#define RelationIsScannable(relation)
Definition: rel.h:676
#define RelationGetDescr(relation)
Definition: rel.h:538
#define RelationGetRelationName(relation)
Definition: rel.h:546
@ ForwardScanDirection
Definition: sdir.h:28
#define InvalidSnapshot
Definition: snapshot.h:119
Definition: attmap.h:35
uint64 es_processed
Definition: execnodes.h:704
List * es_part_prune_infos
Definition: execnodes.h:660
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:656
int es_parallel_workers_to_launch
Definition: execnodes.h:736
List * es_tuple_routing_result_relations
Definition: execnodes.h:688
int es_top_eflags
Definition: execnodes.h:709
struct JitContext * es_jit
Definition: execnodes.h:754
int es_instrument
Definition: execnodes.h:710
PlannedStmt * es_plannedstmt
Definition: execnodes.h:659
QueryEnvironment * es_queryEnv
Definition: execnodes.h:697
ResultRelInfo ** es_result_relations
Definition: execnodes.h:675
ParamExecData * es_param_exec_vals
Definition: execnodes.h:695
uint64 es_total_processed
Definition: execnodes.h:706
List * es_range_table
Definition: execnodes.h:652
List * es_rteperminfos
Definition: execnodes.h:658
Bitmapset * es_unpruned_relids
Definition: execnodes.h:663
List * es_exprcontexts
Definition: execnodes.h:713
ParamListInfo es_param_list_info
Definition: execnodes.h:694
bool es_finished
Definition: execnodes.h:711
List * es_insert_pending_result_relations
Definition: execnodes.h:761
MemoryContext es_query_cxt
Definition: execnodes.h:700
List * es_tupleTable
Definition: execnodes.h:702
ScanDirection es_direction
Definition: execnodes.h:649
PartitionDirectory es_partition_directory
Definition: execnodes.h:682
List * es_trig_target_relations
Definition: execnodes.h:691
int es_jit_flags
Definition: execnodes.h:753
List * es_opened_result_relations
Definition: execnodes.h:678
bool es_use_parallel_mode
Definition: execnodes.h:734
Relation * es_relations
Definition: execnodes.h:654
List * es_subplanstates
Definition: execnodes.h:715
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:724
int es_parallel_workers_launched
Definition: execnodes.h:738
CommandId es_output_cid
Definition: execnodes.h:672
Index es_range_table_size
Definition: execnodes.h:653
List * es_insert_pending_modifytables
Definition: execnodes.h:762
const char * es_sourceText
Definition: execnodes.h:667
Snapshot es_snapshot
Definition: execnodes.h:650
List * es_auxmodifytables
Definition: execnodes.h:717
JunkFilter * es_junkFilter
Definition: execnodes.h:669
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:651
struct ExprContext_CB * next
Definition: execnodes.h:233
ExprContextCallbackFunction function
Definition: execnodes.h:234
Datum domainValue_datum
Definition: execnodes.h:298
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:279
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:275
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:269
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:278
Datum * ecxt_aggvalues
Definition: execnodes.h:286
bool caseValue_isNull
Definition: execnodes.h:294
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:267
Datum caseValue_datum
Definition: execnodes.h:292
bool * ecxt_aggnulls
Definition: execnodes.h:288
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:274
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:312
bool domainValue_isNull
Definition: execnodes.h:300
struct EState * ecxt_estate
Definition: execnodes.h:309
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:271
ItemPointerData t_self
Definition: htup.h:65
uint32 t_len
Definition: htup.h:64
HeapTupleHeader t_data
Definition: htup.h:68
Oid t_tableOid
Definition: htup.h:66
Definition: pg_list.h:54
const TupleTableSlotOps * resultops
Definition: execnodes.h:1227
bool resultopsset
Definition: execnodes.h:1235
const TupleTableSlotOps * scanops
Definition: execnodes.h:1224
Plan * plan
Definition: execnodes.h:1150
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1187
Bitmapset * chgParam
Definition: execnodes.h:1182
bool scanopsset
Definition: execnodes.h:1232
ExprContext * ps_ExprContext
Definition: execnodes.h:1189
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1188
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1190
bool scanopsfixed
Definition: execnodes.h:1228
bool resultopsfixed
Definition: execnodes.h:1231
Bitmapset * allParam
Definition: plannodes.h:220
List * targetlist
Definition: plannodes.h:199
List * resultRelations
Definition: plannodes.h:103
Bitmapset * insertedCols
Definition: parsenodes.h:1303
Bitmapset * updatedCols
Definition: parsenodes.h:1304
RTEKind rtekind
Definition: parsenodes.h:1056
Form_pg_class rd_rel
Definition: rel.h:111
TupleConversionMap * ri_RootToChildMap
Definition: execnodes.h:594
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:608
Relation ri_RelationDesc
Definition: execnodes.h:474
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:521
bool ri_extraUpdatedCols_valid
Definition: execnodes.h:494
bool ri_RootToChildMapValid
Definition: execnodes.h:595
TupleTableSlot * ri_AllNullSlot
Definition: execnodes.h:524
Bitmapset * ri_extraUpdatedCols
Definition: execnodes.h:492
Index ri_RangeTableIndex
Definition: execnodes.h:471
TupleConversionMap * ri_ChildToRootMap
Definition: execnodes.h:588
bool ri_ChildToRootMapValid
Definition: execnodes.h:589
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:523
TupleTableSlot * ri_TrigOldSlot
Definition: execnodes.h:522
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1606
AttrMap * attrMap
Definition: tupconvert.h:28
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:121
Definition: primnodes.h:262
AttrNumber varattno
Definition: primnodes.h:274
int varno
Definition: primnodes.h:269
Index varlevelsup
Definition: primnodes.h:294
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
TupleConversionMap * convert_tuples_by_name_attrmap(TupleDesc indesc, TupleDesc outdesc, AttrMap *attrMap)
Definition: tupconvert.c:124
Bitmapset * execute_attr_map_cols(AttrMap *attrMap, Bitmapset *in_cols)
Definition: tupconvert.c:252
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:213
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:154
#define TTS_FIXED(slot)
Definition: tuptable.h:108
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1920