PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 estate->es_aborted = false;
151
152 estate->es_exprcontexts = NIL;
153
154 estate->es_subplanstates = NIL;
155
156 estate->es_auxmodifytables = NIL;
157
158 estate->es_per_tuple_exprcontext = NULL;
159
160 estate->es_sourceText = NULL;
161
162 estate->es_use_parallel_mode = false;
165
166 estate->es_jit_flags = 0;
167 estate->es_jit = NULL;
168
169 /*
170 * Return the executor state structure
171 */
172 MemoryContextSwitchTo(oldcontext);
173
174 return estate;
175}
176
177/* ----------------
178 * FreeExecutorState
179 *
180 * Release an EState along with all remaining working storage.
181 *
182 * Note: this is not responsible for releasing non-memory resources, such as
183 * open relations or buffer pins. But it will shut down any still-active
184 * ExprContexts within the EState and deallocate associated JITed expressions.
185 * That is sufficient cleanup for situations where the EState has only been
186 * used for expression evaluation, and not to run a complete Plan.
187 *
188 * This can be called in any memory context ... so long as it's not one
189 * of the ones to be freed.
190 * ----------------
191 */
192void
194{
195 /*
196 * Shut down and free any remaining ExprContexts. We do this explicitly
197 * to ensure that any remaining shutdown callbacks get called (since they
198 * might need to release resources that aren't simply memory within the
199 * per-query memory context).
200 */
201 while (estate->es_exprcontexts)
202 {
203 /*
204 * XXX: seems there ought to be a faster way to implement this than
205 * repeated list_delete(), no?
206 */
208 true);
209 /* FreeExprContext removed the list link for us */
210 }
211
212 /* release JIT context, if allocated */
213 if (estate->es_jit)
214 {
216 estate->es_jit = NULL;
217 }
218
219 /* release partition directory, if allocated */
220 if (estate->es_partition_directory)
221 {
223 estate->es_partition_directory = NULL;
224 }
225
226 /*
227 * Free the per-query memory context, thereby releasing all working
228 * memory, including the EState node itself.
229 */
231}
232
233/*
234 * Internal implementation for CreateExprContext() and CreateWorkExprContext()
235 * that allows control over the AllocSet parameters.
236 */
237static ExprContext *
238CreateExprContextInternal(EState *estate, Size minContextSize,
239 Size initBlockSize, Size maxBlockSize)
240{
241 ExprContext *econtext;
242 MemoryContext oldcontext;
243
244 /* Create the ExprContext node within the per-query memory context */
245 oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
246
247 econtext = makeNode(ExprContext);
248
249 /* Initialize fields of ExprContext */
250 econtext->ecxt_scantuple = NULL;
251 econtext->ecxt_innertuple = NULL;
252 econtext->ecxt_outertuple = NULL;
253
254 econtext->ecxt_per_query_memory = estate->es_query_cxt;
255
256 /*
257 * Create working memory for expression evaluation in this context.
258 */
259 econtext->ecxt_per_tuple_memory =
261 "ExprContext",
262 minContextSize,
263 initBlockSize,
264 maxBlockSize);
265
266 econtext->ecxt_param_exec_vals = estate->es_param_exec_vals;
267 econtext->ecxt_param_list_info = estate->es_param_list_info;
268
269 econtext->ecxt_aggvalues = NULL;
270 econtext->ecxt_aggnulls = NULL;
271
272 econtext->caseValue_datum = (Datum) 0;
273 econtext->caseValue_isNull = true;
274
275 econtext->domainValue_datum = (Datum) 0;
276 econtext->domainValue_isNull = true;
277
278 econtext->ecxt_estate = estate;
279
280 econtext->ecxt_callbacks = NULL;
281
282 /*
283 * Link the ExprContext into the EState to ensure it is shut down when the
284 * EState is freed. Because we use lcons(), shutdowns will occur in
285 * reverse order of creation, which may not be essential but can't hurt.
286 */
287 estate->es_exprcontexts = lcons(econtext, estate->es_exprcontexts);
288
289 MemoryContextSwitchTo(oldcontext);
290
291 return econtext;
292}
293
294/* ----------------
295 * CreateExprContext
296 *
297 * Create a context for expression evaluation within an EState.
298 *
299 * An executor run may require multiple ExprContexts (we usually make one
300 * for each Plan node, and a separate one for per-output-tuple processing
301 * such as constraint checking). Each ExprContext has its own "per-tuple"
302 * memory context.
303 *
304 * Note we make no assumption about the caller's memory context.
305 * ----------------
306 */
309{
311}
312
313
314/* ----------------
315 * CreateWorkExprContext
316 *
317 * Like CreateExprContext, but specifies the AllocSet sizes to be reasonable
318 * in proportion to work_mem. If the maximum block allocation size is too
319 * large, it's easy to skip right past work_mem with a single allocation.
320 * ----------------
321 */
324{
325 Size maxBlockSize = ALLOCSET_DEFAULT_MAXSIZE;
326
327 maxBlockSize = pg_prevpower2_size_t(work_mem * (Size) 1024 / 16);
328
329 /* But no bigger than ALLOCSET_DEFAULT_MAXSIZE */
330 maxBlockSize = Min(maxBlockSize, ALLOCSET_DEFAULT_MAXSIZE);
331
332 /* and no smaller than ALLOCSET_DEFAULT_INITSIZE */
333 maxBlockSize = Max(maxBlockSize, ALLOCSET_DEFAULT_INITSIZE);
334
336 ALLOCSET_DEFAULT_INITSIZE, 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, false);
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 *
817 * If isResultRel is true, the relation is being used as a result relation.
818 * Such a relation might have been pruned, which is OK for result relations,
819 * but not for scan relations; see the details in ExecInitModifyTable(). If
820 * isResultRel is false, the caller must ensure that 'rti' refers to an
821 * unpruned relation (i.e., it is a member of estate->es_unpruned_relids)
822 * before calling this function. Attempting to open a pruned relation for
823 * scanning will result in an error.
824 */
826ExecGetRangeTableRelation(EState *estate, Index rti, bool isResultRel)
827{
828 Relation rel;
829
830 Assert(rti > 0 && rti <= estate->es_range_table_size);
831
832 if (!isResultRel && !bms_is_member(rti, estate->es_unpruned_relids))
833 elog(ERROR, "trying to open a pruned relation");
834
835 rel = estate->es_relations[rti - 1];
836 if (rel == NULL)
837 {
838 /* First time through, so open the relation */
839 RangeTblEntry *rte = exec_rt_fetch(rti, estate);
840
841 Assert(rte->rtekind == RTE_RELATION);
842
843 if (!IsParallelWorker())
844 {
845 /*
846 * In a normal query, we should already have the appropriate lock,
847 * but verify that through an Assert. Since there's already an
848 * Assert inside table_open that insists on holding some lock, it
849 * seems sufficient to check this only when rellockmode is higher
850 * than the minimum.
851 */
852 rel = table_open(rte->relid, NoLock);
853 Assert(rte->rellockmode == AccessShareLock ||
854 CheckRelationLockedByMe(rel, rte->rellockmode, false));
855 }
856 else
857 {
858 /*
859 * If we are a parallel worker, we need to obtain our own local
860 * lock on the relation. This ensures sane behavior in case the
861 * parent process exits before we do.
862 */
863 rel = table_open(rte->relid, rte->rellockmode);
864 }
865
866 estate->es_relations[rti - 1] = rel;
867 }
868
869 return rel;
870}
871
872/*
873 * ExecInitResultRelation
874 * Open relation given by the passed-in RT index and fill its
875 * ResultRelInfo node
876 *
877 * Here, we also save the ResultRelInfo in estate->es_result_relations array
878 * such that it can be accessed later using the RT index.
879 */
880void
882 Index rti)
883{
884 Relation resultRelationDesc;
885
886 resultRelationDesc = ExecGetRangeTableRelation(estate, rti, true);
887 InitResultRelInfo(resultRelInfo,
888 resultRelationDesc,
889 rti,
890 NULL,
891 estate->es_instrument);
892
893 if (estate->es_result_relations == NULL)
895 palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *));
896 estate->es_result_relations[rti - 1] = resultRelInfo;
897
898 /*
899 * Saving in the list allows to avoid needlessly traversing the whole
900 * array when only a few of its entries are possibly non-NULL.
901 */
903 lappend(estate->es_opened_result_relations, resultRelInfo);
904}
905
906/*
907 * UpdateChangedParamSet
908 * Add changed parameters to a plan node's chgParam set
909 */
910void
912{
913 Bitmapset *parmset;
914
915 /*
916 * The plan node only depends on params listed in its allParam set. Don't
917 * include anything else into its chgParam set.
918 */
919 parmset = bms_intersect(node->plan->allParam, newchg);
920 node->chgParam = bms_join(node->chgParam, parmset);
921}
922
923/*
924 * executor_errposition
925 * Report an execution-time cursor position, if possible.
926 *
927 * This is expected to be used within an ereport() call. The return value
928 * is a dummy (always 0, in fact).
929 *
930 * The locations stored in parsetrees are byte offsets into the source string.
931 * We have to convert them to 1-based character indexes for reporting to
932 * clients. (We do things this way to avoid unnecessary overhead in the
933 * normal non-error case: computing character indexes would be much more
934 * expensive than storing token offsets.)
935 */
936int
937executor_errposition(EState *estate, int location)
938{
939 int pos;
940
941 /* No-op if location was not provided */
942 if (location < 0)
943 return 0;
944 /* Can't do anything if source text is not available */
945 if (estate == NULL || estate->es_sourceText == NULL)
946 return 0;
947 /* Convert offset to character number */
948 pos = pg_mbstrlen_with_len(estate->es_sourceText, location) + 1;
949 /* And pass it to the ereport mechanism */
950 return errposition(pos);
951}
952
953/*
954 * Register a shutdown callback in an ExprContext.
955 *
956 * Shutdown callbacks will be called (in reverse order of registration)
957 * when the ExprContext is deleted or rescanned. This provides a hook
958 * for functions called in the context to do any cleanup needed --- it's
959 * particularly useful for functions returning sets. Note that the
960 * callback will *not* be called in the event that execution is aborted
961 * by an error.
962 */
963void
966 Datum arg)
967{
968 ExprContext_CB *ecxt_callback;
969
970 /* Save the info in appropriate memory context */
971 ecxt_callback = (ExprContext_CB *)
973 sizeof(ExprContext_CB));
974
975 ecxt_callback->function = function;
976 ecxt_callback->arg = arg;
977
978 /* link to front of list for appropriate execution order */
979 ecxt_callback->next = econtext->ecxt_callbacks;
980 econtext->ecxt_callbacks = ecxt_callback;
981}
982
983/*
984 * Deregister a shutdown callback in an ExprContext.
985 *
986 * Any list entries matching the function and arg will be removed.
987 * This can be used if it's no longer necessary to call the callback.
988 */
989void
992 Datum arg)
993{
994 ExprContext_CB **prev_callback;
995 ExprContext_CB *ecxt_callback;
996
997 prev_callback = &econtext->ecxt_callbacks;
998
999 while ((ecxt_callback = *prev_callback) != NULL)
1000 {
1001 if (ecxt_callback->function == function && ecxt_callback->arg == arg)
1002 {
1003 *prev_callback = ecxt_callback->next;
1004 pfree(ecxt_callback);
1005 }
1006 else
1007 prev_callback = &ecxt_callback->next;
1008 }
1009}
1010
1011/*
1012 * Call all the shutdown callbacks registered in an ExprContext.
1013 *
1014 * The callback list is emptied (important in case this is only a rescan
1015 * reset, and not deletion of the ExprContext).
1016 *
1017 * If isCommit is false, just clean the callback list but don't call 'em.
1018 * (See comment for FreeExprContext.)
1019 */
1020static void
1021ShutdownExprContext(ExprContext *econtext, bool isCommit)
1022{
1023 ExprContext_CB *ecxt_callback;
1024 MemoryContext oldcontext;
1025
1026 /* Fast path in normal case where there's nothing to do. */
1027 if (econtext->ecxt_callbacks == NULL)
1028 return;
1029
1030 /*
1031 * Call the callbacks in econtext's per-tuple context. This ensures that
1032 * any memory they might leak will get cleaned up.
1033 */
1034 oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
1035
1036 /*
1037 * Call each callback function in reverse registration order.
1038 */
1039 while ((ecxt_callback = econtext->ecxt_callbacks) != NULL)
1040 {
1041 econtext->ecxt_callbacks = ecxt_callback->next;
1042 if (isCommit)
1043 ecxt_callback->function(ecxt_callback->arg);
1044 pfree(ecxt_callback);
1045 }
1046
1047 MemoryContextSwitchTo(oldcontext);
1048}
1049
1050/*
1051 * GetAttributeByName
1052 * GetAttributeByNum
1053 *
1054 * These functions return the value of the requested attribute
1055 * out of the given tuple Datum.
1056 * C functions which take a tuple as an argument are expected
1057 * to use these. Ex: overpaid(EMP) might call GetAttributeByNum().
1058 * Note: these are actually rather slow because they do a typcache
1059 * lookup on each call.
1060 */
1061Datum
1062GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
1063{
1064 AttrNumber attrno;
1065 Datum result;
1066 Oid tupType;
1067 int32 tupTypmod;
1068 TupleDesc tupDesc;
1069 HeapTupleData tmptup;
1070 int i;
1071
1072 if (attname == NULL)
1073 elog(ERROR, "invalid attribute name");
1074
1075 if (isNull == NULL)
1076 elog(ERROR, "a NULL isNull pointer was passed");
1077
1078 if (tuple == NULL)
1079 {
1080 /* Kinda bogus but compatible with old behavior... */
1081 *isNull = true;
1082 return (Datum) 0;
1083 }
1084
1085 tupType = HeapTupleHeaderGetTypeId(tuple);
1086 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1087 tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1088
1089 attrno = InvalidAttrNumber;
1090 for (i = 0; i < tupDesc->natts; i++)
1091 {
1092 Form_pg_attribute att = TupleDescAttr(tupDesc, i);
1093
1094 if (namestrcmp(&(att->attname), attname) == 0)
1095 {
1096 attrno = att->attnum;
1097 break;
1098 }
1099 }
1100
1101 if (attrno == InvalidAttrNumber)
1102 elog(ERROR, "attribute \"%s\" does not exist", attname);
1103
1104 /*
1105 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1106 * the fields in the struct just in case user tries to inspect system
1107 * columns.
1108 */
1109 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1110 ItemPointerSetInvalid(&(tmptup.t_self));
1111 tmptup.t_tableOid = InvalidOid;
1112 tmptup.t_data = tuple;
1113
1114 result = heap_getattr(&tmptup,
1115 attrno,
1116 tupDesc,
1117 isNull);
1118
1119 ReleaseTupleDesc(tupDesc);
1120
1121 return result;
1122}
1123
1124Datum
1126 AttrNumber attrno,
1127 bool *isNull)
1128{
1129 Datum result;
1130 Oid tupType;
1131 int32 tupTypmod;
1132 TupleDesc tupDesc;
1133 HeapTupleData tmptup;
1134
1135 if (!AttributeNumberIsValid(attrno))
1136 elog(ERROR, "invalid attribute number %d", attrno);
1137
1138 if (isNull == NULL)
1139 elog(ERROR, "a NULL isNull pointer was passed");
1140
1141 if (tuple == NULL)
1142 {
1143 /* Kinda bogus but compatible with old behavior... */
1144 *isNull = true;
1145 return (Datum) 0;
1146 }
1147
1148 tupType = HeapTupleHeaderGetTypeId(tuple);
1149 tupTypmod = HeapTupleHeaderGetTypMod(tuple);
1150 tupDesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
1151
1152 /*
1153 * heap_getattr needs a HeapTuple not a bare HeapTupleHeader. We set all
1154 * the fields in the struct just in case user tries to inspect system
1155 * columns.
1156 */
1157 tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
1158 ItemPointerSetInvalid(&(tmptup.t_self));
1159 tmptup.t_tableOid = InvalidOid;
1160 tmptup.t_data = tuple;
1161
1162 result = heap_getattr(&tmptup,
1163 attrno,
1164 tupDesc,
1165 isNull);
1166
1167 ReleaseTupleDesc(tupDesc);
1168
1169 return result;
1170}
1171
1172/*
1173 * Number of items in a tlist (including any resjunk items!)
1174 */
1175int
1177{
1178 /* This used to be more complex, but fjoins are dead */
1179 return list_length(targetlist);
1180}
1181
1182/*
1183 * Number of items in a tlist, not including any resjunk items
1184 */
1185int
1187{
1188 int len = 0;
1189 ListCell *tl;
1190
1191 foreach(tl, targetlist)
1192 {
1193 TargetEntry *curTle = lfirst_node(TargetEntry, tl);
1194
1195 if (!curTle->resjunk)
1196 len++;
1197 }
1198 return len;
1199}
1200
1201/*
1202 * Return a relInfo's tuple slot for a trigger's OLD tuples.
1203 */
1206{
1207 if (relInfo->ri_TrigOldSlot == NULL)
1208 {
1209 Relation rel = relInfo->ri_RelationDesc;
1210 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1211
1212 relInfo->ri_TrigOldSlot =
1214 RelationGetDescr(rel),
1216
1217 MemoryContextSwitchTo(oldcontext);
1218 }
1219
1220 return relInfo->ri_TrigOldSlot;
1221}
1222
1223/*
1224 * Return a relInfo's tuple slot for a trigger's NEW tuples.
1225 */
1228{
1229 if (relInfo->ri_TrigNewSlot == NULL)
1230 {
1231 Relation rel = relInfo->ri_RelationDesc;
1232 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1233
1234 relInfo->ri_TrigNewSlot =
1236 RelationGetDescr(rel),
1238
1239 MemoryContextSwitchTo(oldcontext);
1240 }
1241
1242 return relInfo->ri_TrigNewSlot;
1243}
1244
1245/*
1246 * Return a relInfo's tuple slot for processing returning tuples.
1247 */
1250{
1251 if (relInfo->ri_ReturningSlot == NULL)
1252 {
1253 Relation rel = relInfo->ri_RelationDesc;
1254 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1255
1256 relInfo->ri_ReturningSlot =
1258 RelationGetDescr(rel),
1260
1261 MemoryContextSwitchTo(oldcontext);
1262 }
1263
1264 return relInfo->ri_ReturningSlot;
1265}
1266
1267/*
1268 * Return a relInfo's all-NULL tuple slot for processing returning tuples.
1269 *
1270 * Note: this slot is intentionally filled with NULLs in every column, and
1271 * should be considered read-only --- the caller must not update it.
1272 */
1275{
1276 if (relInfo->ri_AllNullSlot == NULL)
1277 {
1278 Relation rel = relInfo->ri_RelationDesc;
1279 MemoryContext oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1280 TupleTableSlot *slot;
1281
1282 slot = ExecInitExtraTupleSlot(estate,
1283 RelationGetDescr(rel),
1286
1287 relInfo->ri_AllNullSlot = slot;
1288
1289 MemoryContextSwitchTo(oldcontext);
1290 }
1291
1292 return relInfo->ri_AllNullSlot;
1293}
1294
1295/*
1296 * Return the map needed to convert given child result relation's tuples to
1297 * the rowtype of the query's main target ("root") relation. Note that a
1298 * NULL result is valid and means that no conversion is needed.
1299 */
1302{
1303 /* If we didn't already do so, compute the map for this child. */
1304 if (!resultRelInfo->ri_ChildToRootMapValid)
1305 {
1306 ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1307
1308 if (rootRelInfo)
1309 resultRelInfo->ri_ChildToRootMap =
1311 RelationGetDescr(rootRelInfo->ri_RelationDesc));
1312 else /* this isn't a child result rel */
1313 resultRelInfo->ri_ChildToRootMap = NULL;
1314
1315 resultRelInfo->ri_ChildToRootMapValid = true;
1316 }
1317
1318 return resultRelInfo->ri_ChildToRootMap;
1319}
1320
1321/*
1322 * Returns the map needed to convert given root result relation's tuples to
1323 * the rowtype of the given child relation. Note that a NULL result is valid
1324 * and means that no conversion is needed.
1325 */
1328{
1329 /* Mustn't get called for a non-child result relation. */
1330 Assert(resultRelInfo->ri_RootResultRelInfo);
1331
1332 /* If we didn't already do so, compute the map for this child. */
1333 if (!resultRelInfo->ri_RootToChildMapValid)
1334 {
1335 ResultRelInfo *rootRelInfo = resultRelInfo->ri_RootResultRelInfo;
1336 TupleDesc indesc = RelationGetDescr(rootRelInfo->ri_RelationDesc);
1337 TupleDesc outdesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
1338 Relation childrel = resultRelInfo->ri_RelationDesc;
1339 AttrMap *attrMap;
1340 MemoryContext oldcontext;
1341
1342 /*
1343 * When this child table is not a partition (!relispartition), it may
1344 * have columns that are not present in the root table, which we ask
1345 * to ignore by passing true for missing_ok.
1346 */
1347 oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
1348 attrMap = build_attrmap_by_name_if_req(indesc, outdesc,
1349 !childrel->rd_rel->relispartition);
1350 if (attrMap)
1351 resultRelInfo->ri_RootToChildMap =
1352 convert_tuples_by_name_attrmap(indesc, outdesc, attrMap);
1353 MemoryContextSwitchTo(oldcontext);
1354 resultRelInfo->ri_RootToChildMapValid = true;
1355 }
1356
1357 return resultRelInfo->ri_RootToChildMap;
1358}
1359
1360/* Return a bitmap representing columns being inserted */
1361Bitmapset *
1363{
1364 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1365
1366 if (perminfo == NULL)
1367 return NULL;
1368
1369 /* Map the columns to child's attribute numbers if needed. */
1370 if (relinfo->ri_RootResultRelInfo)
1371 {
1372 TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1373
1374 if (map)
1375 return execute_attr_map_cols(map->attrMap, perminfo->insertedCols);
1376 }
1377
1378 return perminfo->insertedCols;
1379}
1380
1381/* Return a bitmap representing columns being updated */
1382Bitmapset *
1384{
1385 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relinfo, estate);
1386
1387 if (perminfo == NULL)
1388 return NULL;
1389
1390 /* Map the columns to child's attribute numbers if needed. */
1391 if (relinfo->ri_RootResultRelInfo)
1392 {
1393 TupleConversionMap *map = ExecGetRootToChildMap(relinfo, estate);
1394
1395 if (map)
1396 return execute_attr_map_cols(map->attrMap, perminfo->updatedCols);
1397 }
1398
1399 return perminfo->updatedCols;
1400}
1401
1402/* Return a bitmap representing generated columns being updated */
1403Bitmapset *
1405{
1406 /* Compute the info if we didn't already */
1407 if (!relinfo->ri_extraUpdatedCols_valid)
1408 ExecInitGenerated(relinfo, estate, CMD_UPDATE);
1409 return relinfo->ri_extraUpdatedCols;
1410}
1411
1412/*
1413 * Return columns being updated, including generated columns
1414 *
1415 * The bitmap is allocated in per-tuple memory context. It's up to the caller to
1416 * copy it into a different context with the appropriate lifespan, if needed.
1417 */
1418Bitmapset *
1420{
1421 Bitmapset *ret;
1422 MemoryContext oldcxt;
1423
1425
1426 ret = bms_union(ExecGetUpdatedCols(relinfo, estate),
1427 ExecGetExtraUpdatedCols(relinfo, estate));
1428
1429 MemoryContextSwitchTo(oldcxt);
1430
1431 return ret;
1432}
1433
1434/*
1435 * GetResultRTEPermissionInfo
1436 * Looks up RTEPermissionInfo for ExecGet*Cols() routines
1437 */
1438static RTEPermissionInfo *
1440{
1441 Index rti;
1442 RangeTblEntry *rte;
1443 RTEPermissionInfo *perminfo = NULL;
1444
1445 if (relinfo->ri_RootResultRelInfo)
1446 {
1447 /*
1448 * For inheritance child result relations (a partition routing target
1449 * of an INSERT or a child UPDATE target), this returns the root
1450 * parent's RTE to fetch the RTEPermissionInfo because that's the only
1451 * one that has one assigned.
1452 */
1454 }
1455 else if (relinfo->ri_RangeTableIndex != 0)
1456 {
1457 /*
1458 * Non-child result relation should have their own RTEPermissionInfo.
1459 */
1460 rti = relinfo->ri_RangeTableIndex;
1461 }
1462 else
1463 {
1464 /*
1465 * The relation isn't in the range table and it isn't a partition
1466 * routing target. This ResultRelInfo must've been created only for
1467 * firing triggers and the relation is not being inserted into. (See
1468 * ExecGetTriggerResultRel.)
1469 */
1470 rti = 0;
1471 }
1472
1473 if (rti > 0)
1474 {
1475 rte = exec_rt_fetch(rti, estate);
1476 perminfo = getRTEPermissionInfo(estate->es_rteperminfos, rte);
1477 }
1478
1479 return perminfo;
1480}
1481
1482/*
1483 * ExecGetResultRelCheckAsUser
1484 * Returns the user to modify passed-in result relation as
1485 *
1486 * The user is chosen by looking up the relation's or, if a child table, its
1487 * root parent's RTEPermissionInfo.
1488 */
1489Oid
1491{
1492 RTEPermissionInfo *perminfo = GetResultRTEPermissionInfo(relInfo, estate);
1493
1494 /* XXX - maybe ok to return GetUserId() in this case? */
1495 if (perminfo == NULL)
1496 elog(ERROR, "no RTEPermissionInfo found for result relation with OID %u",
1498
1499 return perminfo->checkAsUser ? perminfo->checkAsUser : GetUserId();
1500}
AttrMap * build_attrmap_by_name_if_req(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
Definition: attmap.c:261
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
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
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 Min(x, y)
Definition: c.h:975
#define Max(x, y)
Definition: c.h:969
int32_t int32
Definition: c.h:498
unsigned int Index
Definition: c.h:585
uint32 CommandId
Definition: c.h:637
size_t Size
Definition: c.h:576
int errhint(const char *fmt,...)
Definition: elog.c:1318
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
int errposition(int cursorpos)
Definition: elog.c:1468
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#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:1329
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultSlot(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1968
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:2000
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:2020
void ExecSetSlotDescriptor(TupleTableSlot *slot, TupleDesc tupdesc)
Definition: execTuples.c:1478
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
Definition: execTuples.c:1765
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:496
Relation ExecGetRangeTableRelation(EState *estate, Index rti, bool isResultRel)
Definition: execUtils.c:826
TupleConversionMap * ExecGetRootToChildMap(ResultRelInfo *resultRelInfo, EState *estate)
Definition: execUtils.c:1327
Bitmapset * ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1404
static void ShutdownExprContext(ExprContext *econtext, bool isCommit)
Definition: execUtils.c:1021
Bitmapset * ExecGetInsertedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1362
TupleTableSlot * ExecGetTriggerNewSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1227
void ReScanExprContext(ExprContext *econtext)
Definition: execUtils.c:444
ExprContext * CreateExprContext(EState *estate)
Definition: execUtils.c:308
static RTEPermissionInfo * GetResultRTEPermissionInfo(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1439
TupleConversionMap * ExecGetChildToRootMap(ResultRelInfo *resultRelInfo)
Definition: execUtils.c:1301
ExprContext * CreateStandaloneExprContext(void)
Definition: execUtils.c:358
TupleTableSlot * ExecGetTriggerOldSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1205
int executor_errposition(EState *estate, int location)
Definition: execUtils.c:937
Datum GetAttributeByNum(HeapTupleHeader tuple, AttrNumber attrno, bool *isNull)
Definition: execUtils.c:1125
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:1383
const TupleTableSlotOps * ExecGetCommonSlotOps(PlanState **planstates, int nplans)
Definition: execUtils.c:537
void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo, Index rti)
Definition: execUtils.c:881
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:705
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
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:990
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:964
int ExecTargetListLength(List *targetlist)
Definition: execUtils.c:1176
void FreeExecutorState(EState *estate)
Definition: execUtils.c:193
bool ExecRelationIsTargetRelation(EState *estate, Index scanrelid)
Definition: execUtils.c:730
static ExprContext * CreateExprContextInternal(EState *estate, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: execUtils.c:238
TupleTableSlot * ExecGetAllNullSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1274
int ExecCleanTargetListLength(List *targetlist)
Definition: execUtils.c:1186
ExprContext * CreateWorkExprContext(EState *estate)
Definition: execUtils.c:323
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:911
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:505
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:1062
Bitmapset * ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1419
TupleTableSlot * ExecGetReturningSlot(EState *estate, ResultRelInfo *relInfo)
Definition: execUtils.c:1249
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:743
Oid ExecGetResultRelCheckAsUser(ResultRelInfo *relInfo, EState *estate)
Definition: execUtils.c:1490
EState * CreateExecutorState(void)
Definition: execUtils.c:88
void(* ExprContextCallbackFunction)(Datum arg)
Definition: execnodes.h:230
#define outerPlanState(node)
Definition: execnodes.h:1255
#define innerPlanState(node)
Definition: execnodes.h:1254
#define EXEC_FLAG_WITH_NO_DATA
Definition: executor.h:72
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:719
#define GetPerTupleMemoryContext(estate)
Definition: executor.h:683
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:66
int work_mem
Definition: globals.c:132
Assert(PointerIsAligned(start, uint64))
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:904
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:77
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:334
#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:1256
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:414
void pfree(void *pointer)
Definition: mcxt.c:2147
void * palloc0(Size size)
Definition: mcxt.c:1970
MemoryContext CurrentMemoryContext
Definition: mcxt.c:159
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:485
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_MAXSIZE
Definition: memutils.h:179
#define ALLOCSET_DEFAULT_MINSIZE
Definition: memutils.h:177
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
#define ALLOCSET_DEFAULT_INITSIZE
Definition: memutils.h:178
Oid GetUserId(void)
Definition: miscinit.c:520
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:164
@ CMD_UPDATE
Definition: nodes.h:272
#define makeNode(_type_)
Definition: nodes.h:161
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:202
on_exit_nicely_callback function
void * arg
#define pg_prevpower2_size_t
Definition: pg_bitutils.h:442
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:241
uintptr_t Datum
Definition: postgres.h:69
#define InvalidOid
Definition: postgres_ext.h:35
unsigned int Oid
Definition: postgres_ext.h:30
#define RelationGetRelid(relation)
Definition: rel.h:516
#define RelationIsScannable(relation)
Definition: rel.h:680
#define RelationGetDescr(relation)
Definition: rel.h:542
#define RelationGetRelationName(relation)
Definition: rel.h:550
@ ForwardScanDirection
Definition: sdir.h:28
#define InvalidSnapshot
Definition: snapshot.h:119
Definition: attmap.h:35
uint64 es_processed
Definition: execnodes.h:712
bool es_aborted
Definition: execnodes.h:720
List * es_part_prune_infos
Definition: execnodes.h:668
struct ExecRowMark ** es_rowmarks
Definition: execnodes.h:663
int es_parallel_workers_to_launch
Definition: execnodes.h:745
List * es_tuple_routing_result_relations
Definition: execnodes.h:696
int es_top_eflags
Definition: execnodes.h:717
struct JitContext * es_jit
Definition: execnodes.h:763
int es_instrument
Definition: execnodes.h:718
PlannedStmt * es_plannedstmt
Definition: execnodes.h:666
QueryEnvironment * es_queryEnv
Definition: execnodes.h:705
ResultRelInfo ** es_result_relations
Definition: execnodes.h:683
ParamExecData * es_param_exec_vals
Definition: execnodes.h:703
uint64 es_total_processed
Definition: execnodes.h:714
List * es_range_table
Definition: execnodes.h:659
List * es_rteperminfos
Definition: execnodes.h:665
Bitmapset * es_unpruned_relids
Definition: execnodes.h:671
List * es_exprcontexts
Definition: execnodes.h:722
ParamListInfo es_param_list_info
Definition: execnodes.h:702
bool es_finished
Definition: execnodes.h:719
List * es_insert_pending_result_relations
Definition: execnodes.h:770
MemoryContext es_query_cxt
Definition: execnodes.h:708
List * es_tupleTable
Definition: execnodes.h:710
ScanDirection es_direction
Definition: execnodes.h:656
PartitionDirectory es_partition_directory
Definition: execnodes.h:690
List * es_trig_target_relations
Definition: execnodes.h:699
int es_jit_flags
Definition: execnodes.h:762
List * es_opened_result_relations
Definition: execnodes.h:686
bool es_use_parallel_mode
Definition: execnodes.h:743
Relation * es_relations
Definition: execnodes.h:661
List * es_subplanstates
Definition: execnodes.h:724
ExprContext * es_per_tuple_exprcontext
Definition: execnodes.h:733
int es_parallel_workers_launched
Definition: execnodes.h:747
CommandId es_output_cid
Definition: execnodes.h:680
Index es_range_table_size
Definition: execnodes.h:660
List * es_insert_pending_modifytables
Definition: execnodes.h:771
const char * es_sourceText
Definition: execnodes.h:675
Snapshot es_snapshot
Definition: execnodes.h:657
List * es_auxmodifytables
Definition: execnodes.h:726
JunkFilter * es_junkFilter
Definition: execnodes.h:677
Snapshot es_crosscheck_snapshot
Definition: execnodes.h:658
struct ExprContext_CB * next
Definition: execnodes.h:234
ExprContextCallbackFunction function
Definition: execnodes.h:235
Datum domainValue_datum
Definition: execnodes.h:299
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:280
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:276
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:270
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:279
Datum * ecxt_aggvalues
Definition: execnodes.h:287
bool caseValue_isNull
Definition: execnodes.h:295
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:268
Datum caseValue_datum
Definition: execnodes.h:293
bool * ecxt_aggnulls
Definition: execnodes.h:289
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:275
ExprContext_CB * ecxt_callbacks
Definition: execnodes.h:313
bool domainValue_isNull
Definition: execnodes.h:301
struct EState * ecxt_estate
Definition: execnodes.h:310
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:272
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:1236
bool resultopsset
Definition: execnodes.h:1244
const TupleTableSlotOps * scanops
Definition: execnodes.h:1233
Plan * plan
Definition: execnodes.h:1159
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1196
Bitmapset * chgParam
Definition: execnodes.h:1191
bool scanopsset
Definition: execnodes.h:1241
ExprContext * ps_ExprContext
Definition: execnodes.h:1198
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1197
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1199
bool scanopsfixed
Definition: execnodes.h:1237
bool resultopsfixed
Definition: execnodes.h:1240
Bitmapset * allParam
Definition: plannodes.h:230
List * targetlist
Definition: plannodes.h:209
List * resultRelations
Definition: plannodes.h:106
Bitmapset * insertedCols
Definition: parsenodes.h:1308
Bitmapset * updatedCols
Definition: parsenodes.h:1309
RTEKind rtekind
Definition: parsenodes.h:1061
Form_pg_class rd_rel
Definition: rel.h:111
TupleConversionMap * ri_RootToChildMap
Definition: execnodes.h:601
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:615
Relation ri_RelationDesc
Definition: execnodes.h:475
TupleTableSlot * ri_ReturningSlot
Definition: execnodes.h:522
bool ri_extraUpdatedCols_valid
Definition: execnodes.h:495
bool ri_RootToChildMapValid
Definition: execnodes.h:602
TupleTableSlot * ri_AllNullSlot
Definition: execnodes.h:525
Bitmapset * ri_extraUpdatedCols
Definition: execnodes.h:493
Index ri_RangeTableIndex
Definition: execnodes.h:472
TupleConversionMap * ri_ChildToRootMap
Definition: execnodes.h:595
bool ri_ChildToRootMapValid
Definition: execnodes.h:596
TupleTableSlot * ri_TrigNewSlot
Definition: execnodes.h:524
TupleTableSlot * ri_TrigOldSlot
Definition: execnodes.h:523
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1618
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:59
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:219
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
#define TTS_FIXED(slot)
Definition: tuptable.h:108
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1922