PostgreSQL Source Code  git master
execExprInterp.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * execExprInterp.c
4  * Interpreted evaluation of an expression step list.
5  *
6  * This file provides either a "direct threaded" (for gcc, clang and
7  * compatible) or a "switch threaded" (for all compilers) implementation of
8  * expression evaluation. The former is amongst the fastest known methods
9  * of interpreting programs without resorting to assembly level work, or
10  * just-in-time compilation, but it requires support for computed gotos.
11  * The latter is amongst the fastest approaches doable in standard C.
12  *
13  * In either case we use ExprEvalStep->opcode to dispatch to the code block
14  * within ExecInterpExpr() that implements the specific opcode type.
15  *
16  * Switch-threading uses a plain switch() statement to perform the
17  * dispatch. This has the advantages of being plain C and allowing the
18  * compiler to warn if implementation of a specific opcode has been forgotten.
19  * The disadvantage is that dispatches will, as commonly implemented by
20  * compilers, happen from a single location, requiring more jumps and causing
21  * bad branch prediction.
22  *
23  * In direct threading, we use gcc's label-as-values extension - also adopted
24  * by some other compilers - to replace ExprEvalStep->opcode with the address
25  * of the block implementing the instruction. Dispatch to the next instruction
26  * is done by a "computed goto". This allows for better branch prediction
27  * (as the jumps are happening from different locations) and fewer jumps
28  * (as no preparatory jump to a common dispatch location is needed).
29  *
30  * When using direct threading, ExecReadyInterpretedExpr will replace
31  * each step's opcode field with the address of the relevant code block and
32  * ExprState->flags will contain EEO_FLAG_DIRECT_THREADED to remember that
33  * that's been done.
34  *
35  * For very simple instructions the overhead of the full interpreter
36  * "startup", as minimal as it is, is noticeable. Therefore
37  * ExecReadyInterpretedExpr will choose to implement certain simple
38  * opcode patterns using special fast-path routines (ExecJust*).
39  *
40  * Complex or uncommon instructions are not implemented in-line in
41  * ExecInterpExpr(), rather we call out to a helper function appearing later
42  * in this file. For one reason, there'd not be a noticeable performance
43  * benefit, but more importantly those complex routines are intended to be
44  * shared between different expression evaluation approaches. For instance
45  * a JIT compiler would generate calls to them. (This is why they are
46  * exported rather than being "static" in this file.)
47  *
48  *
49  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
50  * Portions Copyright (c) 1994, Regents of the University of California
51  *
52  * IDENTIFICATION
53  * src/backend/executor/execExprInterp.c
54  *
55  *-------------------------------------------------------------------------
56  */
57 #include "postgres.h"
58 
59 #include "access/heaptoast.h"
60 #include "catalog/pg_type.h"
61 #include "commands/sequence.h"
62 #include "executor/execExpr.h"
63 #include "executor/nodeSubplan.h"
64 #include "funcapi.h"
65 #include "miscadmin.h"
66 #include "nodes/nodeFuncs.h"
67 #include "parser/parsetree.h"
68 #include "pgstat.h"
69 #include "utils/array.h"
70 #include "utils/builtins.h"
71 #include "utils/date.h"
72 #include "utils/datum.h"
73 #include "utils/expandedrecord.h"
74 #include "utils/lsyscache.h"
75 #include "utils/memutils.h"
76 #include "utils/timestamp.h"
77 #include "utils/typcache.h"
78 #include "utils/xml.h"
79 
80 /*
81  * Use computed-goto-based opcode dispatch when computed gotos are available.
82  * But use a separate symbol so that it's easy to adjust locally in this file
83  * for development and testing.
84  */
85 #ifdef HAVE_COMPUTED_GOTO
86 #define EEO_USE_COMPUTED_GOTO
87 #endif /* HAVE_COMPUTED_GOTO */
88 
89 /*
90  * Macros for opcode dispatch.
91  *
92  * EEO_SWITCH - just hides the switch if not in use.
93  * EEO_CASE - labels the implementation of named expression step type.
94  * EEO_DISPATCH - jump to the implementation of the step type for 'op'.
95  * EEO_OPCODE - compute opcode required by used expression evaluation method.
96  * EEO_NEXT - increment 'op' and jump to correct next step type.
97  * EEO_JUMP - jump to the specified step number within the current expression.
98  */
99 #if defined(EEO_USE_COMPUTED_GOTO)
100 
101 /* struct for jump target -> opcode lookup table */
102 typedef struct ExprEvalOpLookup
103 {
104  const void *opcode;
105  ExprEvalOp op;
106 } ExprEvalOpLookup;
107 
108 /* to make dispatch_table accessible outside ExecInterpExpr() */
109 static const void **dispatch_table = NULL;
110 
111 /* jump target -> opcode lookup table */
112 static ExprEvalOpLookup reverse_dispatch_table[EEOP_LAST];
113 
114 #define EEO_SWITCH()
115 #define EEO_CASE(name) CASE_##name:
116 #define EEO_DISPATCH() goto *((void *) op->opcode)
117 #define EEO_OPCODE(opcode) ((intptr_t) dispatch_table[opcode])
118 
119 #else /* !EEO_USE_COMPUTED_GOTO */
120 
121 #define EEO_SWITCH() starteval: switch ((ExprEvalOp) op->opcode)
122 #define EEO_CASE(name) case name:
123 #define EEO_DISPATCH() goto starteval
124 #define EEO_OPCODE(opcode) (opcode)
125 
126 #endif /* EEO_USE_COMPUTED_GOTO */
127 
128 #define EEO_NEXT() \
129  do { \
130  op++; \
131  EEO_DISPATCH(); \
132  } while (0)
133 
134 #define EEO_JUMP(stepno) \
135  do { \
136  op = &state->steps[stepno]; \
137  EEO_DISPATCH(); \
138  } while (0)
139 
140 
141 static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull);
142 static void ExecInitInterpreter(void);
143 
144 /* support functions */
145 static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype);
147 static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod,
148  TupleDesc *cache_field, ExprContext *econtext);
149 static void ShutdownTupleDescRef(Datum arg);
151  ExprContext *econtext, bool checkisnull);
152 
153 /* fast-path evaluation functions */
154 static Datum ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull);
155 static Datum ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull);
156 static Datum ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull);
157 static Datum ExecJustAssignInnerVar(ExprState *state, ExprContext *econtext, bool *isnull);
158 static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull);
159 static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull);
160 static Datum ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull);
161 static Datum ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull);
162 static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
163 static Datum ExecJustOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
164 static Datum ExecJustScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
165 static Datum ExecJustAssignInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
166 static Datum ExecJustAssignOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
167 static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull);
168 
169 /* execution helper functions */
171  AggStatePerTrans pertrans,
172  AggStatePerGroup pergroup,
173  ExprContext *aggcontext,
174  int setno);
176  AggStatePerTrans pertrans,
177  AggStatePerGroup pergroup,
178  ExprContext *aggcontext,
179  int setno);
180 
181 /*
182  * Prepare ExprState for interpreted execution.
183  */
184 void
186 {
187  /* Ensure one-time interpreter setup has been done */
189 
190  /* Simple validity checks on expression */
191  Assert(state->steps_len >= 1);
192  Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
193 
194  /*
195  * Don't perform redundant initialization. This is unreachable in current
196  * cases, but might be hit if there's additional expression evaluation
197  * methods that rely on interpreted execution to work.
198  */
200  return;
201 
202  /*
203  * First time through, check whether attribute matches Var. Might not be
204  * ok anymore, due to schema changes. We do that by setting up a callback
205  * that does checking on the first call, which then sets the evalfunc
206  * callback to the actual method of execution.
207  */
209 
210  /* DIRECT_THREADED should not already be set */
211  Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
212 
213  /*
214  * There shouldn't be any errors before the expression is fully
215  * initialized, and even if so, it'd lead to the expression being
216  * abandoned. So we can set the flag now and save some code.
217  */
219 
220  /*
221  * Select fast-path evalfuncs for very simple expressions. "Starting up"
222  * the full interpreter is a measurable overhead for these, and these
223  * patterns occur often enough to be worth optimizing.
224  */
225  if (state->steps_len == 3)
226  {
227  ExprEvalOp step0 = state->steps[0].opcode;
228  ExprEvalOp step1 = state->steps[1].opcode;
229 
230  if (step0 == EEOP_INNER_FETCHSOME &&
231  step1 == EEOP_INNER_VAR)
232  {
233  state->evalfunc_private = (void *) ExecJustInnerVar;
234  return;
235  }
236  else if (step0 == EEOP_OUTER_FETCHSOME &&
237  step1 == EEOP_OUTER_VAR)
238  {
239  state->evalfunc_private = (void *) ExecJustOuterVar;
240  return;
241  }
242  else if (step0 == EEOP_SCAN_FETCHSOME &&
243  step1 == EEOP_SCAN_VAR)
244  {
245  state->evalfunc_private = (void *) ExecJustScanVar;
246  return;
247  }
248  else if (step0 == EEOP_INNER_FETCHSOME &&
249  step1 == EEOP_ASSIGN_INNER_VAR)
250  {
251  state->evalfunc_private = (void *) ExecJustAssignInnerVar;
252  return;
253  }
254  else if (step0 == EEOP_OUTER_FETCHSOME &&
255  step1 == EEOP_ASSIGN_OUTER_VAR)
256  {
257  state->evalfunc_private = (void *) ExecJustAssignOuterVar;
258  return;
259  }
260  else if (step0 == EEOP_SCAN_FETCHSOME &&
261  step1 == EEOP_ASSIGN_SCAN_VAR)
262  {
263  state->evalfunc_private = (void *) ExecJustAssignScanVar;
264  return;
265  }
266  else if (step0 == EEOP_CASE_TESTVAL &&
267  step1 == EEOP_FUNCEXPR_STRICT &&
268  state->steps[0].d.casetest.value)
269  {
270  state->evalfunc_private = (void *) ExecJustApplyFuncToCase;
271  return;
272  }
273  }
274  else if (state->steps_len == 2)
275  {
276  ExprEvalOp step0 = state->steps[0].opcode;
277 
278  if (step0 == EEOP_CONST)
279  {
280  state->evalfunc_private = (void *) ExecJustConst;
281  return;
282  }
283  else if (step0 == EEOP_INNER_VAR)
284  {
285  state->evalfunc_private = (void *) ExecJustInnerVarVirt;
286  return;
287  }
288  else if (step0 == EEOP_OUTER_VAR)
289  {
290  state->evalfunc_private = (void *) ExecJustOuterVarVirt;
291  return;
292  }
293  else if (step0 == EEOP_SCAN_VAR)
294  {
295  state->evalfunc_private = (void *) ExecJustScanVarVirt;
296  return;
297  }
298  else if (step0 == EEOP_ASSIGN_INNER_VAR)
299  {
301  return;
302  }
303  else if (step0 == EEOP_ASSIGN_OUTER_VAR)
304  {
306  return;
307  }
308  else if (step0 == EEOP_ASSIGN_SCAN_VAR)
309  {
311  return;
312  }
313  }
314 
315 #if defined(EEO_USE_COMPUTED_GOTO)
316 
317  /*
318  * In the direct-threaded implementation, replace each opcode with the
319  * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
320  */
321  for (int off = 0; off < state->steps_len; off++)
322  {
323  ExprEvalStep *op = &state->steps[off];
324 
325  op->opcode = EEO_OPCODE(op->opcode);
326  }
327 
329 #endif /* EEO_USE_COMPUTED_GOTO */
330 
331  state->evalfunc_private = (void *) ExecInterpExpr;
332 }
333 
334 
335 /*
336  * Evaluate expression identified by "state" in the execution context
337  * given by "econtext". *isnull is set to the is-null flag for the result,
338  * and the Datum value is the function result.
339  *
340  * As a special case, return the dispatch table's address if state is NULL.
341  * This is used by ExecInitInterpreter to set up the dispatch_table global.
342  * (Only applies when EEO_USE_COMPUTED_GOTO is defined.)
343  */
344 static Datum
345 ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
346 {
347  ExprEvalStep *op;
348  TupleTableSlot *resultslot;
349  TupleTableSlot *innerslot;
350  TupleTableSlot *outerslot;
351  TupleTableSlot *scanslot;
352 
353  /*
354  * This array has to be in the same order as enum ExprEvalOp.
355  */
356 #if defined(EEO_USE_COMPUTED_GOTO)
357  static const void *const dispatch_table[] = {
358  &&CASE_EEOP_DONE,
359  &&CASE_EEOP_INNER_FETCHSOME,
360  &&CASE_EEOP_OUTER_FETCHSOME,
361  &&CASE_EEOP_SCAN_FETCHSOME,
362  &&CASE_EEOP_INNER_VAR,
363  &&CASE_EEOP_OUTER_VAR,
364  &&CASE_EEOP_SCAN_VAR,
365  &&CASE_EEOP_INNER_SYSVAR,
366  &&CASE_EEOP_OUTER_SYSVAR,
367  &&CASE_EEOP_SCAN_SYSVAR,
368  &&CASE_EEOP_WHOLEROW,
369  &&CASE_EEOP_ASSIGN_INNER_VAR,
370  &&CASE_EEOP_ASSIGN_OUTER_VAR,
371  &&CASE_EEOP_ASSIGN_SCAN_VAR,
372  &&CASE_EEOP_ASSIGN_TMP,
373  &&CASE_EEOP_ASSIGN_TMP_MAKE_RO,
374  &&CASE_EEOP_CONST,
375  &&CASE_EEOP_FUNCEXPR,
376  &&CASE_EEOP_FUNCEXPR_STRICT,
377  &&CASE_EEOP_FUNCEXPR_FUSAGE,
378  &&CASE_EEOP_FUNCEXPR_STRICT_FUSAGE,
379  &&CASE_EEOP_BOOL_AND_STEP_FIRST,
380  &&CASE_EEOP_BOOL_AND_STEP,
381  &&CASE_EEOP_BOOL_AND_STEP_LAST,
382  &&CASE_EEOP_BOOL_OR_STEP_FIRST,
383  &&CASE_EEOP_BOOL_OR_STEP,
384  &&CASE_EEOP_BOOL_OR_STEP_LAST,
385  &&CASE_EEOP_BOOL_NOT_STEP,
386  &&CASE_EEOP_QUAL,
387  &&CASE_EEOP_JUMP,
388  &&CASE_EEOP_JUMP_IF_NULL,
389  &&CASE_EEOP_JUMP_IF_NOT_NULL,
390  &&CASE_EEOP_JUMP_IF_NOT_TRUE,
391  &&CASE_EEOP_NULLTEST_ISNULL,
392  &&CASE_EEOP_NULLTEST_ISNOTNULL,
393  &&CASE_EEOP_NULLTEST_ROWISNULL,
394  &&CASE_EEOP_NULLTEST_ROWISNOTNULL,
395  &&CASE_EEOP_BOOLTEST_IS_TRUE,
396  &&CASE_EEOP_BOOLTEST_IS_NOT_TRUE,
397  &&CASE_EEOP_BOOLTEST_IS_FALSE,
398  &&CASE_EEOP_BOOLTEST_IS_NOT_FALSE,
399  &&CASE_EEOP_PARAM_EXEC,
400  &&CASE_EEOP_PARAM_EXTERN,
401  &&CASE_EEOP_PARAM_CALLBACK,
402  &&CASE_EEOP_CASE_TESTVAL,
403  &&CASE_EEOP_MAKE_READONLY,
404  &&CASE_EEOP_IOCOERCE,
405  &&CASE_EEOP_DISTINCT,
406  &&CASE_EEOP_NOT_DISTINCT,
407  &&CASE_EEOP_NULLIF,
408  &&CASE_EEOP_SQLVALUEFUNCTION,
409  &&CASE_EEOP_CURRENTOFEXPR,
410  &&CASE_EEOP_NEXTVALUEEXPR,
411  &&CASE_EEOP_ARRAYEXPR,
412  &&CASE_EEOP_ARRAYCOERCE,
413  &&CASE_EEOP_ROW,
414  &&CASE_EEOP_ROWCOMPARE_STEP,
415  &&CASE_EEOP_ROWCOMPARE_FINAL,
416  &&CASE_EEOP_MINMAX,
417  &&CASE_EEOP_FIELDSELECT,
418  &&CASE_EEOP_FIELDSTORE_DEFORM,
419  &&CASE_EEOP_FIELDSTORE_FORM,
420  &&CASE_EEOP_SBSREF_SUBSCRIPT,
421  &&CASE_EEOP_SBSREF_OLD,
422  &&CASE_EEOP_SBSREF_ASSIGN,
423  &&CASE_EEOP_SBSREF_FETCH,
424  &&CASE_EEOP_DOMAIN_TESTVAL,
425  &&CASE_EEOP_DOMAIN_NOTNULL,
426  &&CASE_EEOP_DOMAIN_CHECK,
427  &&CASE_EEOP_CONVERT_ROWTYPE,
428  &&CASE_EEOP_SCALARARRAYOP,
429  &&CASE_EEOP_XMLEXPR,
430  &&CASE_EEOP_AGGREF,
431  &&CASE_EEOP_GROUPING_FUNC,
432  &&CASE_EEOP_WINDOW_FUNC,
433  &&CASE_EEOP_SUBPLAN,
434  &&CASE_EEOP_AGG_STRICT_DESERIALIZE,
435  &&CASE_EEOP_AGG_DESERIALIZE,
436  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
437  &&CASE_EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
438  &&CASE_EEOP_AGG_PLAIN_PERGROUP_NULLCHECK,
439  &&CASE_EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
440  &&CASE_EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL,
441  &&CASE_EEOP_AGG_PLAIN_TRANS_BYVAL,
442  &&CASE_EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF,
443  &&CASE_EEOP_AGG_PLAIN_TRANS_STRICT_BYREF,
444  &&CASE_EEOP_AGG_PLAIN_TRANS_BYREF,
445  &&CASE_EEOP_AGG_ORDERED_TRANS_DATUM,
446  &&CASE_EEOP_AGG_ORDERED_TRANS_TUPLE,
447  &&CASE_EEOP_LAST
448  };
449 
450  StaticAssertStmt(EEOP_LAST + 1 == lengthof(dispatch_table),
451  "dispatch_table out of whack with ExprEvalOp");
452 
453  if (unlikely(state == NULL))
454  return PointerGetDatum(dispatch_table);
455 #else
456  Assert(state != NULL);
457 #endif /* EEO_USE_COMPUTED_GOTO */
458 
459  /* setup state */
460  op = state->steps;
461  resultslot = state->resultslot;
462  innerslot = econtext->ecxt_innertuple;
463  outerslot = econtext->ecxt_outertuple;
464  scanslot = econtext->ecxt_scantuple;
465 
466 #if defined(EEO_USE_COMPUTED_GOTO)
467  EEO_DISPATCH();
468 #endif
469 
470  EEO_SWITCH()
471  {
473  {
474  goto out;
475  }
476 
478  {
479  CheckOpSlotCompatibility(op, innerslot);
480 
481  slot_getsomeattrs(innerslot, op->d.fetch.last_var);
482 
483  EEO_NEXT();
484  }
485 
487  {
488  CheckOpSlotCompatibility(op, outerslot);
489 
490  slot_getsomeattrs(outerslot, op->d.fetch.last_var);
491 
492  EEO_NEXT();
493  }
494 
496  {
497  CheckOpSlotCompatibility(op, scanslot);
498 
499  slot_getsomeattrs(scanslot, op->d.fetch.last_var);
500 
501  EEO_NEXT();
502  }
503 
505  {
506  int attnum = op->d.var.attnum;
507 
508  /*
509  * Since we already extracted all referenced columns from the
510  * tuple with a FETCHSOME step, we can just grab the value
511  * directly out of the slot's decomposed-data arrays. But let's
512  * have an Assert to check that that did happen.
513  */
514  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
515  *op->resvalue = innerslot->tts_values[attnum];
516  *op->resnull = innerslot->tts_isnull[attnum];
517 
518  EEO_NEXT();
519  }
520 
522  {
523  int attnum = op->d.var.attnum;
524 
525  /* See EEOP_INNER_VAR comments */
526 
527  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
528  *op->resvalue = outerslot->tts_values[attnum];
529  *op->resnull = outerslot->tts_isnull[attnum];
530 
531  EEO_NEXT();
532  }
533 
535  {
536  int attnum = op->d.var.attnum;
537 
538  /* See EEOP_INNER_VAR comments */
539 
540  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
541  *op->resvalue = scanslot->tts_values[attnum];
542  *op->resnull = scanslot->tts_isnull[attnum];
543 
544  EEO_NEXT();
545  }
546 
548  {
549  ExecEvalSysVar(state, op, econtext, innerslot);
550  EEO_NEXT();
551  }
552 
554  {
555  ExecEvalSysVar(state, op, econtext, outerslot);
556  EEO_NEXT();
557  }
558 
560  {
561  ExecEvalSysVar(state, op, econtext, scanslot);
562  EEO_NEXT();
563  }
564 
566  {
567  /* too complex for an inline implementation */
568  ExecEvalWholeRowVar(state, op, econtext);
569 
570  EEO_NEXT();
571  }
572 
574  {
575  int resultnum = op->d.assign_var.resultnum;
576  int attnum = op->d.assign_var.attnum;
577 
578  /*
579  * We do not need CheckVarSlotCompatibility here; that was taken
580  * care of at compilation time. But see EEOP_INNER_VAR comments.
581  */
582  Assert(attnum >= 0 && attnum < innerslot->tts_nvalid);
583  resultslot->tts_values[resultnum] = innerslot->tts_values[attnum];
584  resultslot->tts_isnull[resultnum] = innerslot->tts_isnull[attnum];
585 
586  EEO_NEXT();
587  }
588 
590  {
591  int resultnum = op->d.assign_var.resultnum;
592  int attnum = op->d.assign_var.attnum;
593 
594  /*
595  * We do not need CheckVarSlotCompatibility here; that was taken
596  * care of at compilation time. But see EEOP_INNER_VAR comments.
597  */
598  Assert(attnum >= 0 && attnum < outerslot->tts_nvalid);
599  resultslot->tts_values[resultnum] = outerslot->tts_values[attnum];
600  resultslot->tts_isnull[resultnum] = outerslot->tts_isnull[attnum];
601 
602  EEO_NEXT();
603  }
604 
606  {
607  int resultnum = op->d.assign_var.resultnum;
608  int attnum = op->d.assign_var.attnum;
609 
610  /*
611  * We do not need CheckVarSlotCompatibility here; that was taken
612  * care of at compilation time. But see EEOP_INNER_VAR comments.
613  */
614  Assert(attnum >= 0 && attnum < scanslot->tts_nvalid);
615  resultslot->tts_values[resultnum] = scanslot->tts_values[attnum];
616  resultslot->tts_isnull[resultnum] = scanslot->tts_isnull[attnum];
617 
618  EEO_NEXT();
619  }
620 
622  {
623  int resultnum = op->d.assign_tmp.resultnum;
624 
625  resultslot->tts_values[resultnum] = state->resvalue;
626  resultslot->tts_isnull[resultnum] = state->resnull;
627 
628  EEO_NEXT();
629  }
630 
632  {
633  int resultnum = op->d.assign_tmp.resultnum;
634 
635  resultslot->tts_isnull[resultnum] = state->resnull;
636  if (!resultslot->tts_isnull[resultnum])
637  resultslot->tts_values[resultnum] =
639  else
640  resultslot->tts_values[resultnum] = state->resvalue;
641 
642  EEO_NEXT();
643  }
644 
646  {
647  *op->resnull = op->d.constval.isnull;
648  *op->resvalue = op->d.constval.value;
649 
650  EEO_NEXT();
651  }
652 
653  /*
654  * Function-call implementations. Arguments have previously been
655  * evaluated directly into fcinfo->args.
656  *
657  * As both STRICT checks and function-usage are noticeable performance
658  * wise, and function calls are a very hot-path (they also back
659  * operators!), it's worth having so many separate opcodes.
660  *
661  * Note: the reason for using a temporary variable "d", here and in
662  * other places, is that some compilers think "*op->resvalue = f();"
663  * requires them to evaluate op->resvalue into a register before
664  * calling f(), just in case f() is able to modify op->resvalue
665  * somehow. The extra line of code can save a useless register spill
666  * and reload across the function call.
667  */
669  {
670  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
671  Datum d;
672 
673  fcinfo->isnull = false;
674  d = op->d.func.fn_addr(fcinfo);
675  *op->resvalue = d;
676  *op->resnull = fcinfo->isnull;
677 
678  EEO_NEXT();
679  }
680 
682  {
683  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
684  NullableDatum *args = fcinfo->args;
685  int nargs = op->d.func.nargs;
686  Datum d;
687 
688  /* strict function, so check for NULL args */
689  for (int argno = 0; argno < nargs; argno++)
690  {
691  if (args[argno].isnull)
692  {
693  *op->resnull = true;
694  goto strictfail;
695  }
696  }
697  fcinfo->isnull = false;
698  d = op->d.func.fn_addr(fcinfo);
699  *op->resvalue = d;
700  *op->resnull = fcinfo->isnull;
701 
702  strictfail:
703  EEO_NEXT();
704  }
705 
707  {
708  /* not common enough to inline */
709  ExecEvalFuncExprFusage(state, op, econtext);
710 
711  EEO_NEXT();
712  }
713 
715  {
716  /* not common enough to inline */
717  ExecEvalFuncExprStrictFusage(state, op, econtext);
718 
719  EEO_NEXT();
720  }
721 
722  /*
723  * If any of its clauses is FALSE, an AND's result is FALSE regardless
724  * of the states of the rest of the clauses, so we can stop evaluating
725  * and return FALSE immediately. If none are FALSE and one or more is
726  * NULL, we return NULL; otherwise we return TRUE. This makes sense
727  * when you interpret NULL as "don't know": perhaps one of the "don't
728  * knows" would have been FALSE if we'd known its value. Only when
729  * all the inputs are known to be TRUE can we state confidently that
730  * the AND's result is TRUE.
731  */
733  {
734  *op->d.boolexpr.anynull = false;
735 
736  /*
737  * EEOP_BOOL_AND_STEP_FIRST resets anynull, otherwise it's the
738  * same as EEOP_BOOL_AND_STEP - so fall through to that.
739  */
740 
741  /* FALL THROUGH */
742  }
743 
745  {
746  if (*op->resnull)
747  {
748  *op->d.boolexpr.anynull = true;
749  }
750  else if (!DatumGetBool(*op->resvalue))
751  {
752  /* result is already set to FALSE, need not change it */
753  /* bail out early */
754  EEO_JUMP(op->d.boolexpr.jumpdone);
755  }
756 
757  EEO_NEXT();
758  }
759 
761  {
762  if (*op->resnull)
763  {
764  /* result is already set to NULL, need not change it */
765  }
766  else if (!DatumGetBool(*op->resvalue))
767  {
768  /* result is already set to FALSE, need not change it */
769 
770  /*
771  * No point jumping early to jumpdone - would be same target
772  * (as this is the last argument to the AND expression),
773  * except more expensive.
774  */
775  }
776  else if (*op->d.boolexpr.anynull)
777  {
778  *op->resvalue = (Datum) 0;
779  *op->resnull = true;
780  }
781  else
782  {
783  /* result is already set to TRUE, need not change it */
784  }
785 
786  EEO_NEXT();
787  }
788 
789  /*
790  * If any of its clauses is TRUE, an OR's result is TRUE regardless of
791  * the states of the rest of the clauses, so we can stop evaluating
792  * and return TRUE immediately. If none are TRUE and one or more is
793  * NULL, we return NULL; otherwise we return FALSE. This makes sense
794  * when you interpret NULL as "don't know": perhaps one of the "don't
795  * knows" would have been TRUE if we'd known its value. Only when all
796  * the inputs are known to be FALSE can we state confidently that the
797  * OR's result is FALSE.
798  */
800  {
801  *op->d.boolexpr.anynull = false;
802 
803  /*
804  * EEOP_BOOL_OR_STEP_FIRST resets anynull, otherwise it's the same
805  * as EEOP_BOOL_OR_STEP - so fall through to that.
806  */
807 
808  /* FALL THROUGH */
809  }
810 
812  {
813  if (*op->resnull)
814  {
815  *op->d.boolexpr.anynull = true;
816  }
817  else if (DatumGetBool(*op->resvalue))
818  {
819  /* result is already set to TRUE, need not change it */
820  /* bail out early */
821  EEO_JUMP(op->d.boolexpr.jumpdone);
822  }
823 
824  EEO_NEXT();
825  }
826 
828  {
829  if (*op->resnull)
830  {
831  /* result is already set to NULL, need not change it */
832  }
833  else if (DatumGetBool(*op->resvalue))
834  {
835  /* result is already set to TRUE, need not change it */
836 
837  /*
838  * No point jumping to jumpdone - would be same target (as
839  * this is the last argument to the AND expression), except
840  * more expensive.
841  */
842  }
843  else if (*op->d.boolexpr.anynull)
844  {
845  *op->resvalue = (Datum) 0;
846  *op->resnull = true;
847  }
848  else
849  {
850  /* result is already set to FALSE, need not change it */
851  }
852 
853  EEO_NEXT();
854  }
855 
857  {
858  /*
859  * Evaluation of 'not' is simple... if expr is false, then return
860  * 'true' and vice versa. It's safe to do this even on a
861  * nominally null value, so we ignore resnull; that means that
862  * NULL in produces NULL out, which is what we want.
863  */
865 
866  EEO_NEXT();
867  }
868 
870  {
871  /* simplified version of BOOL_AND_STEP for use by ExecQual() */
872 
873  /* If argument (also result) is false or null ... */
874  if (*op->resnull ||
875  !DatumGetBool(*op->resvalue))
876  {
877  /* ... bail out early, returning FALSE */
878  *op->resnull = false;
879  *op->resvalue = BoolGetDatum(false);
880  EEO_JUMP(op->d.qualexpr.jumpdone);
881  }
882 
883  /*
884  * Otherwise, leave the TRUE value in place, in case this is the
885  * last qual. Then, TRUE is the correct answer.
886  */
887 
888  EEO_NEXT();
889  }
890 
892  {
893  /* Unconditionally jump to target step */
894  EEO_JUMP(op->d.jump.jumpdone);
895  }
896 
898  {
899  /* Transfer control if current result is null */
900  if (*op->resnull)
901  EEO_JUMP(op->d.jump.jumpdone);
902 
903  EEO_NEXT();
904  }
905 
907  {
908  /* Transfer control if current result is non-null */
909  if (!*op->resnull)
910  EEO_JUMP(op->d.jump.jumpdone);
911 
912  EEO_NEXT();
913  }
914 
916  {
917  /* Transfer control if current result is null or false */
918  if (*op->resnull || !DatumGetBool(*op->resvalue))
919  EEO_JUMP(op->d.jump.jumpdone);
920 
921  EEO_NEXT();
922  }
923 
925  {
926  *op->resvalue = BoolGetDatum(*op->resnull);
927  *op->resnull = false;
928 
929  EEO_NEXT();
930  }
931 
933  {
934  *op->resvalue = BoolGetDatum(!*op->resnull);
935  *op->resnull = false;
936 
937  EEO_NEXT();
938  }
939 
941  {
942  /* out of line implementation: too large */
943  ExecEvalRowNull(state, op, econtext);
944 
945  EEO_NEXT();
946  }
947 
949  {
950  /* out of line implementation: too large */
951  ExecEvalRowNotNull(state, op, econtext);
952 
953  EEO_NEXT();
954  }
955 
956  /* BooleanTest implementations for all booltesttypes */
957 
959  {
960  if (*op->resnull)
961  {
962  *op->resvalue = BoolGetDatum(false);
963  *op->resnull = false;
964  }
965  /* else, input value is the correct output as well */
966 
967  EEO_NEXT();
968  }
969 
971  {
972  if (*op->resnull)
973  {
974  *op->resvalue = BoolGetDatum(true);
975  *op->resnull = false;
976  }
977  else
979 
980  EEO_NEXT();
981  }
982 
984  {
985  if (*op->resnull)
986  {
987  *op->resvalue = BoolGetDatum(false);
988  *op->resnull = false;
989  }
990  else
992 
993  EEO_NEXT();
994  }
995 
997  {
998  if (*op->resnull)
999  {
1000  *op->resvalue = BoolGetDatum(true);
1001  *op->resnull = false;
1002  }
1003  /* else, input value is the correct output as well */
1004 
1005  EEO_NEXT();
1006  }
1007 
1009  {
1010  /* out of line implementation: too large */
1011  ExecEvalParamExec(state, op, econtext);
1012 
1013  EEO_NEXT();
1014  }
1015 
1017  {
1018  /* out of line implementation: too large */
1019  ExecEvalParamExtern(state, op, econtext);
1020  EEO_NEXT();
1021  }
1022 
1024  {
1025  /* allow an extension module to supply a PARAM_EXTERN value */
1026  op->d.cparam.paramfunc(state, op, econtext);
1027  EEO_NEXT();
1028  }
1029 
1031  {
1032  /*
1033  * Normally upper parts of the expression tree have setup the
1034  * values to be returned here, but some parts of the system
1035  * currently misuse {caseValue,domainValue}_{datum,isNull} to set
1036  * run-time data. So if no values have been set-up, use
1037  * ExprContext's. This isn't pretty, but also not *that* ugly,
1038  * and this is unlikely to be performance sensitive enough to
1039  * worry about an extra branch.
1040  */
1041  if (op->d.casetest.value)
1042  {
1043  *op->resvalue = *op->d.casetest.value;
1044  *op->resnull = *op->d.casetest.isnull;
1045  }
1046  else
1047  {
1048  *op->resvalue = econtext->caseValue_datum;
1049  *op->resnull = econtext->caseValue_isNull;
1050  }
1051 
1052  EEO_NEXT();
1053  }
1054 
1056  {
1057  /*
1058  * See EEOP_CASE_TESTVAL comment.
1059  */
1060  if (op->d.casetest.value)
1061  {
1062  *op->resvalue = *op->d.casetest.value;
1063  *op->resnull = *op->d.casetest.isnull;
1064  }
1065  else
1066  {
1067  *op->resvalue = econtext->domainValue_datum;
1068  *op->resnull = econtext->domainValue_isNull;
1069  }
1070 
1071  EEO_NEXT();
1072  }
1073 
1075  {
1076  /*
1077  * Force a varlena value that might be read multiple times to R/O
1078  */
1079  if (!*op->d.make_readonly.isnull)
1080  *op->resvalue =
1082  *op->resnull = *op->d.make_readonly.isnull;
1083 
1084  EEO_NEXT();
1085  }
1086 
1088  {
1089  /*
1090  * Evaluate a CoerceViaIO node. This can be quite a hot path, so
1091  * inline as much work as possible. The source value is in our
1092  * result variable.
1093  */
1094  char *str;
1095 
1096  /* call output function (similar to OutputFunctionCall) */
1097  if (*op->resnull)
1098  {
1099  /* output functions are not called on nulls */
1100  str = NULL;
1101  }
1102  else
1103  {
1104  FunctionCallInfo fcinfo_out;
1105 
1106  fcinfo_out = op->d.iocoerce.fcinfo_data_out;
1107  fcinfo_out->args[0].value = *op->resvalue;
1108  fcinfo_out->args[0].isnull = false;
1109 
1110  fcinfo_out->isnull = false;
1111  str = DatumGetCString(FunctionCallInvoke(fcinfo_out));
1112 
1113  /* OutputFunctionCall assumes result isn't null */
1114  Assert(!fcinfo_out->isnull);
1115  }
1116 
1117  /* call input function (similar to InputFunctionCall) */
1118  if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
1119  {
1120  FunctionCallInfo fcinfo_in;
1121  Datum d;
1122 
1123  fcinfo_in = op->d.iocoerce.fcinfo_data_in;
1124  fcinfo_in->args[0].value = PointerGetDatum(str);
1125  fcinfo_in->args[0].isnull = *op->resnull;
1126  /* second and third arguments are already set up */
1127 
1128  fcinfo_in->isnull = false;
1129  d = FunctionCallInvoke(fcinfo_in);
1130  *op->resvalue = d;
1131 
1132  /* Should get null result if and only if str is NULL */
1133  if (str == NULL)
1134  {
1135  Assert(*op->resnull);
1136  Assert(fcinfo_in->isnull);
1137  }
1138  else
1139  {
1140  Assert(!*op->resnull);
1141  Assert(!fcinfo_in->isnull);
1142  }
1143  }
1144 
1145  EEO_NEXT();
1146  }
1147 
1149  {
1150  /*
1151  * IS DISTINCT FROM must evaluate arguments (already done into
1152  * fcinfo->args) to determine whether they are NULL; if either is
1153  * NULL then the result is determined. If neither is NULL, then
1154  * proceed to evaluate the comparison function, which is just the
1155  * type's standard equality operator. We need not care whether
1156  * that function is strict. Because the handling of nulls is
1157  * different, we can't just reuse EEOP_FUNCEXPR.
1158  */
1159  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1160 
1161  /* check function arguments for NULLness */
1162  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1163  {
1164  /* Both NULL? Then is not distinct... */
1165  *op->resvalue = BoolGetDatum(false);
1166  *op->resnull = false;
1167  }
1168  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1169  {
1170  /* Only one is NULL? Then is distinct... */
1171  *op->resvalue = BoolGetDatum(true);
1172  *op->resnull = false;
1173  }
1174  else
1175  {
1176  /* Neither null, so apply the equality function */
1177  Datum eqresult;
1178 
1179  fcinfo->isnull = false;
1180  eqresult = op->d.func.fn_addr(fcinfo);
1181  /* Must invert result of "="; safe to do even if null */
1182  *op->resvalue = BoolGetDatum(!DatumGetBool(eqresult));
1183  *op->resnull = fcinfo->isnull;
1184  }
1185 
1186  EEO_NEXT();
1187  }
1188 
1189  /* see EEOP_DISTINCT for comments, this is just inverted */
1191  {
1192  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1193 
1194  if (fcinfo->args[0].isnull && fcinfo->args[1].isnull)
1195  {
1196  *op->resvalue = BoolGetDatum(true);
1197  *op->resnull = false;
1198  }
1199  else if (fcinfo->args[0].isnull || fcinfo->args[1].isnull)
1200  {
1201  *op->resvalue = BoolGetDatum(false);
1202  *op->resnull = false;
1203  }
1204  else
1205  {
1206  Datum eqresult;
1207 
1208  fcinfo->isnull = false;
1209  eqresult = op->d.func.fn_addr(fcinfo);
1210  *op->resvalue = eqresult;
1211  *op->resnull = fcinfo->isnull;
1212  }
1213 
1214  EEO_NEXT();
1215  }
1216 
1218  {
1219  /*
1220  * The arguments are already evaluated into fcinfo->args.
1221  */
1222  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
1223 
1224  /* if either argument is NULL they can't be equal */
1225  if (!fcinfo->args[0].isnull && !fcinfo->args[1].isnull)
1226  {
1227  Datum result;
1228 
1229  fcinfo->isnull = false;
1230  result = op->d.func.fn_addr(fcinfo);
1231 
1232  /* if the arguments are equal return null */
1233  if (!fcinfo->isnull && DatumGetBool(result))
1234  {
1235  *op->resvalue = (Datum) 0;
1236  *op->resnull = true;
1237 
1238  EEO_NEXT();
1239  }
1240  }
1241 
1242  /* Arguments aren't equal, so return the first one */
1243  *op->resvalue = fcinfo->args[0].value;
1244  *op->resnull = fcinfo->args[0].isnull;
1245 
1246  EEO_NEXT();
1247  }
1248 
1250  {
1251  /*
1252  * Doesn't seem worthwhile to have an inline implementation
1253  * efficiency-wise.
1254  */
1255  ExecEvalSQLValueFunction(state, op);
1256 
1257  EEO_NEXT();
1258  }
1259 
1261  {
1262  /* error invocation uses space, and shouldn't ever occur */
1263  ExecEvalCurrentOfExpr(state, op);
1264 
1265  EEO_NEXT();
1266  }
1267 
1269  {
1270  /*
1271  * Doesn't seem worthwhile to have an inline implementation
1272  * efficiency-wise.
1273  */
1274  ExecEvalNextValueExpr(state, op);
1275 
1276  EEO_NEXT();
1277  }
1278 
1280  {
1281  /* too complex for an inline implementation */
1282  ExecEvalArrayExpr(state, op);
1283 
1284  EEO_NEXT();
1285  }
1286 
1288  {
1289  /* too complex for an inline implementation */
1290  ExecEvalArrayCoerce(state, op, econtext);
1291 
1292  EEO_NEXT();
1293  }
1294 
1296  {
1297  /* too complex for an inline implementation */
1298  ExecEvalRow(state, op);
1299 
1300  EEO_NEXT();
1301  }
1302 
1304  {
1305  FunctionCallInfo fcinfo = op->d.rowcompare_step.fcinfo_data;
1306  Datum d;
1307 
1308  /* force NULL result if strict fn and NULL input */
1309  if (op->d.rowcompare_step.finfo->fn_strict &&
1310  (fcinfo->args[0].isnull || fcinfo->args[1].isnull))
1311  {
1312  *op->resnull = true;
1313  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1314  }
1315 
1316  /* Apply comparison function */
1317  fcinfo->isnull = false;
1318  d = op->d.rowcompare_step.fn_addr(fcinfo);
1319  *op->resvalue = d;
1320 
1321  /* force NULL result if NULL function result */
1322  if (fcinfo->isnull)
1323  {
1324  *op->resnull = true;
1325  EEO_JUMP(op->d.rowcompare_step.jumpnull);
1326  }
1327  *op->resnull = false;
1328 
1329  /* If unequal, no need to compare remaining columns */
1330  if (DatumGetInt32(*op->resvalue) != 0)
1331  {
1332  EEO_JUMP(op->d.rowcompare_step.jumpdone);
1333  }
1334 
1335  EEO_NEXT();
1336  }
1337 
1339  {
1340  int32 cmpresult = DatumGetInt32(*op->resvalue);
1341  RowCompareType rctype = op->d.rowcompare_final.rctype;
1342 
1343  *op->resnull = false;
1344  switch (rctype)
1345  {
1346  /* EQ and NE cases aren't allowed here */
1347  case ROWCOMPARE_LT:
1348  *op->resvalue = BoolGetDatum(cmpresult < 0);
1349  break;
1350  case ROWCOMPARE_LE:
1351  *op->resvalue = BoolGetDatum(cmpresult <= 0);
1352  break;
1353  case ROWCOMPARE_GE:
1354  *op->resvalue = BoolGetDatum(cmpresult >= 0);
1355  break;
1356  case ROWCOMPARE_GT:
1357  *op->resvalue = BoolGetDatum(cmpresult > 0);
1358  break;
1359  default:
1360  Assert(false);
1361  break;
1362  }
1363 
1364  EEO_NEXT();
1365  }
1366 
1368  {
1369  /* too complex for an inline implementation */
1370  ExecEvalMinMax(state, op);
1371 
1372  EEO_NEXT();
1373  }
1374 
1376  {
1377  /* too complex for an inline implementation */
1378  ExecEvalFieldSelect(state, op, econtext);
1379 
1380  EEO_NEXT();
1381  }
1382 
1384  {
1385  /* too complex for an inline implementation */
1386  ExecEvalFieldStoreDeForm(state, op, econtext);
1387 
1388  EEO_NEXT();
1389  }
1390 
1392  {
1393  /* too complex for an inline implementation */
1394  ExecEvalFieldStoreForm(state, op, econtext);
1395 
1396  EEO_NEXT();
1397  }
1398 
1400  {
1401  /* Process an array subscript */
1402 
1403  /* too complex for an inline implementation */
1404  if (ExecEvalSubscriptingRef(state, op))
1405  {
1406  EEO_NEXT();
1407  }
1408  else
1409  {
1410  /* Subscript is null, short-circuit SubscriptingRef to NULL */
1411  EEO_JUMP(op->d.sbsref_subscript.jumpdone);
1412  }
1413  }
1414 
1416  {
1417  /*
1418  * Fetch the old value in an sbsref assignment, in case it's
1419  * referenced (via a CaseTestExpr) inside the assignment
1420  * expression.
1421  */
1422 
1423  /* too complex for an inline implementation */
1424  ExecEvalSubscriptingRefOld(state, op);
1425 
1426  EEO_NEXT();
1427  }
1428 
1429  /*
1430  * Perform SubscriptingRef assignment
1431  */
1433  {
1434  /* too complex for an inline implementation */
1435  ExecEvalSubscriptingRefAssign(state, op);
1436 
1437  EEO_NEXT();
1438  }
1439 
1440  /*
1441  * Fetch subset of an array.
1442  */
1444  {
1445  /* too complex for an inline implementation */
1446  ExecEvalSubscriptingRefFetch(state, op);
1447 
1448  EEO_NEXT();
1449  }
1450 
1452  {
1453  /* too complex for an inline implementation */
1454  ExecEvalConvertRowtype(state, op, econtext);
1455 
1456  EEO_NEXT();
1457  }
1458 
1460  {
1461  /* too complex for an inline implementation */
1462  ExecEvalScalarArrayOp(state, op);
1463 
1464  EEO_NEXT();
1465  }
1466 
1468  {
1469  /* too complex for an inline implementation */
1470  ExecEvalConstraintNotNull(state, op);
1471 
1472  EEO_NEXT();
1473  }
1474 
1476  {
1477  /* too complex for an inline implementation */
1478  ExecEvalConstraintCheck(state, op);
1479 
1480  EEO_NEXT();
1481  }
1482 
1484  {
1485  /* too complex for an inline implementation */
1486  ExecEvalXmlExpr(state, op);
1487 
1488  EEO_NEXT();
1489  }
1490 
1492  {
1493  /*
1494  * Returns a Datum whose value is the precomputed aggregate value
1495  * found in the given expression context.
1496  */
1497  AggrefExprState *aggref = op->d.aggref.astate;
1498 
1499  Assert(econtext->ecxt_aggvalues != NULL);
1500 
1501  *op->resvalue = econtext->ecxt_aggvalues[aggref->aggno];
1502  *op->resnull = econtext->ecxt_aggnulls[aggref->aggno];
1503 
1504  EEO_NEXT();
1505  }
1506 
1508  {
1509  /* too complex/uncommon for an inline implementation */
1510  ExecEvalGroupingFunc(state, op);
1511 
1512  EEO_NEXT();
1513  }
1514 
1516  {
1517  /*
1518  * Like Aggref, just return a precomputed value from the econtext.
1519  */
1520  WindowFuncExprState *wfunc = op->d.window_func.wfstate;
1521 
1522  Assert(econtext->ecxt_aggvalues != NULL);
1523 
1524  *op->resvalue = econtext->ecxt_aggvalues[wfunc->wfuncno];
1525  *op->resnull = econtext->ecxt_aggnulls[wfunc->wfuncno];
1526 
1527  EEO_NEXT();
1528  }
1529 
1531  {
1532  /* too complex for an inline implementation */
1533  ExecEvalSubPlan(state, op, econtext);
1534 
1535  EEO_NEXT();
1536  }
1537 
1538  /* evaluate a strict aggregate deserialization function */
1540  {
1541  /* Don't call a strict deserialization function with NULL input */
1542  if (op->d.agg_deserialize.fcinfo_data->args[0].isnull)
1543  EEO_JUMP(op->d.agg_deserialize.jumpnull);
1544 
1545  /* fallthrough */
1546  }
1547 
1548  /* evaluate aggregate deserialization function (non-strict portion) */
1550  {
1551  FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
1552  AggState *aggstate = castNode(AggState, state->parent);
1553  MemoryContext oldContext;
1554 
1555  /*
1556  * We run the deserialization functions in per-input-tuple memory
1557  * context.
1558  */
1559  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1560  fcinfo->isnull = false;
1561  *op->resvalue = FunctionCallInvoke(fcinfo);
1562  *op->resnull = fcinfo->isnull;
1563  MemoryContextSwitchTo(oldContext);
1564 
1565  EEO_NEXT();
1566  }
1567 
1568  /*
1569  * Check that a strict aggregate transition / combination function's
1570  * input is not NULL.
1571  */
1572 
1574  {
1576  int nargs = op->d.agg_strict_input_check.nargs;
1577 
1578  for (int argno = 0; argno < nargs; argno++)
1579  {
1580  if (args[argno].isnull)
1581  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1582  }
1583  EEO_NEXT();
1584  }
1585 
1587  {
1588  bool *nulls = op->d.agg_strict_input_check.nulls;
1589  int nargs = op->d.agg_strict_input_check.nargs;
1590 
1591  for (int argno = 0; argno < nargs; argno++)
1592  {
1593  if (nulls[argno])
1594  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1595  }
1596  EEO_NEXT();
1597  }
1598 
1599  /*
1600  * Check for a NULL pointer to the per-group states.
1601  */
1602 
1604  {
1605  AggState *aggstate = castNode(AggState, state->parent);
1606  AggStatePerGroup pergroup_allaggs =
1607  aggstate->all_pergroups[op->d.agg_plain_pergroup_nullcheck.setoff];
1608 
1609  if (pergroup_allaggs == NULL)
1610  EEO_JUMP(op->d.agg_plain_pergroup_nullcheck.jumpnull);
1611 
1612  EEO_NEXT();
1613  }
1614 
1615  /*
1616  * Different types of aggregate transition functions are implemented
1617  * as different types of steps, to avoid incurring unnecessary
1618  * overhead. There's a step type for each valid combination of having
1619  * a by value / by reference transition type, [not] needing to the
1620  * initialize the transition value for the first row in a group from
1621  * input, and [not] strict transition function.
1622  *
1623  * Could optimize further by splitting off by-reference for
1624  * fixed-length types, but currently that doesn't seem worth it.
1625  */
1626 
1628  {
1629  AggState *aggstate = castNode(AggState, state->parent);
1630  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1631  AggStatePerGroup pergroup =
1632  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1633 
1634  Assert(pertrans->transtypeByVal);
1635 
1636  if (pergroup->noTransValue)
1637  {
1638  /* If transValue has not yet been initialized, do so now. */
1639  ExecAggInitGroup(aggstate, pertrans, pergroup,
1640  op->d.agg_trans.aggcontext);
1641  /* copied trans value from input, done this round */
1642  }
1643  else if (likely(!pergroup->transValueIsNull))
1644  {
1645  /* invoke transition function, unless prevented by strictness */
1646  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1647  op->d.agg_trans.aggcontext,
1648  op->d.agg_trans.setno);
1649  }
1650 
1651  EEO_NEXT();
1652  }
1653 
1654  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1656  {
1657  AggState *aggstate = castNode(AggState, state->parent);
1658  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1659  AggStatePerGroup pergroup =
1660  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1661 
1662  Assert(pertrans->transtypeByVal);
1663 
1664  if (likely(!pergroup->transValueIsNull))
1665  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1666  op->d.agg_trans.aggcontext,
1667  op->d.agg_trans.setno);
1668 
1669  EEO_NEXT();
1670  }
1671 
1672  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1674  {
1675  AggState *aggstate = castNode(AggState, state->parent);
1676  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1677  AggStatePerGroup pergroup =
1678  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1679 
1680  Assert(pertrans->transtypeByVal);
1681 
1682  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1683  op->d.agg_trans.aggcontext,
1684  op->d.agg_trans.setno);
1685 
1686  EEO_NEXT();
1687  }
1688 
1689  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1691  {
1692  AggState *aggstate = castNode(AggState, state->parent);
1693  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1694  AggStatePerGroup pergroup =
1695  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1696 
1697  Assert(!pertrans->transtypeByVal);
1698 
1699  if (pergroup->noTransValue)
1700  ExecAggInitGroup(aggstate, pertrans, pergroup,
1701  op->d.agg_trans.aggcontext);
1702  else if (likely(!pergroup->transValueIsNull))
1703  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1704  op->d.agg_trans.aggcontext,
1705  op->d.agg_trans.setno);
1706 
1707  EEO_NEXT();
1708  }
1709 
1710  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1712  {
1713  AggState *aggstate = castNode(AggState, state->parent);
1714  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1715  AggStatePerGroup pergroup =
1716  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1717 
1718  Assert(!pertrans->transtypeByVal);
1719 
1720  if (likely(!pergroup->transValueIsNull))
1721  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1722  op->d.agg_trans.aggcontext,
1723  op->d.agg_trans.setno);
1724  EEO_NEXT();
1725  }
1726 
1727  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1729  {
1730  AggState *aggstate = castNode(AggState, state->parent);
1731  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1732  AggStatePerGroup pergroup =
1733  &aggstate->all_pergroups[op->d.agg_trans.setoff][op->d.agg_trans.transno];
1734 
1735  Assert(!pertrans->transtypeByVal);
1736 
1737  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1738  op->d.agg_trans.aggcontext,
1739  op->d.agg_trans.setno);
1740 
1741  EEO_NEXT();
1742  }
1743 
1744  /* process single-column ordered aggregate datum */
1746  {
1747  /* too complex for an inline implementation */
1748  ExecEvalAggOrderedTransDatum(state, op, econtext);
1749 
1750  EEO_NEXT();
1751  }
1752 
1753  /* process multi-column ordered aggregate tuple */
1755  {
1756  /* too complex for an inline implementation */
1757  ExecEvalAggOrderedTransTuple(state, op, econtext);
1758 
1759  EEO_NEXT();
1760  }
1761 
1763  {
1764  /* unreachable */
1765  Assert(false);
1766  goto out;
1767  }
1768  }
1769 
1770 out:
1771  *isnull = state->resnull;
1772  return state->resvalue;
1773 }
1774 
1775 /*
1776  * Expression evaluation callback that performs extra checks before executing
1777  * the expression. Declared extern so other methods of execution can use it
1778  * too.
1779  */
1780 Datum
1782 {
1783  /*
1784  * First time through, check whether attribute matches Var. Might not be
1785  * ok anymore, due to schema changes.
1786  */
1787  CheckExprStillValid(state, econtext);
1788 
1789  /* skip the check during further executions */
1790  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1791 
1792  /* and actually execute */
1793  return state->evalfunc(state, econtext, isNull);
1794 }
1795 
1796 /*
1797  * Check that an expression is still valid in the face of potential schema
1798  * changes since the plan has been created.
1799  */
1800 void
1802 {
1803  TupleTableSlot *innerslot;
1804  TupleTableSlot *outerslot;
1805  TupleTableSlot *scanslot;
1806 
1807  innerslot = econtext->ecxt_innertuple;
1808  outerslot = econtext->ecxt_outertuple;
1809  scanslot = econtext->ecxt_scantuple;
1810 
1811  for (int i = 0; i < state->steps_len; i++)
1812  {
1813  ExprEvalStep *op = &state->steps[i];
1814 
1815  switch (ExecEvalStepOp(state, op))
1816  {
1817  case EEOP_INNER_VAR:
1818  {
1819  int attnum = op->d.var.attnum;
1820 
1821  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1822  break;
1823  }
1824 
1825  case EEOP_OUTER_VAR:
1826  {
1827  int attnum = op->d.var.attnum;
1828 
1829  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1830  break;
1831  }
1832 
1833  case EEOP_SCAN_VAR:
1834  {
1835  int attnum = op->d.var.attnum;
1836 
1837  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1838  break;
1839  }
1840  default:
1841  break;
1842  }
1843  }
1844 }
1845 
1846 /*
1847  * Check whether a user attribute in a slot can be referenced by a Var
1848  * expression. This should succeed unless there have been schema changes
1849  * since the expression tree has been created.
1850  */
1851 static void
1853 {
1854  /*
1855  * What we have to check for here is the possibility of an attribute
1856  * having been dropped or changed in type since the plan tree was created.
1857  * Ideally the plan will get invalidated and not re-used, but just in
1858  * case, we keep these defenses. Fortunately it's sufficient to check
1859  * once on the first time through.
1860  *
1861  * Note: ideally we'd check typmod as well as typid, but that seems
1862  * impractical at the moment: in many cases the tupdesc will have been
1863  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1864  * accurate typmod in all cases, because some expression node types don't
1865  * carry typmod. Fortunately, for precisely that reason, there should be
1866  * no places with a critical dependency on the typmod of a value.
1867  *
1868  * System attributes don't require checking since their types never
1869  * change.
1870  */
1871  if (attnum > 0)
1872  {
1873  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1874  Form_pg_attribute attr;
1875 
1876  if (attnum > slot_tupdesc->natts) /* should never happen */
1877  elog(ERROR, "attribute number %d exceeds number of columns %d",
1878  attnum, slot_tupdesc->natts);
1879 
1880  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
1881 
1882  if (attr->attisdropped)
1883  ereport(ERROR,
1884  (errcode(ERRCODE_UNDEFINED_COLUMN),
1885  errmsg("attribute %d of type %s has been dropped",
1886  attnum, format_type_be(slot_tupdesc->tdtypeid))));
1887 
1888  if (vartype != attr->atttypid)
1889  ereport(ERROR,
1890  (errcode(ERRCODE_DATATYPE_MISMATCH),
1891  errmsg("attribute %d of type %s has wrong type",
1892  attnum, format_type_be(slot_tupdesc->tdtypeid)),
1893  errdetail("Table has type %s, but query expects %s.",
1894  format_type_be(attr->atttypid),
1895  format_type_be(vartype))));
1896  }
1897 }
1898 
1899 /*
1900  * Verify that the slot is compatible with a EEOP_*_FETCHSOME operation.
1901  */
1902 static void
1904 {
1905 #ifdef USE_ASSERT_CHECKING
1906  /* there's nothing to check */
1907  if (!op->d.fetch.fixed)
1908  return;
1909 
1910  /*
1911  * Should probably fixed at some point, but for now it's easier to allow
1912  * buffer and heap tuples to be used interchangeably.
1913  */
1914  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1915  op->d.fetch.kind == &TTSOpsHeapTuple)
1916  return;
1917  if (slot->tts_ops == &TTSOpsHeapTuple &&
1918  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1919  return;
1920 
1921  /*
1922  * At the moment we consider it OK if a virtual slot is used instead of a
1923  * specific type of slot, as a virtual slot never needs to be deformed.
1924  */
1925  if (slot->tts_ops == &TTSOpsVirtual)
1926  return;
1927 
1928  Assert(op->d.fetch.kind == slot->tts_ops);
1929 #endif
1930 }
1931 
1932 /*
1933  * get_cached_rowtype: utility function to lookup a rowtype tupdesc
1934  *
1935  * type_id, typmod: identity of the rowtype
1936  * cache_field: where to cache the TupleDesc pointer in expression state node
1937  * (field must be initialized to NULL)
1938  * econtext: expression context we are executing in
1939  *
1940  * NOTE: because the shutdown callback will be called during plan rescan,
1941  * must be prepared to re-do this during any node execution; cannot call
1942  * just once during expression initialization.
1943  */
1944 static TupleDesc
1945 get_cached_rowtype(Oid type_id, int32 typmod,
1946  TupleDesc *cache_field, ExprContext *econtext)
1947 {
1948  TupleDesc tupDesc = *cache_field;
1949 
1950  /* Do lookup if no cached value or if requested type changed */
1951  if (tupDesc == NULL ||
1952  type_id != tupDesc->tdtypeid ||
1953  typmod != tupDesc->tdtypmod)
1954  {
1955  tupDesc = lookup_rowtype_tupdesc(type_id, typmod);
1956 
1957  if (*cache_field)
1958  {
1959  /* Release old tupdesc; but callback is already registered */
1960  ReleaseTupleDesc(*cache_field);
1961  }
1962  else
1963  {
1964  /* Need to register shutdown callback to release tupdesc */
1965  RegisterExprContextCallback(econtext,
1967  PointerGetDatum(cache_field));
1968  }
1969  *cache_field = tupDesc;
1970  }
1971  return tupDesc;
1972 }
1973 
1974 /*
1975  * Callback function to release a tupdesc refcount at econtext shutdown
1976  */
1977 static void
1979 {
1980  TupleDesc *cache_field = (TupleDesc *) DatumGetPointer(arg);
1981 
1982  if (*cache_field)
1983  ReleaseTupleDesc(*cache_field);
1984  *cache_field = NULL;
1985 }
1986 
1987 /*
1988  * Fast-path functions, for very simple expressions
1989  */
1990 
1991 /* implementation of ExecJust(Inner|Outer|Scan)Var */
1994 {
1995  ExprEvalStep *op = &state->steps[1];
1996  int attnum = op->d.var.attnum + 1;
1997 
1998  CheckOpSlotCompatibility(&state->steps[0], slot);
1999 
2000  /*
2001  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2002  * step explicitly, and we also needn't Assert that the attnum is in range
2003  * --- slot_getattr() will take care of any problems.
2004  */
2005  return slot_getattr(slot, attnum, isnull);
2006 }
2007 
2008 /* Simple reference to inner Var */
2009 static Datum
2010 ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
2011 {
2012  return ExecJustVarImpl(state, econtext->ecxt_innertuple, isnull);
2013 }
2014 
2015 /* Simple reference to outer Var */
2016 static Datum
2017 ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
2018 {
2019  return ExecJustVarImpl(state, econtext->ecxt_outertuple, isnull);
2020 }
2021 
2022 /* Simple reference to scan Var */
2023 static Datum
2024 ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
2025 {
2026  return ExecJustVarImpl(state, econtext->ecxt_scantuple, isnull);
2027 }
2028 
2029 /* implementation of ExecJustAssign(Inner|Outer|Scan)Var */
2032 {
2033  ExprEvalStep *op = &state->steps[1];
2034  int attnum = op->d.assign_var.attnum + 1;
2035  int resultnum = op->d.assign_var.resultnum;
2036  TupleTableSlot *outslot = state->resultslot;
2037 
2038  CheckOpSlotCompatibility(&state->steps[0], inslot);
2039 
2040  /*
2041  * We do not need CheckVarSlotCompatibility here; that was taken care of
2042  * at compilation time.
2043  *
2044  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2045  * step explicitly, and we also needn't Assert that the attnum is in range
2046  * --- slot_getattr() will take care of any problems.
2047  */
2048  outslot->tts_values[resultnum] =
2049  slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2050  return 0;
2051 }
2052 
2053 /* Evaluate inner Var and assign to appropriate column of result tuple */
2054 static Datum
2056 {
2057  return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2058 }
2059 
2060 /* Evaluate outer Var and assign to appropriate column of result tuple */
2061 static Datum
2063 {
2064  return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2065 }
2066 
2067 /* Evaluate scan Var and assign to appropriate column of result tuple */
2068 static Datum
2070 {
2071  return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2072 }
2073 
2074 /* Evaluate CASE_TESTVAL and apply a strict function to it */
2075 static Datum
2077 {
2078  ExprEvalStep *op = &state->steps[0];
2079  FunctionCallInfo fcinfo;
2081  int nargs;
2082  Datum d;
2083 
2084  /*
2085  * XXX with some redesign of the CaseTestExpr mechanism, maybe we could
2086  * get rid of this data shuffling?
2087  */
2088  *op->resvalue = *op->d.casetest.value;
2089  *op->resnull = *op->d.casetest.isnull;
2090 
2091  op++;
2092 
2093  nargs = op->d.func.nargs;
2094  fcinfo = op->d.func.fcinfo_data;
2095  args = fcinfo->args;
2096 
2097  /* strict function, so check for NULL args */
2098  for (int argno = 0; argno < nargs; argno++)
2099  {
2100  if (args[argno].isnull)
2101  {
2102  *isnull = true;
2103  return (Datum) 0;
2104  }
2105  }
2106  fcinfo->isnull = false;
2107  d = op->d.func.fn_addr(fcinfo);
2108  *isnull = fcinfo->isnull;
2109  return d;
2110 }
2111 
2112 /* Simple Const expression */
2113 static Datum
2114 ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
2115 {
2116  ExprEvalStep *op = &state->steps[0];
2117 
2118  *isnull = op->d.constval.isnull;
2119  return op->d.constval.value;
2120 }
2121 
2122 /* implementation of ExecJust(Inner|Outer|Scan)VarVirt */
2125 {
2126  ExprEvalStep *op = &state->steps[0];
2127  int attnum = op->d.var.attnum;
2128 
2129  /*
2130  * As it is guaranteed that a virtual slot is used, there never is a need
2131  * to perform tuple deforming (nor would it be possible). Therefore
2132  * execExpr.c has not emitted an EEOP_*_FETCHSOME step. Verify, as much as
2133  * possible, that that determination was accurate.
2134  */
2135  Assert(TTS_IS_VIRTUAL(slot));
2136  Assert(TTS_FIXED(slot));
2137  Assert(attnum >= 0 && attnum < slot->tts_nvalid);
2138 
2139  *isnull = slot->tts_isnull[attnum];
2140 
2141  return slot->tts_values[attnum];
2142 }
2143 
2144 /* Like ExecJustInnerVar, optimized for virtual slots */
2145 static Datum
2147 {
2148  return ExecJustVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2149 }
2150 
2151 /* Like ExecJustOuterVar, optimized for virtual slots */
2152 static Datum
2154 {
2155  return ExecJustVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2156 }
2157 
2158 /* Like ExecJustScanVar, optimized for virtual slots */
2159 static Datum
2161 {
2162  return ExecJustVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2163 }
2164 
2165 /* implementation of ExecJustAssign(Inner|Outer|Scan)VarVirt */
2168 {
2169  ExprEvalStep *op = &state->steps[0];
2170  int attnum = op->d.assign_var.attnum;
2171  int resultnum = op->d.assign_var.resultnum;
2172  TupleTableSlot *outslot = state->resultslot;
2173 
2174  /* see ExecJustVarVirtImpl for comments */
2175 
2176  Assert(TTS_IS_VIRTUAL(inslot));
2177  Assert(TTS_FIXED(inslot));
2178  Assert(attnum >= 0 && attnum < inslot->tts_nvalid);
2179 
2180  outslot->tts_values[resultnum] = inslot->tts_values[attnum];
2181  outslot->tts_isnull[resultnum] = inslot->tts_isnull[attnum];
2182 
2183  return 0;
2184 }
2185 
2186 /* Like ExecJustAssignInnerVar, optimized for virtual slots */
2187 static Datum
2189 {
2190  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2191 }
2192 
2193 /* Like ExecJustAssignOuterVar, optimized for virtual slots */
2194 static Datum
2196 {
2197  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2198 }
2199 
2200 /* Like ExecJustAssignScanVar, optimized for virtual slots */
2201 static Datum
2203 {
2204  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2205 }
2206 
2207 #if defined(EEO_USE_COMPUTED_GOTO)
2208 /*
2209  * Comparator used when building address->opcode lookup table for
2210  * ExecEvalStepOp() in the threaded dispatch case.
2211  */
2212 static int
2213 dispatch_compare_ptr(const void *a, const void *b)
2214 {
2215  const ExprEvalOpLookup *la = (const ExprEvalOpLookup *) a;
2216  const ExprEvalOpLookup *lb = (const ExprEvalOpLookup *) b;
2217 
2218  if (la->opcode < lb->opcode)
2219  return -1;
2220  else if (la->opcode > lb->opcode)
2221  return 1;
2222  return 0;
2223 }
2224 #endif
2225 
2226 /*
2227  * Do one-time initialization of interpretation machinery.
2228  */
2229 static void
2231 {
2232 #if defined(EEO_USE_COMPUTED_GOTO)
2233  /* Set up externally-visible pointer to dispatch table */
2234  if (dispatch_table == NULL)
2235  {
2236  dispatch_table = (const void **)
2237  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2238 
2239  /* build reverse lookup table */
2240  for (int i = 0; i < EEOP_LAST; i++)
2241  {
2242  reverse_dispatch_table[i].opcode = dispatch_table[i];
2243  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2244  }
2245 
2246  /* make it bsearch()able */
2247  qsort(reverse_dispatch_table,
2248  EEOP_LAST /* nmembers */ ,
2249  sizeof(ExprEvalOpLookup),
2250  dispatch_compare_ptr);
2251  }
2252 #endif
2253 }
2254 
2255 /*
2256  * Function to return the opcode of an expression step.
2257  *
2258  * When direct-threading is in use, ExprState->opcode isn't easily
2259  * decipherable. This function returns the appropriate enum member.
2260  */
2261 ExprEvalOp
2263 {
2264 #if defined(EEO_USE_COMPUTED_GOTO)
2265  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2266  {
2267  ExprEvalOpLookup key;
2268  ExprEvalOpLookup *res;
2269 
2270  key.opcode = (void *) op->opcode;
2271  res = bsearch(&key,
2272  reverse_dispatch_table,
2273  EEOP_LAST /* nmembers */ ,
2274  sizeof(ExprEvalOpLookup),
2275  dispatch_compare_ptr);
2276  Assert(res); /* unknown ops shouldn't get looked up */
2277  return res->op;
2278  }
2279 #endif
2280  return (ExprEvalOp) op->opcode;
2281 }
2282 
2283 
2284 /*
2285  * Out-of-line helper functions for complex instructions.
2286  */
2287 
2288 /*
2289  * Evaluate EEOP_FUNCEXPR_FUSAGE
2290  */
2291 void
2293  ExprContext *econtext)
2294 {
2295  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2296  PgStat_FunctionCallUsage fcusage;
2297  Datum d;
2298 
2299  pgstat_init_function_usage(fcinfo, &fcusage);
2300 
2301  fcinfo->isnull = false;
2302  d = op->d.func.fn_addr(fcinfo);
2303  *op->resvalue = d;
2304  *op->resnull = fcinfo->isnull;
2305 
2306  pgstat_end_function_usage(&fcusage, true);
2307 }
2308 
2309 /*
2310  * Evaluate EEOP_FUNCEXPR_STRICT_FUSAGE
2311  */
2312 void
2314  ExprContext *econtext)
2315 {
2316 
2317  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2318  PgStat_FunctionCallUsage fcusage;
2319  NullableDatum *args = fcinfo->args;
2320  int nargs = op->d.func.nargs;
2321  Datum d;
2322 
2323  /* strict function, so check for NULL args */
2324  for (int argno = 0; argno < nargs; argno++)
2325  {
2326  if (args[argno].isnull)
2327  {
2328  *op->resnull = true;
2329  return;
2330  }
2331  }
2332 
2333  pgstat_init_function_usage(fcinfo, &fcusage);
2334 
2335  fcinfo->isnull = false;
2336  d = op->d.func.fn_addr(fcinfo);
2337  *op->resvalue = d;
2338  *op->resnull = fcinfo->isnull;
2339 
2340  pgstat_end_function_usage(&fcusage, true);
2341 }
2342 
2343 /*
2344  * Evaluate a PARAM_EXEC parameter.
2345  *
2346  * PARAM_EXEC params (internal executor parameters) are stored in the
2347  * ecxt_param_exec_vals array, and can be accessed by array index.
2348  */
2349 void
2351 {
2352  ParamExecData *prm;
2353 
2354  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2355  if (unlikely(prm->execPlan != NULL))
2356  {
2357  /* Parameter not evaluated yet, so go do it */
2358  ExecSetParamPlan(prm->execPlan, econtext);
2359  /* ExecSetParamPlan should have processed this param... */
2360  Assert(prm->execPlan == NULL);
2361  }
2362  *op->resvalue = prm->value;
2363  *op->resnull = prm->isnull;
2364 }
2365 
2366 /*
2367  * Evaluate a PARAM_EXTERN parameter.
2368  *
2369  * PARAM_EXTERN parameters must be sought in ecxt_param_list_info.
2370  */
2371 void
2373 {
2374  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2375  int paramId = op->d.param.paramid;
2376 
2377  if (likely(paramInfo &&
2378  paramId > 0 && paramId <= paramInfo->numParams))
2379  {
2380  ParamExternData *prm;
2381  ParamExternData prmdata;
2382 
2383  /* give hook a chance in case parameter is dynamic */
2384  if (paramInfo->paramFetch != NULL)
2385  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2386  else
2387  prm = &paramInfo->params[paramId - 1];
2388 
2389  if (likely(OidIsValid(prm->ptype)))
2390  {
2391  /* safety check in case hook did something unexpected */
2392  if (unlikely(prm->ptype != op->d.param.paramtype))
2393  ereport(ERROR,
2394  (errcode(ERRCODE_DATATYPE_MISMATCH),
2395  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2396  paramId,
2397  format_type_be(prm->ptype),
2398  format_type_be(op->d.param.paramtype))));
2399  *op->resvalue = prm->value;
2400  *op->resnull = prm->isnull;
2401  return;
2402  }
2403  }
2404 
2405  ereport(ERROR,
2406  (errcode(ERRCODE_UNDEFINED_OBJECT),
2407  errmsg("no value found for parameter %d", paramId)));
2408 }
2409 
2410 /*
2411  * Evaluate a SQLValueFunction expression.
2412  */
2413 void
2415 {
2416  LOCAL_FCINFO(fcinfo, 0);
2417  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2418 
2419  *op->resnull = false;
2420 
2421  /*
2422  * Note: current_schema() can return NULL. current_user() etc currently
2423  * cannot, but might as well code those cases the same way for safety.
2424  */
2425  switch (svf->op)
2426  {
2427  case SVFOP_CURRENT_DATE:
2429  break;
2430  case SVFOP_CURRENT_TIME:
2431  case SVFOP_CURRENT_TIME_N:
2433  break;
2437  break;
2438  case SVFOP_LOCALTIME:
2439  case SVFOP_LOCALTIME_N:
2441  break;
2442  case SVFOP_LOCALTIMESTAMP:
2445  break;
2446  case SVFOP_CURRENT_ROLE:
2447  case SVFOP_CURRENT_USER:
2448  case SVFOP_USER:
2449  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2450  *op->resvalue = current_user(fcinfo);
2451  *op->resnull = fcinfo->isnull;
2452  break;
2453  case SVFOP_SESSION_USER:
2454  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2455  *op->resvalue = session_user(fcinfo);
2456  *op->resnull = fcinfo->isnull;
2457  break;
2458  case SVFOP_CURRENT_CATALOG:
2459  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2460  *op->resvalue = current_database(fcinfo);
2461  *op->resnull = fcinfo->isnull;
2462  break;
2463  case SVFOP_CURRENT_SCHEMA:
2464  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2465  *op->resvalue = current_schema(fcinfo);
2466  *op->resnull = fcinfo->isnull;
2467  break;
2468  }
2469 }
2470 
2471 /*
2472  * Raise error if a CURRENT OF expression is evaluated.
2473  *
2474  * The planner should convert CURRENT OF into a TidScan qualification, or some
2475  * other special handling in a ForeignScan node. So we have to be able to do
2476  * ExecInitExpr on a CurrentOfExpr, but we shouldn't ever actually execute it.
2477  * If we get here, we suppose we must be dealing with CURRENT OF on a foreign
2478  * table whose FDW doesn't handle it, and complain accordingly.
2479  */
2480 void
2482 {
2483  ereport(ERROR,
2484  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2485  errmsg("WHERE CURRENT OF is not supported for this table type")));
2486 }
2487 
2488 /*
2489  * Evaluate NextValueExpr.
2490  */
2491 void
2493 {
2494  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2495 
2496  switch (op->d.nextvalueexpr.seqtypid)
2497  {
2498  case INT2OID:
2499  *op->resvalue = Int16GetDatum((int16) newval);
2500  break;
2501  case INT4OID:
2502  *op->resvalue = Int32GetDatum((int32) newval);
2503  break;
2504  case INT8OID:
2505  *op->resvalue = Int64GetDatum((int64) newval);
2506  break;
2507  default:
2508  elog(ERROR, "unsupported sequence type %u",
2509  op->d.nextvalueexpr.seqtypid);
2510  }
2511  *op->resnull = false;
2512 }
2513 
2514 /*
2515  * Evaluate NullTest / IS NULL for rows.
2516  */
2517 void
2519 {
2520  ExecEvalRowNullInt(state, op, econtext, true);
2521 }
2522 
2523 /*
2524  * Evaluate NullTest / IS NOT NULL for rows.
2525  */
2526 void
2528 {
2529  ExecEvalRowNullInt(state, op, econtext, false);
2530 }
2531 
2532 /* Common code for IS [NOT] NULL on a row value */
2533 static void
2535  ExprContext *econtext, bool checkisnull)
2536 {
2537  Datum value = *op->resvalue;
2538  bool isnull = *op->resnull;
2539  HeapTupleHeader tuple;
2540  Oid tupType;
2541  int32 tupTypmod;
2542  TupleDesc tupDesc;
2543  HeapTupleData tmptup;
2544 
2545  *op->resnull = false;
2546 
2547  /* NULL row variables are treated just as NULL scalar columns */
2548  if (isnull)
2549  {
2550  *op->resvalue = BoolGetDatum(checkisnull);
2551  return;
2552  }
2553 
2554  /*
2555  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2556  * as:
2557  *
2558  * "R IS NULL" is true if every field is the null value.
2559  *
2560  * "R IS NOT NULL" is true if no field is the null value.
2561  *
2562  * This definition is (apparently intentionally) not recursive; so our
2563  * tests on the fields are primitive attisnull tests, not recursive checks
2564  * to see if they are all-nulls or no-nulls rowtypes.
2565  *
2566  * The standard does not consider the possibility of zero-field rows, but
2567  * here we consider them to vacuously satisfy both predicates.
2568  */
2569 
2570  tuple = DatumGetHeapTupleHeader(value);
2571 
2572  tupType = HeapTupleHeaderGetTypeId(tuple);
2573  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2574 
2575  /* Lookup tupdesc if first time through or if type changes */
2576  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2577  &op->d.nulltest_row.argdesc,
2578  econtext);
2579 
2580  /*
2581  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2582  */
2583  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2584  tmptup.t_data = tuple;
2585 
2586  for (int att = 1; att <= tupDesc->natts; att++)
2587  {
2588  /* ignore dropped columns */
2589  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2590  continue;
2591  if (heap_attisnull(&tmptup, att, tupDesc))
2592  {
2593  /* null field disproves IS NOT NULL */
2594  if (!checkisnull)
2595  {
2596  *op->resvalue = BoolGetDatum(false);
2597  return;
2598  }
2599  }
2600  else
2601  {
2602  /* non-null field disproves IS NULL */
2603  if (checkisnull)
2604  {
2605  *op->resvalue = BoolGetDatum(false);
2606  return;
2607  }
2608  }
2609  }
2610 
2611  *op->resvalue = BoolGetDatum(true);
2612 }
2613 
2614 /*
2615  * Evaluate an ARRAY[] expression.
2616  *
2617  * The individual array elements (or subarrays) have already been evaluated
2618  * into op->d.arrayexpr.elemvalues[]/elemnulls[].
2619  */
2620 void
2622 {
2623  ArrayType *result;
2624  Oid element_type = op->d.arrayexpr.elemtype;
2625  int nelems = op->d.arrayexpr.nelems;
2626  int ndims = 0;
2627  int dims[MAXDIM];
2628  int lbs[MAXDIM];
2629 
2630  /* Set non-null as default */
2631  *op->resnull = false;
2632 
2633  if (!op->d.arrayexpr.multidims)
2634  {
2635  /* Elements are presumably of scalar type */
2636  Datum *dvalues = op->d.arrayexpr.elemvalues;
2637  bool *dnulls = op->d.arrayexpr.elemnulls;
2638 
2639  /* setup for 1-D array of the given length */
2640  ndims = 1;
2641  dims[0] = nelems;
2642  lbs[0] = 1;
2643 
2644  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2645  element_type,
2646  op->d.arrayexpr.elemlength,
2647  op->d.arrayexpr.elembyval,
2648  op->d.arrayexpr.elemalign);
2649  }
2650  else
2651  {
2652  /* Must be nested array expressions */
2653  int nbytes = 0;
2654  int nitems = 0;
2655  int outer_nelems = 0;
2656  int elem_ndims = 0;
2657  int *elem_dims = NULL;
2658  int *elem_lbs = NULL;
2659  bool firstone = true;
2660  bool havenulls = false;
2661  bool haveempty = false;
2662  char **subdata;
2663  bits8 **subbitmaps;
2664  int *subbytes;
2665  int *subnitems;
2666  int32 dataoffset;
2667  char *dat;
2668  int iitem;
2669 
2670  subdata = (char **) palloc(nelems * sizeof(char *));
2671  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2672  subbytes = (int *) palloc(nelems * sizeof(int));
2673  subnitems = (int *) palloc(nelems * sizeof(int));
2674 
2675  /* loop through and get data area from each element */
2676  for (int elemoff = 0; elemoff < nelems; elemoff++)
2677  {
2678  Datum arraydatum;
2679  bool eisnull;
2680  ArrayType *array;
2681  int this_ndims;
2682 
2683  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2684  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2685 
2686  /* temporarily ignore null subarrays */
2687  if (eisnull)
2688  {
2689  haveempty = true;
2690  continue;
2691  }
2692 
2693  array = DatumGetArrayTypeP(arraydatum);
2694 
2695  /* run-time double-check on element type */
2696  if (element_type != ARR_ELEMTYPE(array))
2697  ereport(ERROR,
2698  (errcode(ERRCODE_DATATYPE_MISMATCH),
2699  errmsg("cannot merge incompatible arrays"),
2700  errdetail("Array with element type %s cannot be "
2701  "included in ARRAY construct with element type %s.",
2702  format_type_be(ARR_ELEMTYPE(array)),
2703  format_type_be(element_type))));
2704 
2705  this_ndims = ARR_NDIM(array);
2706  /* temporarily ignore zero-dimensional subarrays */
2707  if (this_ndims <= 0)
2708  {
2709  haveempty = true;
2710  continue;
2711  }
2712 
2713  if (firstone)
2714  {
2715  /* Get sub-array details from first member */
2716  elem_ndims = this_ndims;
2717  ndims = elem_ndims + 1;
2718  if (ndims <= 0 || ndims > MAXDIM)
2719  ereport(ERROR,
2720  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2721  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2722  ndims, MAXDIM)));
2723 
2724  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2725  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2726  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2727  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2728 
2729  firstone = false;
2730  }
2731  else
2732  {
2733  /* Check other sub-arrays are compatible */
2734  if (elem_ndims != this_ndims ||
2735  memcmp(elem_dims, ARR_DIMS(array),
2736  elem_ndims * sizeof(int)) != 0 ||
2737  memcmp(elem_lbs, ARR_LBOUND(array),
2738  elem_ndims * sizeof(int)) != 0)
2739  ereport(ERROR,
2740  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2741  errmsg("multidimensional arrays must have array "
2742  "expressions with matching dimensions")));
2743  }
2744 
2745  subdata[outer_nelems] = ARR_DATA_PTR(array);
2746  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2747  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2748  nbytes += subbytes[outer_nelems];
2749  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2750  ARR_DIMS(array));
2751  nitems += subnitems[outer_nelems];
2752  havenulls |= ARR_HASNULL(array);
2753  outer_nelems++;
2754  }
2755 
2756  /*
2757  * If all items were null or empty arrays, return an empty array;
2758  * otherwise, if some were and some weren't, raise error. (Note: we
2759  * must special-case this somehow to avoid trying to generate a 1-D
2760  * array formed from empty arrays. It's not ideal...)
2761  */
2762  if (haveempty)
2763  {
2764  if (ndims == 0) /* didn't find any nonempty array */
2765  {
2766  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2767  return;
2768  }
2769  ereport(ERROR,
2770  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2771  errmsg("multidimensional arrays must have array "
2772  "expressions with matching dimensions")));
2773  }
2774 
2775  /* setup for multi-D array */
2776  dims[0] = outer_nelems;
2777  lbs[0] = 1;
2778  for (int i = 1; i < ndims; i++)
2779  {
2780  dims[i] = elem_dims[i - 1];
2781  lbs[i] = elem_lbs[i - 1];
2782  }
2783 
2784  if (havenulls)
2785  {
2786  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2787  nbytes += dataoffset;
2788  }
2789  else
2790  {
2791  dataoffset = 0; /* marker for no null bitmap */
2792  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2793  }
2794 
2795  result = (ArrayType *) palloc(nbytes);
2796  SET_VARSIZE(result, nbytes);
2797  result->ndim = ndims;
2798  result->dataoffset = dataoffset;
2799  result->elemtype = element_type;
2800  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2801  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2802 
2803  dat = ARR_DATA_PTR(result);
2804  iitem = 0;
2805  for (int i = 0; i < outer_nelems; i++)
2806  {
2807  memcpy(dat, subdata[i], subbytes[i]);
2808  dat += subbytes[i];
2809  if (havenulls)
2810  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2811  subbitmaps[i], 0,
2812  subnitems[i]);
2813  iitem += subnitems[i];
2814  }
2815  }
2816 
2817  *op->resvalue = PointerGetDatum(result);
2818 }
2819 
2820 /*
2821  * Evaluate an ArrayCoerceExpr expression.
2822  *
2823  * Source array is in step's result variable.
2824  */
2825 void
2827 {
2828  Datum arraydatum;
2829 
2830  /* NULL array -> NULL result */
2831  if (*op->resnull)
2832  return;
2833 
2834  arraydatum = *op->resvalue;
2835 
2836  /*
2837  * If it's binary-compatible, modify the element type in the array header,
2838  * but otherwise leave the array as we received it.
2839  */
2840  if (op->d.arraycoerce.elemexprstate == NULL)
2841  {
2842  /* Detoast input array if necessary, and copy in any case */
2843  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2844 
2845  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2846  *op->resvalue = PointerGetDatum(array);
2847  return;
2848  }
2849 
2850  /*
2851  * Use array_map to apply the sub-expression to each array element.
2852  */
2853  *op->resvalue = array_map(arraydatum,
2854  op->d.arraycoerce.elemexprstate,
2855  econtext,
2856  op->d.arraycoerce.resultelemtype,
2857  op->d.arraycoerce.amstate);
2858 }
2859 
2860 /*
2861  * Evaluate a ROW() expression.
2862  *
2863  * The individual columns have already been evaluated into
2864  * op->d.row.elemvalues[]/elemnulls[].
2865  */
2866 void
2868 {
2869  HeapTuple tuple;
2870 
2871  /* build tuple from evaluated field values */
2872  tuple = heap_form_tuple(op->d.row.tupdesc,
2873  op->d.row.elemvalues,
2874  op->d.row.elemnulls);
2875 
2876  *op->resvalue = HeapTupleGetDatum(tuple);
2877  *op->resnull = false;
2878 }
2879 
2880 /*
2881  * Evaluate GREATEST() or LEAST() expression (note this is *not* MIN()/MAX()).
2882  *
2883  * All of the to-be-compared expressions have already been evaluated into
2884  * op->d.minmax.values[]/nulls[].
2885  */
2886 void
2888 {
2889  Datum *values = op->d.minmax.values;
2890  bool *nulls = op->d.minmax.nulls;
2891  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2892  MinMaxOp operator = op->d.minmax.op;
2893 
2894  /* set at initialization */
2895  Assert(fcinfo->args[0].isnull == false);
2896  Assert(fcinfo->args[1].isnull == false);
2897 
2898  /* default to null result */
2899  *op->resnull = true;
2900 
2901  for (int off = 0; off < op->d.minmax.nelems; off++)
2902  {
2903  /* ignore NULL inputs */
2904  if (nulls[off])
2905  continue;
2906 
2907  if (*op->resnull)
2908  {
2909  /* first nonnull input, adopt value */
2910  *op->resvalue = values[off];
2911  *op->resnull = false;
2912  }
2913  else
2914  {
2915  int cmpresult;
2916 
2917  /* apply comparison function */
2918  fcinfo->args[0].value = *op->resvalue;
2919  fcinfo->args[1].value = values[off];
2920 
2921  fcinfo->isnull = false;
2922  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2923  if (fcinfo->isnull) /* probably should not happen */
2924  continue;
2925 
2926  if (cmpresult > 0 && operator == IS_LEAST)
2927  *op->resvalue = values[off];
2928  else if (cmpresult < 0 && operator == IS_GREATEST)
2929  *op->resvalue = values[off];
2930  }
2931  }
2932 }
2933 
2934 /*
2935  * Evaluate a FieldSelect node.
2936  *
2937  * Source record is in step's result variable.
2938  */
2939 void
2941 {
2942  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2943  Datum tupDatum;
2944  HeapTupleHeader tuple;
2945  Oid tupType;
2946  int32 tupTypmod;
2947  TupleDesc tupDesc;
2948  Form_pg_attribute attr;
2949  HeapTupleData tmptup;
2950 
2951  /* NULL record -> NULL result */
2952  if (*op->resnull)
2953  return;
2954 
2955  tupDatum = *op->resvalue;
2956 
2957  /* We can special-case expanded records for speed */
2959  {
2961 
2962  Assert(erh->er_magic == ER_MAGIC);
2963 
2964  /* Extract record's TupleDesc */
2965  tupDesc = expanded_record_get_tupdesc(erh);
2966 
2967  /*
2968  * Find field's attr record. Note we don't support system columns
2969  * here: a datum tuple doesn't have valid values for most of the
2970  * interesting system columns anyway.
2971  */
2972  if (fieldnum <= 0) /* should never happen */
2973  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2974  fieldnum);
2975  if (fieldnum > tupDesc->natts) /* should never happen */
2976  elog(ERROR, "attribute number %d exceeds number of columns %d",
2977  fieldnum, tupDesc->natts);
2978  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2979 
2980  /* Check for dropped column, and force a NULL result if so */
2981  if (attr->attisdropped)
2982  {
2983  *op->resnull = true;
2984  return;
2985  }
2986 
2987  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
2988  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
2989  if (op->d.fieldselect.resulttype != attr->atttypid)
2990  ereport(ERROR,
2991  (errcode(ERRCODE_DATATYPE_MISMATCH),
2992  errmsg("attribute %d has wrong type", fieldnum),
2993  errdetail("Table has type %s, but query expects %s.",
2994  format_type_be(attr->atttypid),
2995  format_type_be(op->d.fieldselect.resulttype))));
2996 
2997  /* extract the field */
2998  *op->resvalue = expanded_record_get_field(erh, fieldnum,
2999  op->resnull);
3000  }
3001  else
3002  {
3003  /* Get the composite datum and extract its type fields */
3004  tuple = DatumGetHeapTupleHeader(tupDatum);
3005 
3006  tupType = HeapTupleHeaderGetTypeId(tuple);
3007  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3008 
3009  /* Lookup tupdesc if first time through or if type changes */
3010  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3011  &op->d.fieldselect.argdesc,
3012  econtext);
3013 
3014  /*
3015  * Find field's attr record. Note we don't support system columns
3016  * here: a datum tuple doesn't have valid values for most of the
3017  * interesting system columns anyway.
3018  */
3019  if (fieldnum <= 0) /* should never happen */
3020  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3021  fieldnum);
3022  if (fieldnum > tupDesc->natts) /* should never happen */
3023  elog(ERROR, "attribute number %d exceeds number of columns %d",
3024  fieldnum, tupDesc->natts);
3025  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3026 
3027  /* Check for dropped column, and force a NULL result if so */
3028  if (attr->attisdropped)
3029  {
3030  *op->resnull = true;
3031  return;
3032  }
3033 
3034  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3035  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3036  if (op->d.fieldselect.resulttype != attr->atttypid)
3037  ereport(ERROR,
3038  (errcode(ERRCODE_DATATYPE_MISMATCH),
3039  errmsg("attribute %d has wrong type", fieldnum),
3040  errdetail("Table has type %s, but query expects %s.",
3041  format_type_be(attr->atttypid),
3042  format_type_be(op->d.fieldselect.resulttype))));
3043 
3044  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3045  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3046  tmptup.t_data = tuple;
3047 
3048  /* extract the field */
3049  *op->resvalue = heap_getattr(&tmptup,
3050  fieldnum,
3051  tupDesc,
3052  op->resnull);
3053  }
3054 }
3055 
3056 /*
3057  * Deform source tuple, filling in the step's values/nulls arrays, before
3058  * evaluating individual new values as part of a FieldStore expression.
3059  * Subsequent steps will overwrite individual elements of the values/nulls
3060  * arrays with the new field values, and then FIELDSTORE_FORM will build the
3061  * new tuple value.
3062  *
3063  * Source record is in step's result variable.
3064  */
3065 void
3067 {
3068  TupleDesc tupDesc;
3069 
3070  /* Lookup tupdesc if first time through or after rescan */
3071  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3072  op->d.fieldstore.argdesc, econtext);
3073 
3074  /* Check that current tupdesc doesn't have more fields than we allocated */
3075  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3076  elog(ERROR, "too many columns in composite type %u",
3077  op->d.fieldstore.fstore->resulttype);
3078 
3079  if (*op->resnull)
3080  {
3081  /* Convert null input tuple into an all-nulls row */
3082  memset(op->d.fieldstore.nulls, true,
3083  op->d.fieldstore.ncolumns * sizeof(bool));
3084  }
3085  else
3086  {
3087  /*
3088  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3089  * set all the fields in the struct just in case.
3090  */
3091  Datum tupDatum = *op->resvalue;
3092  HeapTupleHeader tuphdr;
3093  HeapTupleData tmptup;
3094 
3095  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3096  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3097  ItemPointerSetInvalid(&(tmptup.t_self));
3098  tmptup.t_tableOid = InvalidOid;
3099  tmptup.t_data = tuphdr;
3100 
3101  heap_deform_tuple(&tmptup, tupDesc,
3102  op->d.fieldstore.values,
3103  op->d.fieldstore.nulls);
3104  }
3105 }
3106 
3107 /*
3108  * Compute the new composite datum after each individual field value of a
3109  * FieldStore expression has been evaluated.
3110  */
3111 void
3113 {
3114  HeapTuple tuple;
3115 
3116  /* argdesc should already be valid from the DeForm step */
3117  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3118  op->d.fieldstore.values,
3119  op->d.fieldstore.nulls);
3120 
3121  *op->resvalue = HeapTupleGetDatum(tuple);
3122  *op->resnull = false;
3123 }
3124 
3125 /*
3126  * Process a subscript in a SubscriptingRef expression.
3127  *
3128  * If subscript is NULL, throw error in assignment case, or in fetch case
3129  * set result to NULL and return false (instructing caller to skip the rest
3130  * of the SubscriptingRef sequence).
3131  *
3132  * Subscript expression result is in subscriptvalue/subscriptnull.
3133  * On success, integer subscript value has been saved in upperindex[] or
3134  * lowerindex[] for use later.
3135  */
3136 bool
3138 {
3139  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3140  int *indexes;
3141  int off;
3142 
3143  /* If any index expr yields NULL, result is NULL or error */
3144  if (sbsrefstate->subscriptnull)
3145  {
3146  if (sbsrefstate->isassignment)
3147  ereport(ERROR,
3148  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3149  errmsg("array subscript in assignment must not be null")));
3150  *op->resnull = true;
3151  return false;
3152  }
3153 
3154  /* Convert datum to int, save in appropriate place */
3155  if (op->d.sbsref_subscript.isupper)
3156  indexes = sbsrefstate->upperindex;
3157  else
3158  indexes = sbsrefstate->lowerindex;
3159  off = op->d.sbsref_subscript.off;
3160 
3161  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3162 
3163  return true;
3164 }
3165 
3166 /*
3167  * Evaluate SubscriptingRef fetch.
3168  *
3169  * Source container is in step's result variable.
3170  */
3171 void
3173 {
3174  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3175 
3176  /* Should not get here if source container (or any subscript) is null */
3177  Assert(!(*op->resnull));
3178 
3179  if (sbsrefstate->numlower == 0)
3180  {
3181  /* Scalar case */
3182  *op->resvalue = array_get_element(*op->resvalue,
3183  sbsrefstate->numupper,
3184  sbsrefstate->upperindex,
3185  sbsrefstate->refattrlength,
3186  sbsrefstate->refelemlength,
3187  sbsrefstate->refelembyval,
3188  sbsrefstate->refelemalign,
3189  op->resnull);
3190  }
3191  else
3192  {
3193  /* Slice case */
3194  *op->resvalue = array_get_slice(*op->resvalue,
3195  sbsrefstate->numupper,
3196  sbsrefstate->upperindex,
3197  sbsrefstate->lowerindex,
3198  sbsrefstate->upperprovided,
3199  sbsrefstate->lowerprovided,
3200  sbsrefstate->refattrlength,
3201  sbsrefstate->refelemlength,
3202  sbsrefstate->refelembyval,
3203  sbsrefstate->refelemalign);
3204  }
3205 }
3206 
3207 /*
3208  * Compute old container element/slice value for a SubscriptingRef assignment
3209  * expression. Will only be generated if the new-value subexpression
3210  * contains SubscriptingRef or FieldStore. The value is stored into the
3211  * SubscriptingRefState's prevvalue/prevnull fields.
3212  */
3213 void
3215 {
3216  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3217 
3218  if (*op->resnull)
3219  {
3220  /* whole array is null, so any element or slice is too */
3221  sbsrefstate->prevvalue = (Datum) 0;
3222  sbsrefstate->prevnull = true;
3223  }
3224  else if (sbsrefstate->numlower == 0)
3225  {
3226  /* Scalar case */
3227  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3228  sbsrefstate->numupper,
3229  sbsrefstate->upperindex,
3230  sbsrefstate->refattrlength,
3231  sbsrefstate->refelemlength,
3232  sbsrefstate->refelembyval,
3233  sbsrefstate->refelemalign,
3234  &sbsrefstate->prevnull);
3235  }
3236  else
3237  {
3238  /* Slice case */
3239  /* this is currently unreachable */
3240  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3241  sbsrefstate->numupper,
3242  sbsrefstate->upperindex,
3243  sbsrefstate->lowerindex,
3244  sbsrefstate->upperprovided,
3245  sbsrefstate->lowerprovided,
3246  sbsrefstate->refattrlength,
3247  sbsrefstate->refelemlength,
3248  sbsrefstate->refelembyval,
3249  sbsrefstate->refelemalign);
3250  sbsrefstate->prevnull = false;
3251  }
3252 }
3253 
3254 /*
3255  * Evaluate SubscriptingRef assignment.
3256  *
3257  * Input container (possibly null) is in result area, replacement value is in
3258  * SubscriptingRefState's replacevalue/replacenull.
3259  */
3260 void
3262 {
3263  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3264 
3265  /*
3266  * For an assignment to a fixed-length container type, both the original
3267  * container and the value to be assigned into it must be non-NULL, else
3268  * we punt and return the original container.
3269  */
3270  if (sbsrefstate->refattrlength > 0)
3271  {
3272  if (*op->resnull || sbsrefstate->replacenull)
3273  return;
3274  }
3275 
3276  /*
3277  * For assignment to varlena arrays, we handle a NULL original array by
3278  * substituting an empty (zero-dimensional) array; insertion of the new
3279  * element will result in a singleton array value. It does not matter
3280  * whether the new element is NULL.
3281  */
3282  if (*op->resnull)
3283  {
3285  *op->resnull = false;
3286  }
3287 
3288  if (sbsrefstate->numlower == 0)
3289  {
3290  /* Scalar case */
3291  *op->resvalue = array_set_element(*op->resvalue,
3292  sbsrefstate->numupper,
3293  sbsrefstate->upperindex,
3294  sbsrefstate->replacevalue,
3295  sbsrefstate->replacenull,
3296  sbsrefstate->refattrlength,
3297  sbsrefstate->refelemlength,
3298  sbsrefstate->refelembyval,
3299  sbsrefstate->refelemalign);
3300  }
3301  else
3302  {
3303  /* Slice case */
3304  *op->resvalue = array_set_slice(*op->resvalue,
3305  sbsrefstate->numupper,
3306  sbsrefstate->upperindex,
3307  sbsrefstate->lowerindex,
3308  sbsrefstate->upperprovided,
3309  sbsrefstate->lowerprovided,
3310  sbsrefstate->replacevalue,
3311  sbsrefstate->replacenull,
3312  sbsrefstate->refattrlength,
3313  sbsrefstate->refelemlength,
3314  sbsrefstate->refelembyval,
3315  sbsrefstate->refelemalign);
3316  }
3317 }
3318 
3319 /*
3320  * Evaluate a rowtype coercion operation.
3321  * This may require rearranging field positions.
3322  *
3323  * Source record is in step's result variable.
3324  */
3325 void
3327 {
3329  HeapTuple result;
3330  Datum tupDatum;
3331  HeapTupleHeader tuple;
3332  HeapTupleData tmptup;
3333  TupleDesc indesc,
3334  outdesc;
3335 
3336  /* NULL in -> NULL out */
3337  if (*op->resnull)
3338  return;
3339 
3340  tupDatum = *op->resvalue;
3341  tuple = DatumGetHeapTupleHeader(tupDatum);
3342 
3343  /* Lookup tupdescs if first time through or after rescan */
3344  if (op->d.convert_rowtype.indesc == NULL)
3345  {
3346  get_cached_rowtype(exprType((Node *) convert->arg), -1,
3347  &op->d.convert_rowtype.indesc,
3348  econtext);
3349  op->d.convert_rowtype.initialized = false;
3350  }
3351  if (op->d.convert_rowtype.outdesc == NULL)
3352  {
3353  get_cached_rowtype(convert->resulttype, -1,
3354  &op->d.convert_rowtype.outdesc,
3355  econtext);
3356  op->d.convert_rowtype.initialized = false;
3357  }
3358 
3359  indesc = op->d.convert_rowtype.indesc;
3360  outdesc = op->d.convert_rowtype.outdesc;
3361 
3362  /*
3363  * We used to be able to assert that incoming tuples are marked with
3364  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3365  * might change the tuples' marking to plain RECORD due to inserting
3366  * aliases, we can only make this weak test:
3367  */
3368  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3369  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3370 
3371  /* if first time through, initialize conversion map */
3372  if (!op->d.convert_rowtype.initialized)
3373  {
3374  MemoryContext old_cxt;
3375 
3376  /* allocate map in long-lived memory context */
3377  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3378 
3379  /* prepare map from old to new attribute numbers */
3380  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3381  op->d.convert_rowtype.initialized = true;
3382 
3383  MemoryContextSwitchTo(old_cxt);
3384  }
3385 
3386  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3387  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3388  tmptup.t_data = tuple;
3389 
3390  if (op->d.convert_rowtype.map != NULL)
3391  {
3392  /* Full conversion with attribute rearrangement needed */
3393  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3394  /* Result already has appropriate composite-datum header fields */
3395  *op->resvalue = HeapTupleGetDatum(result);
3396  }
3397  else
3398  {
3399  /*
3400  * The tuple is physically compatible as-is, but we need to insert the
3401  * destination rowtype OID in its composite-datum header field, so we
3402  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3403  * for this since it will both make the physical copy and insert the
3404  * correct composite header fields. Note that we aren't expecting to
3405  * have to flatten any toasted fields: the input was a composite
3406  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3407  * is overkill here, but its check for external fields is cheap.
3408  */
3409  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3410  }
3411 }
3412 
3413 /*
3414  * Evaluate "scalar op ANY/ALL (array)".
3415  *
3416  * Source array is in our result area, scalar arg is already evaluated into
3417  * fcinfo->args[0].
3418  *
3419  * The operator always yields boolean, and we combine the results across all
3420  * array elements using OR and AND (for ANY and ALL respectively). Of course
3421  * we short-circuit as soon as the result is known.
3422  */
3423 void
3425 {
3426  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3427  bool useOr = op->d.scalararrayop.useOr;
3428  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3429  ArrayType *arr;
3430  int nitems;
3431  Datum result;
3432  bool resultnull;
3433  int16 typlen;
3434  bool typbyval;
3435  char typalign;
3436  char *s;
3437  bits8 *bitmap;
3438  int bitmask;
3439 
3440  /*
3441  * If the array is NULL then we return NULL --- it's not very meaningful
3442  * to do anything else, even if the operator isn't strict.
3443  */
3444  if (*op->resnull)
3445  return;
3446 
3447  /* Else okay to fetch and detoast the array */
3448  arr = DatumGetArrayTypeP(*op->resvalue);
3449 
3450  /*
3451  * If the array is empty, we return either FALSE or TRUE per the useOr
3452  * flag. This is correct even if the scalar is NULL; since we would
3453  * evaluate the operator zero times, it matters not whether it would want
3454  * to return NULL.
3455  */
3456  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3457  if (nitems <= 0)
3458  {
3459  *op->resvalue = BoolGetDatum(!useOr);
3460  *op->resnull = false;
3461  return;
3462  }
3463 
3464  /*
3465  * If the scalar is NULL, and the function is strict, return NULL; no
3466  * point in iterating the loop.
3467  */
3468  if (fcinfo->args[0].isnull && strictfunc)
3469  {
3470  *op->resnull = true;
3471  return;
3472  }
3473 
3474  /*
3475  * We arrange to look up info about the element type only once per series
3476  * of calls, assuming the element type doesn't change underneath us.
3477  */
3478  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3479  {
3481  &op->d.scalararrayop.typlen,
3482  &op->d.scalararrayop.typbyval,
3483  &op->d.scalararrayop.typalign);
3484  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3485  }
3486 
3487  typlen = op->d.scalararrayop.typlen;
3488  typbyval = op->d.scalararrayop.typbyval;
3489  typalign = op->d.scalararrayop.typalign;
3490 
3491  /* Initialize result appropriately depending on useOr */
3492  result = BoolGetDatum(!useOr);
3493  resultnull = false;
3494 
3495  /* Loop over the array elements */
3496  s = (char *) ARR_DATA_PTR(arr);
3497  bitmap = ARR_NULLBITMAP(arr);
3498  bitmask = 1;
3499 
3500  for (int i = 0; i < nitems; i++)
3501  {
3502  Datum elt;
3503  Datum thisresult;
3504 
3505  /* Get array element, checking for NULL */
3506  if (bitmap && (*bitmap & bitmask) == 0)
3507  {
3508  fcinfo->args[1].value = (Datum) 0;
3509  fcinfo->args[1].isnull = true;
3510  }
3511  else
3512  {
3513  elt = fetch_att(s, typbyval, typlen);
3514  s = att_addlength_pointer(s, typlen, s);
3515  s = (char *) att_align_nominal(s, typalign);
3516  fcinfo->args[1].value = elt;
3517  fcinfo->args[1].isnull = false;
3518  }
3519 
3520  /* Call comparison function */
3521  if (fcinfo->args[1].isnull && strictfunc)
3522  {
3523  fcinfo->isnull = true;
3524  thisresult = (Datum) 0;
3525  }
3526  else
3527  {
3528  fcinfo->isnull = false;
3529  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3530  }
3531 
3532  /* Combine results per OR or AND semantics */
3533  if (fcinfo->isnull)
3534  resultnull = true;
3535  else if (useOr)
3536  {
3537  if (DatumGetBool(thisresult))
3538  {
3539  result = BoolGetDatum(true);
3540  resultnull = false;
3541  break; /* needn't look at any more elements */
3542  }
3543  }
3544  else
3545  {
3546  if (!DatumGetBool(thisresult))
3547  {
3548  result = BoolGetDatum(false);
3549  resultnull = false;
3550  break; /* needn't look at any more elements */
3551  }
3552  }
3553 
3554  /* advance bitmap pointer if any */
3555  if (bitmap)
3556  {
3557  bitmask <<= 1;
3558  if (bitmask == 0x100)
3559  {
3560  bitmap++;
3561  bitmask = 1;
3562  }
3563  }
3564  }
3565 
3566  *op->resvalue = result;
3567  *op->resnull = resultnull;
3568 }
3569 
3570 /*
3571  * Evaluate a NOT NULL domain constraint.
3572  */
3573 void
3575 {
3576  if (*op->resnull)
3577  ereport(ERROR,
3578  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3579  errmsg("domain %s does not allow null values",
3580  format_type_be(op->d.domaincheck.resulttype)),
3581  errdatatype(op->d.domaincheck.resulttype)));
3582 }
3583 
3584 /*
3585  * Evaluate a CHECK domain constraint.
3586  */
3587 void
3589 {
3590  if (!*op->d.domaincheck.checknull &&
3591  !DatumGetBool(*op->d.domaincheck.checkvalue))
3592  ereport(ERROR,
3593  (errcode(ERRCODE_CHECK_VIOLATION),
3594  errmsg("value for domain %s violates check constraint \"%s\"",
3595  format_type_be(op->d.domaincheck.resulttype),
3596  op->d.domaincheck.constraintname),
3597  errdomainconstraint(op->d.domaincheck.resulttype,
3598  op->d.domaincheck.constraintname)));
3599 }
3600 
3601 /*
3602  * Evaluate the various forms of XmlExpr.
3603  *
3604  * Arguments have been evaluated into named_argvalue/named_argnull
3605  * and/or argvalue/argnull arrays.
3606  */
3607 void
3609 {
3610  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3611  Datum value;
3612 
3613  *op->resnull = true; /* until we get a result */
3614  *op->resvalue = (Datum) 0;
3615 
3616  switch (xexpr->op)
3617  {
3618  case IS_XMLCONCAT:
3619  {
3620  Datum *argvalue = op->d.xmlexpr.argvalue;
3621  bool *argnull = op->d.xmlexpr.argnull;
3622  List *values = NIL;
3623 
3624  for (int i = 0; i < list_length(xexpr->args); i++)
3625  {
3626  if (!argnull[i])
3627  values = lappend(values, DatumGetPointer(argvalue[i]));
3628  }
3629 
3630  if (values != NIL)
3631  {
3632  *op->resvalue = PointerGetDatum(xmlconcat(values));
3633  *op->resnull = false;
3634  }
3635  }
3636  break;
3637 
3638  case IS_XMLFOREST:
3639  {
3640  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3641  bool *argnull = op->d.xmlexpr.named_argnull;
3643  ListCell *lc;
3644  ListCell *lc2;
3645  int i;
3646 
3647  initStringInfo(&buf);
3648 
3649  i = 0;
3650  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3651  {
3652  Expr *e = (Expr *) lfirst(lc);
3653  char *argname = strVal(lfirst(lc2));
3654 
3655  if (!argnull[i])
3656  {
3657  value = argvalue[i];
3658  appendStringInfo(&buf, "<%s>%s</%s>",
3659  argname,
3661  exprType((Node *) e), true),
3662  argname);
3663  *op->resnull = false;
3664  }
3665  i++;
3666  }
3667 
3668  if (!*op->resnull)
3669  {
3670  text *result;
3671 
3672  result = cstring_to_text_with_len(buf.data, buf.len);
3673  *op->resvalue = PointerGetDatum(result);
3674  }
3675 
3676  pfree(buf.data);
3677  }
3678  break;
3679 
3680  case IS_XMLELEMENT:
3681  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3682  op->d.xmlexpr.named_argvalue,
3683  op->d.xmlexpr.named_argnull,
3684  op->d.xmlexpr.argvalue,
3685  op->d.xmlexpr.argnull));
3686  *op->resnull = false;
3687  break;
3688 
3689  case IS_XMLPARSE:
3690  {
3691  Datum *argvalue = op->d.xmlexpr.argvalue;
3692  bool *argnull = op->d.xmlexpr.argnull;
3693  text *data;
3694  bool preserve_whitespace;
3695 
3696  /* arguments are known to be text, bool */
3697  Assert(list_length(xexpr->args) == 2);
3698 
3699  if (argnull[0])
3700  return;
3701  value = argvalue[0];
3702  data = DatumGetTextPP(value);
3703 
3704  if (argnull[1]) /* probably can't happen */
3705  return;
3706  value = argvalue[1];
3707  preserve_whitespace = DatumGetBool(value);
3708 
3709  *op->resvalue = PointerGetDatum(xmlparse(data,
3710  xexpr->xmloption,
3711  preserve_whitespace));
3712  *op->resnull = false;
3713  }
3714  break;
3715 
3716  case IS_XMLPI:
3717  {
3718  text *arg;
3719  bool isnull;
3720 
3721  /* optional argument is known to be text */
3722  Assert(list_length(xexpr->args) <= 1);
3723 
3724  if (xexpr->args)
3725  {
3726  isnull = op->d.xmlexpr.argnull[0];
3727  if (isnull)
3728  arg = NULL;
3729  else
3730  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3731  }
3732  else
3733  {
3734  arg = NULL;
3735  isnull = false;
3736  }
3737 
3738  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3739  arg,
3740  isnull,
3741  op->resnull));
3742  }
3743  break;
3744 
3745  case IS_XMLROOT:
3746  {
3747  Datum *argvalue = op->d.xmlexpr.argvalue;
3748  bool *argnull = op->d.xmlexpr.argnull;
3749  xmltype *data;
3750  text *version;
3751  int standalone;
3752 
3753  /* arguments are known to be xml, text, int */
3754  Assert(list_length(xexpr->args) == 3);
3755 
3756  if (argnull[0])
3757  return;
3758  data = DatumGetXmlP(argvalue[0]);
3759 
3760  if (argnull[1])
3761  version = NULL;
3762  else
3763  version = DatumGetTextPP(argvalue[1]);
3764 
3765  Assert(!argnull[2]); /* always present */
3766  standalone = DatumGetInt32(argvalue[2]);
3767 
3768  *op->resvalue = PointerGetDatum(xmlroot(data,
3769  version,
3770  standalone));
3771  *op->resnull = false;
3772  }
3773  break;
3774 
3775  case IS_XMLSERIALIZE:
3776  {
3777  Datum *argvalue = op->d.xmlexpr.argvalue;
3778  bool *argnull = op->d.xmlexpr.argnull;
3779 
3780  /* argument type is known to be xml */
3781  Assert(list_length(xexpr->args) == 1);
3782 
3783  if (argnull[0])
3784  return;
3785  value = argvalue[0];
3786 
3788  xexpr->xmloption));
3789  *op->resnull = false;
3790  }
3791  break;
3792 
3793  case IS_DOCUMENT:
3794  {
3795  Datum *argvalue = op->d.xmlexpr.argvalue;
3796  bool *argnull = op->d.xmlexpr.argnull;
3797 
3798  /* optional argument is known to be xml */
3799  Assert(list_length(xexpr->args) == 1);
3800 
3801  if (argnull[0])
3802  return;
3803  value = argvalue[0];
3804 
3805  *op->resvalue =
3807  *op->resnull = false;
3808  }
3809  break;
3810 
3811  default:
3812  elog(ERROR, "unrecognized XML operation");
3813  break;
3814  }
3815 }
3816 
3817 /*
3818  * ExecEvalGroupingFunc
3819  *
3820  * Computes a bitmask with a bit for each (unevaluated) argument expression
3821  * (rightmost arg is least significant bit).
3822  *
3823  * A bit is set if the corresponding expression is NOT part of the set of
3824  * grouping expressions in the current grouping set.
3825  */
3826 void
3828 {
3829  AggState *aggstate = castNode(AggState, state->parent);
3830  int result = 0;
3831  Bitmapset *grouped_cols = aggstate->grouped_cols;
3832  ListCell *lc;
3833 
3834  foreach(lc, op->d.grouping_func.clauses)
3835  {
3836  int attnum = lfirst_int(lc);
3837 
3838  result <<= 1;
3839 
3840  if (!bms_is_member(attnum, grouped_cols))
3841  result |= 1;
3842  }
3843 
3844  *op->resvalue = Int32GetDatum(result);
3845  *op->resnull = false;
3846 }
3847 
3848 /*
3849  * Hand off evaluation of a subplan to nodeSubplan.c
3850  */
3851 void
3853 {
3854  SubPlanState *sstate = op->d.subplan.sstate;
3855 
3856  /* could potentially be nested, so make sure there's enough stack */
3858 
3859  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3860 }
3861 
3862 /*
3863  * Evaluate a wholerow Var expression.
3864  *
3865  * Returns a Datum whose value is the value of a whole-row range variable
3866  * with respect to given expression context.
3867  */
3868 void
3870 {
3871  Var *variable = op->d.wholerow.var;
3872  TupleTableSlot *slot;
3873  TupleDesc output_tupdesc;
3874  MemoryContext oldcontext;
3875  HeapTupleHeader dtuple;
3876  HeapTuple tuple;
3877 
3878  /* This was checked by ExecInitExpr */
3879  Assert(variable->varattno == InvalidAttrNumber);
3880 
3881  /* Get the input slot we want */
3882  switch (variable->varno)
3883  {
3884  case INNER_VAR:
3885  /* get the tuple from the inner node */
3886  slot = econtext->ecxt_innertuple;
3887  break;
3888 
3889  case OUTER_VAR:
3890  /* get the tuple from the outer node */
3891  slot = econtext->ecxt_outertuple;
3892  break;
3893 
3894  /* INDEX_VAR is handled by default case */
3895 
3896  default:
3897  /* get the tuple from the relation being scanned */
3898  slot = econtext->ecxt_scantuple;
3899  break;
3900  }
3901 
3902  /* Apply the junkfilter if any */
3903  if (op->d.wholerow.junkFilter != NULL)
3904  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
3905 
3906  /*
3907  * If first time through, obtain tuple descriptor and check compatibility.
3908  *
3909  * XXX: It'd be great if this could be moved to the expression
3910  * initialization phase, but due to using slots that's currently not
3911  * feasible.
3912  */
3913  if (op->d.wholerow.first)
3914  {
3915  /* optimistically assume we don't need slow path */
3916  op->d.wholerow.slow = false;
3917 
3918  /*
3919  * If the Var identifies a named composite type, we must check that
3920  * the actual tuple type is compatible with it.
3921  */
3922  if (variable->vartype != RECORDOID)
3923  {
3924  TupleDesc var_tupdesc;
3925  TupleDesc slot_tupdesc;
3926 
3927  /*
3928  * We really only care about numbers of attributes and data types.
3929  * Also, we can ignore type mismatch on columns that are dropped
3930  * in the destination type, so long as (1) the physical storage
3931  * matches or (2) the actual column value is NULL. Case (1) is
3932  * helpful in some cases involving out-of-date cached plans, while
3933  * case (2) is expected behavior in situations such as an INSERT
3934  * into a table with dropped columns (the planner typically
3935  * generates an INT4 NULL regardless of the dropped column type).
3936  * If we find a dropped column and cannot verify that case (1)
3937  * holds, we have to use the slow path to check (2) for each row.
3938  *
3939  * If vartype is a domain over composite, just look through that
3940  * to the base composite type.
3941  */
3942  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
3943  -1, false);
3944 
3945  slot_tupdesc = slot->tts_tupleDescriptor;
3946 
3947  if (var_tupdesc->natts != slot_tupdesc->natts)
3948  ereport(ERROR,
3949  (errcode(ERRCODE_DATATYPE_MISMATCH),
3950  errmsg("table row type and query-specified row type do not match"),
3951  errdetail_plural("Table row contains %d attribute, but query expects %d.",
3952  "Table row contains %d attributes, but query expects %d.",
3953  slot_tupdesc->natts,
3954  slot_tupdesc->natts,
3955  var_tupdesc->natts)));
3956 
3957  for (int i = 0; i < var_tupdesc->natts; i++)
3958  {
3959  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
3960  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
3961 
3962  if (vattr->atttypid == sattr->atttypid)
3963  continue; /* no worries */
3964  if (!vattr->attisdropped)
3965  ereport(ERROR,
3966  (errcode(ERRCODE_DATATYPE_MISMATCH),
3967  errmsg("table row type and query-specified row type do not match"),
3968  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
3969  format_type_be(sattr->atttypid),
3970  i + 1,
3971  format_type_be(vattr->atttypid))));
3972 
3973  if (vattr->attlen != sattr->attlen ||
3974  vattr->attalign != sattr->attalign)
3975  op->d.wholerow.slow = true; /* need to check for nulls */
3976  }
3977 
3978  /*
3979  * Use the variable's declared rowtype as the descriptor for the
3980  * output values, modulo possibly assigning new column names
3981  * below. In particular, we *must* absorb any attisdropped
3982  * markings.
3983  */
3984  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3985  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
3986  MemoryContextSwitchTo(oldcontext);
3987 
3988  ReleaseTupleDesc(var_tupdesc);
3989  }
3990  else
3991  {
3992  /*
3993  * In the RECORD case, we use the input slot's rowtype as the
3994  * descriptor for the output values, modulo possibly assigning new
3995  * column names below.
3996  */
3997  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3998  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
3999  MemoryContextSwitchTo(oldcontext);
4000  }
4001 
4002  /*
4003  * Construct a tuple descriptor for the composite values we'll
4004  * produce, and make sure its record type is "blessed". The main
4005  * reason to do this is to be sure that operations such as
4006  * row_to_json() will see the desired column names when they look up
4007  * the descriptor from the type information embedded in the composite
4008  * values.
4009  *
4010  * We already got the correct physical datatype info above, but now we
4011  * should try to find the source RTE and adopt its column aliases, in
4012  * case they are different from the original rowtype's names. For
4013  * example, in "SELECT foo(t) FROM tab t(x,y)", the first two columns
4014  * in the composite output should be named "x" and "y" regardless of
4015  * tab's column names.
4016  *
4017  * If we can't locate the RTE, assume the column names we've got are
4018  * OK. (As of this writing, the only cases where we can't locate the
4019  * RTE are in execution of trigger WHEN clauses, and then the Var will
4020  * have the trigger's relation's rowtype, so its names are fine.)
4021  * Also, if the creator of the RTE didn't bother to fill in an eref
4022  * field, assume our column names are OK. (This happens in COPY, and
4023  * perhaps other places.)
4024  */
4025  if (econtext->ecxt_estate &&
4026  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4027  {
4028  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4029  econtext->ecxt_estate);
4030 
4031  if (rte->eref)
4032  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4033  }
4034 
4035  /* Bless the tupdesc if needed, and save it in the execution state */
4036  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4037 
4038  op->d.wholerow.first = false;
4039  }
4040 
4041  /*
4042  * Make sure all columns of the slot are accessible in the slot's
4043  * Datum/isnull arrays.
4044  */
4045  slot_getallattrs(slot);
4046 
4047  if (op->d.wholerow.slow)
4048  {
4049  /* Check to see if any dropped attributes are non-null */
4050  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4051  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4052 
4053  Assert(var_tupdesc->natts == tupleDesc->natts);
4054 
4055  for (int i = 0; i < var_tupdesc->natts; i++)
4056  {
4057  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4058  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4059 
4060  if (!vattr->attisdropped)
4061  continue; /* already checked non-dropped cols */
4062  if (slot->tts_isnull[i])
4063  continue; /* null is always okay */
4064  if (vattr->attlen != sattr->attlen ||
4065  vattr->attalign != sattr->attalign)
4066  ereport(ERROR,
4067  (errcode(ERRCODE_DATATYPE_MISMATCH),
4068  errmsg("table row type and query-specified row type do not match"),
4069  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4070  i + 1)));
4071  }
4072  }
4073 
4074  /*
4075  * Build a composite datum, making sure any toasted fields get detoasted.
4076  *
4077  * (Note: it is critical that we not change the slot's state here.)
4078  */
4080  slot->tts_values,
4081  slot->tts_isnull);
4082  dtuple = tuple->t_data;
4083 
4084  /*
4085  * Label the datum with the composite type info we identified before.
4086  *
4087  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4088  * the tuple build step; but that seems a tad risky so let's not.)
4089  */
4090  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4091  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4092 
4093  *op->resvalue = PointerGetDatum(dtuple);
4094  *op->resnull = false;
4095 }
4096 
4097 void
4099  TupleTableSlot *slot)
4100 {
4101  Datum d;
4102 
4103  /* slot_getsysattr has sufficient defenses against bad attnums */
4104  d = slot_getsysattr(slot,
4105  op->d.var.attnum,
4106  op->resnull);
4107  *op->resvalue = d;
4108  /* this ought to be unreachable, but it's cheap enough to check */
4109  if (unlikely(*op->resnull))
4110  elog(ERROR, "failed to fetch attribute from slot");
4111 }
4112 
4113 /*
4114  * Transition value has not been initialized. This is the first non-NULL input
4115  * value for a group. We use it as the initial value for transValue.
4116  */
4117 void
4119  ExprContext *aggcontext)
4120 {
4121  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4122  MemoryContext oldContext;
4123 
4124  /*
4125  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4126  * need to pfree the old transValue, since it's NULL. (We already checked
4127  * that the agg's input type is binary-compatible with its transtype, so
4128  * straight copy here is OK.)
4129  */
4130  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4131  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4132  pertrans->transtypeByVal,
4133  pertrans->transtypeLen);
4134  pergroup->transValueIsNull = false;
4135  pergroup->noTransValue = false;
4136  MemoryContextSwitchTo(oldContext);
4137 }
4138 
4139 /*
4140  * Ensure that the current transition value is a child of the aggcontext,
4141  * rather than the per-tuple context.
4142  *
4143  * NB: This can change the current memory context.
4144  */
4145 Datum
4147  Datum newValue, bool newValueIsNull,
4148  Datum oldValue, bool oldValueIsNull)
4149 {
4150  Assert(newValue != oldValue);
4151 
4152  if (!newValueIsNull)
4153  {
4155  if (DatumIsReadWriteExpandedObject(newValue,
4156  false,
4157  pertrans->transtypeLen) &&
4158  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4159  /* do nothing */ ;
4160  else
4161  newValue = datumCopy(newValue,
4162  pertrans->transtypeByVal,
4163  pertrans->transtypeLen);
4164  }
4165  else
4166  {
4167  /*
4168  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4169  * callers can safely compare newValue/oldValue without having to
4170  * check their respective nullness.
4171  */
4172  newValue = (Datum) 0;
4173  }
4174 
4175  if (!oldValueIsNull)
4176  {
4177  if (DatumIsReadWriteExpandedObject(oldValue,
4178  false,
4179  pertrans->transtypeLen))
4180  DeleteExpandedObject(oldValue);
4181  else
4182  pfree(DatumGetPointer(oldValue));
4183  }
4184 
4185  return newValue;
4186 }
4187 
4188 /*
4189  * Invoke ordered transition function, with a datum argument.
4190  */
4191 void
4193  ExprContext *econtext)
4194 {
4195  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4196  int setno = op->d.agg_trans.setno;
4197 
4198  tuplesort_putdatum(pertrans->sortstates[setno],
4199  *op->resvalue, *op->resnull);
4200 }
4201 
4202 /*
4203  * Invoke ordered transition function, with a tuple argument.
4204  */
4205 void
4207  ExprContext *econtext)
4208 {
4209  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4210  int setno = op->d.agg_trans.setno;
4211 
4212  ExecClearTuple(pertrans->sortslot);
4213  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4214  ExecStoreVirtualTuple(pertrans->sortslot);
4215  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4216 }
4217 
4218 /* implementation of transition function invocation for byval types */
4219 static pg_attribute_always_inline void
4221  AggStatePerGroup pergroup,
4222  ExprContext *aggcontext, int setno)
4223 {
4224  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4225  MemoryContext oldContext;
4226  Datum newVal;
4227 
4228  /* cf. select_current_set() */
4229  aggstate->curaggcontext = aggcontext;
4230  aggstate->current_set = setno;
4231 
4232  /* set up aggstate->curpertrans for AggGetAggref() */
4233  aggstate->curpertrans = pertrans;
4234 
4235  /* invoke transition function in per-tuple context */
4236  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4237 
4238  fcinfo->args[0].value = pergroup->transValue;
4239  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4240  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4241 
4242  newVal = FunctionCallInvoke(fcinfo);
4243 
4244  pergroup->transValue = newVal;
4245  pergroup->transValueIsNull = fcinfo->isnull;
4246 
4247  MemoryContextSwitchTo(oldContext);
4248 }
4249 
4250 /* implementation of transition function invocation for byref types */
4251 static pg_attribute_always_inline void
4253  AggStatePerGroup pergroup,
4254  ExprContext *aggcontext, int setno)
4255 {
4256  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4257  MemoryContext oldContext;
4258  Datum newVal;
4259 
4260  /* cf. select_current_set() */
4261  aggstate->curaggcontext = aggcontext;
4262  aggstate->current_set = setno;
4263 
4264  /* set up aggstate->curpertrans for AggGetAggref() */
4265  aggstate->curpertrans = pertrans;
4266 
4267  /* invoke transition function in per-tuple context */
4268  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4269 
4270  fcinfo->args[0].value = pergroup->transValue;
4271  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4272  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4273 
4274  newVal = FunctionCallInvoke(fcinfo);
4275 
4276  /*
4277  * For pass-by-ref datatype, must copy the new value into aggcontext and
4278  * free the prior transValue. But if transfn returned a pointer to its
4279  * first input, we don't need to do anything. Also, if transfn returned a
4280  * pointer to a R/W expanded object that is already a child of the
4281  * aggcontext, assume we can adopt that value without copying it.
4282  *
4283  * It's safe to compare newVal with pergroup->transValue without regard
4284  * for either being NULL, because ExecAggTransReparent() takes care to set
4285  * transValue to 0 when NULL. Otherwise we could end up accidentally not
4286  * reparenting, when the transValue has the same numerical value as
4287  * newValue, despite being NULL. This is a somewhat hot path, making it
4288  * undesirable to instead solve this with another branch for the common
4289  * case of the transition function returning its (modified) input
4290  * argument.
4291  */
4292  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
4293  newVal = ExecAggTransReparent(aggstate, pertrans,
4294  newVal, fcinfo->isnull,
4295  pergroup->transValue,
4296  pergroup->transValueIsNull);
4297 
4298  pergroup->transValue = newVal;
4299  pergroup->transValueIsNull = fcinfo->isnull;
4300 
4301  MemoryContextSwitchTo(oldContext);
4302 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
signed short int16
Definition: c.h:361
struct ExprEvalStep::@51::@71 arraycoerce
struct ExprEvalStep::@51::@63 param
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:125
#define NIL
Definition: pg_list.h:65
void ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
Datum value
Definition: params.h:92
struct ExprEvalStep::@51::@79 sbsref
Datum ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2050
struct ExprEvalStep::@51::@89 agg_strict_input_check
struct ExprEvalStep::@51::@86 window_func
void * execPlan
Definition: params.h:148
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition: tupdesc.c:110
Datum * ecxt_aggvalues
Definition: execnodes.h:245
struct ExprEvalStep::@51::@74 rowcompare_final
Datum MakeExpandedObjectReadOnlyInternal(Datum d)
Definition: expandeddatum.c:95
struct ExprEvalStep::@51::@70 arrayexpr
#define HeapTupleHeaderSetTypeId(tup, typeid)
Definition: htup_details.h:463
struct PlanState * parent
Definition: execnodes.h:108
#define likely(x)
Definition: c.h:205
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:434
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:298
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1786
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:279
#define att_align_nominal(cur_offset, attalign)
Definition: tupmacs.h:148
static Datum ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static pg_attribute_always_inline void ExecAggPlainTransByVal(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext, int setno)
char * name
Definition: primnodes.h:1185
#define ARR_SIZE(a)
Definition: array.h:277
static struct @142 value
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
Definition: postgres.h:322
static void ShutdownTupleDescRef(Datum arg)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1710
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
static Datum ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
Datum * resvalue
Definition: execExpr.h:252
List * colnames
Definition: primnodes.h:43
#define DatumGetInt32(X)
Definition: postgres.h:472
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:440
#define MAXDIM
Definition: c.h:542
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
struct ExprEvalStep::@51::@80 domaincheck
#define castNode(_type_, nodeptr)
Definition: nodes.h:597
struct ExprEvalStep::@51::@78 sbsref_subscript
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define EEO_SWITCH()
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition: lsyscache.c:2159
#define PointerGetDatum(X)
Definition: postgres.h:556
struct ExprEvalStep * steps
Definition: execnodes.h:85
struct ExprEvalStep::@51::@81 convert_rowtype
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
struct ExprEvalStep::@51::@91 agg_trans
void ExecReadyInterpretedExpr(ExprState *state)
struct ExprEvalStep::@51::@85 grouping_func
const TupleTableSlotOps TTSOpsBufferHeapTuple
Definition: execTuples.c:86
MemoryContext ecxt_per_tuple_memory
Definition: execnodes.h:234
#define EEO_JUMP(stepno)
void array_bitmap_copy(bits8 *destbitmap, int destoffset, const bits8 *srcbitmap, int srcoffset, int nitems)
Definition: arrayfuncs.c:4714
int64 nextval_internal(Oid relid, bool check_permissions)
Definition: sequence.c:579
int32 dataoffset
Definition: array.h:84
struct ExprEvalStep::@51::@57 constval
#define DatumGetTextPP(X)
Definition: fmgr.h:291
void ExecEvalParamExec(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
struct ExprEvalStep::@51::@52 fetch
bool * resnull
Definition: execExpr.h:253
int ArrayGetNItems(int ndim, const int *dims)
Definition: arrayutils.c:75
#define TimeTzADTPGetDatum(X)
Definition: date.h:59
struct ExprEvalStep::@51::@77 fieldstore
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define Int16GetDatum(X)
Definition: postgres.h:451
ExprEvalOp
Definition: execExpr.h:44
xmltype * xmlconcat(List *args)
Definition: xml.c:512
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:341
Definition: nodes.h:528
#define strVal(v)
Definition: value.h:54
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1596
int errcode(int sqlerrcode)
Definition: elog.c:610
void ExecEvalConvertRowtype(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define DateADTGetDatum(X)
Definition: date.h:57
AttrNumber varattno
Definition: primnodes.h:186
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2221
bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)
Definition: heaptuple.c:359
Datum * tts_values
Definition: tuptable.h:126
void ExecEvalSubscriptingRefAssign(ExprState *state, ExprEvalStep *op)
struct ExprEvalStep::@51::@55 assign_var
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
static pg_attribute_always_inline Datum ExecJustAssignVarImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)
bool ExecEvalSubscriptingRef(ExprState *state, ExprEvalStep *op)
#define lengthof(array)
Definition: c.h:675
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3432
DateADT GetSQLCurrentDate(void)
Definition: date.c:300
TupleTableSlot * resultslot
Definition: execnodes.h:80
struct ExprEvalStep::@51::@67 iocoerce
unsigned int Oid
Definition: postgres_ext.h:31
Datum domainValue_datum
Definition: execnodes.h:257
List * arg_names
Definition: primnodes.h:1187
Definition: primnodes.h:181
struct ExprEvalStep::@51::@58 func
#define DatumGetXmlP(X)
Definition: xml.h:50
int current_set
Definition: execnodes.h:2156
#define OidIsValid(objectId)
Definition: c.h:651
struct ExprEvalStep::@51::@82 scalararrayop
void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:294
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:162
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
Definition: execnodes.h:53
#define ARR_OVERHEAD_WITHNULLS(ndims, nitems)
Definition: array.h:300
Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
SQLValueFunctionOp op
Definition: primnodes.h:1146
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1766
ExprContext * tmpcontext
Definition: execnodes.h:2146
signed int int32
Definition: c.h:362
struct ExprEvalStep::@51::@90 agg_plain_pergroup_nullcheck
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:170
xmltype * xmlpi(const char *target, text *arg, bool arg_is_null, bool *result_is_null)
Definition: xml.c:770
struct ExprEvalStep::@51::@72 row
void ExecEvalRow(ExprState *state, ExprEvalStep *op)
#define ARR_DATA_OFFSET(a)
Definition: array.h:304
#define ARR_LBOUND(a)
Definition: array.h:284
HeapTupleHeader t_data
Definition: htup.h:68
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:468
static pg_attribute_always_inline Datum ExecJustVarVirtImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
#define StaticAssertStmt(condition, errmessage)
Definition: c.h:859
void ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
Datum array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, Datum srcArrayDatum, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:2781
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ParamFetchHook paramFetch
Definition: params.h:112
void pfree(void *pointer)
Definition: mcxt.c:1057
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
MinMaxOp
Definition: primnodes.h:1096
static void convert(const int32 val, char *const buf)
Definition: zic.c:2001
char typalign
Definition: pg_type.h:170
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
static Datum ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
#define ERROR
Definition: elog.h:43
struct ExprEvalStep::@51::@87 subplan
int errdomainconstraint(Oid datatypeOid, const char *conname)
Definition: domains.c:384
bool resnull
Definition: execnodes.h:72
#define DatumGetCString(X)
Definition: postgres.h:566
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1675
Oid elemtype
Definition: array.h:85
#define lfirst_int(lc)
Definition: pg_list.h:170
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1050
bool isnull
Definition: params.h:150
Oid vartype
Definition: primnodes.h:188
Datum caseValue_datum
Definition: execnodes.h:251
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
text * xmltotext_with_xmloption(xmltype *data, XmlOptionType xmloption_arg)
Definition: xml.c:615
int32 tdtypmod
Definition: tupdesc.h:83
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
Definition: fmgr.h:95
#define ARR_DIMS(a)
Definition: array.h:282
TimeTzADT * GetSQLCurrentTime(int32 typmod)
Definition: date.c:333
ItemPointerData t_self
Definition: htup.h:65
void ExecEvalSubscriptingRefFetch(ExprState *state, ExprEvalStep *op)
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:354
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2052
uint32 t_len
Definition: htup.h:64
#define EEO_NEXT()
#define ARR_DATA_PTR(a)
Definition: array.h:310
void ExecEvalRowNull(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
TupleConversionMap * convert_tuples_by_name(TupleDesc indesc, TupleDesc outdesc)
Definition: tupconvert.c:102
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
ExprStateEvalFunc evalfunc
Definition: execnodes.h:91
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)
static char * buf
Definition: pg_test_fsync.c:68
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:263
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:200
HeapTuple toast_build_flattened_tuple(TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptoast.c:563
bool * tts_isnull
Definition: tuptable.h:128
void ExecEvalSysVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext, TupleTableSlot *slot)
static Datum ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
void check_stack_depth(void)
Definition: postgres.c:3312
void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext)
int errdetail(const char *fmt,...)
Definition: elog.c:957
xmltype * xmlroot(xmltype *data, text *version, int standalone)
Definition: xml.c:822
#define DatumGetBool(X)
Definition: postgres.h:393
bool upperprovided[MAXDIM]
Definition: execExpr.h:653
TupleTableSlot * ecxt_innertuple
Definition: execnodes.h:228
void ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op)
ParamExecData * ecxt_param_exec_vals
Definition: execnodes.h:237
struct EState * ecxt_estate
Definition: execnodes.h:262
static Datum ExecJustAssignOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
static RangeTblEntry * exec_rt_fetch(Index rti, EState *estate)
Definition: executor.h:543
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
Oid t_tableOid
Definition: htup.h:66
#define ARR_HASNULL(a)
Definition: array.h:279
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1701
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
Definition: tupconvert.c:139
struct ExprEvalStep::@51::@76 fieldselect
#define EEO_DISPATCH()
#define att_addlength_pointer(cur_offset, attlen, attptr)
Definition: tupmacs.h:176
struct ExprEvalStep::@51::@68 sqlvaluefunction
Datum value
Definition: postgres.h:378
Bitmapset * grouped_cols
Definition: execnodes.h:2157
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:131
#define TimestampGetDatum(X)
Definition: timestamp.h:31
static pg_attribute_always_inline Datum ExecJustAssignVarVirtImpl(ExprState *state, TupleTableSlot *inslot, bool *isnull)
void * evalfunc_private
Definition: execnodes.h:97
Datum heap_copy_tuple_as_datum(HeapTuple tuple, TupleDesc tupleDesc)
Definition: heaptuple.c:984
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
TimeADT GetSQLLocalTime(int32 typmod)
Definition: date.c:353
union ExprEvalStep::@51 d
List * lappend(List *list, void *datum)
Definition: list.c:321
static Datum ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
bool xml_is_document(xmltype *arg)
Definition: xml.c:888
static Datum ExecJustAssignOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
ExpandedObjectHeader * DatumGetEOHP(Datum d)
Definition: expandeddatum.c:29
Index varno
Definition: primnodes.h:184
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
bool domainValue_isNull
Definition: execnodes.h:259
XmlExprOp op
Definition: primnodes.h:1184
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:269
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
ExprContext * curaggcontext
Definition: execnodes.h:2148
bool * ecxt_aggnulls
Definition: execnodes.h:247
uint8 bits8
Definition: c.h:381
static TupleDesc get_cached_rowtype(Oid type_id, int32 typmod, TupleDesc *cache_field, ExprContext *econtext)
struct ExprEvalStep::@51::@66 make_readonly
#define TTS_IS_VIRTUAL(slot)
Definition: tuptable.h:228
uintptr_t Datum
Definition: postgres.h:367
TupleTableSlot * ExecFilterJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
Definition: execJunk.c:261
#define ER_MAGIC
void ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
#define HeapTupleHeaderSetTypMod(tup, typmod)
Definition: htup_details.h:473
bool lowerprovided[MAXDIM]
Definition: execExpr.h:658
void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define DatumGetArrayTypePCopy(X)
Definition: array.h:250
#define TimeADTGetDatum(X)
Definition: date.h:58
int errdatatype(Oid datatypeOid)
Definition: domains.c:360
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:458
Timestamp GetSQLLocalTimestamp(int32 typmod)
Definition: timestamp.c:1610
struct ExprEvalStep::@51::@59 boolexpr
struct ExprEvalStep::@51::@53 var
struct ExprEvalStep::@51::@69 nextvalueexpr
#define BoolGetDatum(X)
Definition: postgres.h:402
void ExecEvalParamExtern(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void DeleteExpandedObject(Datum d)
struct ExprEvalStep::@51::@83 xmlexpr
#define InvalidOid
Definition: postgres_ext.h:36
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:381
int16 attnum
Definition: pg_attribute.h:79
List * named_args
Definition: primnodes.h:1186
#define ereport(elevel,...)
Definition: elog.h:144
RowCompareType
Definition: primnodes.h:1059
static Datum ExecJustScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
#define INNER_VAR
Definition: primnodes.h:171
struct ExprEvalStep::@51::@62 nulltest_row
List * args
Definition: primnodes.h:1188
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1841
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
Datum array_map(Datum arrayd, ExprState *exprstate, ExprContext *econtext, Oid retType, ArrayMapState *amstate)
Definition: arrayfuncs.c:3153
struct ExprEvalStep::@51::@73 rowcompare_step
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:230
static Datum ExecJustAssignScanVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:169
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
Definition: execUtils.c:904
struct ExprEvalStep::@51::@64 cparam
struct ExprEvalStep::@51::@56 assign_tmp
Definition: regguts.h:298
intptr_t opcode
Definition: execExpr.h:249
static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
XmlOptionType xmloption
Definition: primnodes.h:1189
int lowerindex[MAXDIM]
Definition: execExpr.h:659
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static void ExecInitInterpreter(void)
static int list_length(const List *l)
Definition: pg_list.h:149
#define newval
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
Definition: elog.c:1049
void ExecEvalArrayCoerce(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:226
Index es_range_table_size
Definition: execnodes.h:508
void ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalSubscriptingRefOld(ExprState *state, ExprEvalStep *op)
static pg_attribute_always_inline Datum ExecJustVarImpl(ExprState *state, TupleTableSlot *slot, bool *isnull)
struct ExprEvalStep::@51::@65 casetest
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:233
#define ARR_NDIM(a)
Definition: array.h:278
#define InvalidAttrNumber
Definition: attnum.h:23
static Datum ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
void ExecEvalAggOrderedTransDatum(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
struct ExprEvalStep::@51::@88 agg_deserialize
#define DatumGetPointer(X)
Definition: postgres.h:549
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1747
int upperindex[MAXDIM]
Definition: execExpr.h:654
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
void ExecEvalFieldStoreDeForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static Datum values[MAXATTR]
Definition: bootstrap.c:165
struct ExprEvalStep::@51::@84 aggref
Oid tdtypeid
Definition: tupdesc.h:82
void ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op)
#define Int32GetDatum(X)
Definition: postgres.h:479
e
Definition: preproc-init.c:82
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
static Datum ExecJustOuterVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
bool caseValue_isNull
Definition: execnodes.h:253
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define fetch_att(T, attbyval, attlen)
Definition: tupmacs.h:75
int steps_len
Definition: execnodes.h:104
void ExecEvalRowNotNull(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalConstraintNotNull(ExprState *state, ExprEvalStep *op)
#define elog(elevel,...)
Definition: elog.h:214
static Datum ExecJustAssignInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
Datum ExecSubPlan(SubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:62
int i
xmltype * xmlelement(XmlExpr *xexpr, Datum *named_argvalue, bool *named_argnull, Datum *argvalue, bool *argnull)
Definition: xml.c:628
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
Datum value
Definition: params.h:149
static Datum ExecJustAssignInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
uint8 flags
Definition: execnodes.h:65
static pg_attribute_always_inline void ExecAggPlainTransByRef(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup, ExprContext *aggcontext, int setno)
#define pg_attribute_always_inline
Definition: c.h:162
void * arg
struct ExprEvalStep::@51::@61 jump
AggStatePerTrans curpertrans
Definition: execnodes.h:2151
#define unlikely(x)
Definition: c.h:206
Definition: c.h:562
void ExecEvalSubPlan(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalFuncExprFusage(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
AttrNumber tts_nvalid
Definition: tuptable.h:121
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:329
struct ExprEvalStep::@51::@75 minmax
TupleTableSlot * sortslot
Definition: nodeAgg.h:136
Alias * eref
Definition: parsenodes.h:1116
struct ExprEvalStep::@51::@54 wholerow
#define qsort(a, b, c, d)
Definition: port.h:475
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
#define EEO_OPCODE(opcode)
static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition: tuptable.h:402
void ExecEvalCurrentOfExpr(ExprState *state, ExprEvalStep *op)
static void CheckOpSlotCompatibility(ExprEvalStep *op, TupleTableSlot *slot)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3348
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
char * map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
Definition: xml.c:2134
ParamListInfo ecxt_param_list_info
Definition: execnodes.h:238
Definition: pg_list.h:50
void ExecEvalNextValueExpr(ExprState *state, ExprEvalStep *op)
bool isnull
Definition: params.h:93
#define EEO_CASE(name)
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427
#define ARR_ELEMTYPE(a)
Definition: array.h:280
Datum resvalue
Definition: execnodes.h:74
#define EEO_FLAG_INTERPRETER_INITIALIZED
Definition: execExpr.h:26
int16 AttrNumber
Definition: attnum.h:21
#define ARR_NULLBITMAP(a)
Definition: array.h:288
#define OUTER_VAR
Definition: primnodes.h:172
void ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
Definition: execTuples.c:2006
void ExecEvalAggOrderedTransTuple(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void ExecEvalFieldSelect(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
xmltype * xmlparse(text *data, XmlOptionType xmloption_arg, bool preserve_whitespace)
Definition: xml.c:752
int ndim
Definition: array.h:83
#define EEO_FLAG_DIRECT_THREADED
Definition: execExpr.h:28
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1522
struct ExprEvalStep::@51::@60 qualexpr
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Definition: tuplesort.c:1665
void ExecEvalSQLValueFunction(ExprState *state, ExprEvalStep *op)
AggStatePerGroup * all_pergroups
Definition: execnodes.h:2202
void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452
#define DatumGetArrayTypeP(X)
Definition: array.h:249