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 */
170 static pg_attribute_always_inline void
172  AggStatePerGroup pergroup,
173  ExprContext *aggcontext, int setno);
174 
175 static pg_attribute_always_inline void
177  AggStatePerGroup pergroup,
178  ExprContext *aggcontext, int setno);
179 
180 /*
181  * Prepare ExprState for interpreted execution.
182  */
183 void
185 {
186  /* Ensure one-time interpreter setup has been done */
188 
189  /* Simple validity checks on expression */
190  Assert(state->steps_len >= 1);
191  Assert(state->steps[state->steps_len - 1].opcode == EEOP_DONE);
192 
193  /*
194  * Don't perform redundant initialization. This is unreachable in current
195  * cases, but might be hit if there's additional expression evaluation
196  * methods that rely on interpreted execution to work.
197  */
199  return;
200 
201  /*
202  * First time through, check whether attribute matches Var. Might not be
203  * ok anymore, due to schema changes. We do that by setting up a callback
204  * that does checking on the first call, which then sets the evalfunc
205  * callback to the actual method of execution.
206  */
208 
209  /* DIRECT_THREADED should not already be set */
210  Assert((state->flags & EEO_FLAG_DIRECT_THREADED) == 0);
211 
212  /*
213  * There shouldn't be any errors before the expression is fully
214  * initialized, and even if so, it'd lead to the expression being
215  * abandoned. So we can set the flag now and save some code.
216  */
218 
219  /*
220  * Select fast-path evalfuncs for very simple expressions. "Starting up"
221  * the full interpreter is a measurable overhead for these, and these
222  * patterns occur often enough to be worth optimizing.
223  */
224  if (state->steps_len == 3)
225  {
226  ExprEvalOp step0 = state->steps[0].opcode;
227  ExprEvalOp step1 = state->steps[1].opcode;
228 
229  if (step0 == EEOP_INNER_FETCHSOME &&
230  step1 == EEOP_INNER_VAR)
231  {
232  state->evalfunc_private = (void *) ExecJustInnerVar;
233  return;
234  }
235  else if (step0 == EEOP_OUTER_FETCHSOME &&
236  step1 == EEOP_OUTER_VAR)
237  {
238  state->evalfunc_private = (void *) ExecJustOuterVar;
239  return;
240  }
241  else if (step0 == EEOP_SCAN_FETCHSOME &&
242  step1 == EEOP_SCAN_VAR)
243  {
244  state->evalfunc_private = (void *) ExecJustScanVar;
245  return;
246  }
247  else if (step0 == EEOP_INNER_FETCHSOME &&
248  step1 == EEOP_ASSIGN_INNER_VAR)
249  {
250  state->evalfunc_private = (void *) ExecJustAssignInnerVar;
251  return;
252  }
253  else if (step0 == EEOP_OUTER_FETCHSOME &&
254  step1 == EEOP_ASSIGN_OUTER_VAR)
255  {
256  state->evalfunc_private = (void *) ExecJustAssignOuterVar;
257  return;
258  }
259  else if (step0 == EEOP_SCAN_FETCHSOME &&
260  step1 == EEOP_ASSIGN_SCAN_VAR)
261  {
262  state->evalfunc_private = (void *) ExecJustAssignScanVar;
263  return;
264  }
265  else if (step0 == EEOP_CASE_TESTVAL &&
266  step1 == EEOP_FUNCEXPR_STRICT &&
267  state->steps[0].d.casetest.value)
268  {
269  state->evalfunc_private = (void *) ExecJustApplyFuncToCase;
270  return;
271  }
272  }
273  else if (state->steps_len == 2)
274  {
275  ExprEvalOp step0 = state->steps[0].opcode;
276 
277  if (step0 == EEOP_CONST)
278  {
279  state->evalfunc_private = (void *) ExecJustConst;
280  return;
281  }
282  else if (step0 == EEOP_INNER_VAR)
283  {
284  state->evalfunc_private = (void *) ExecJustInnerVarVirt;
285  return;
286  }
287  else if (step0 == EEOP_OUTER_VAR)
288  {
289  state->evalfunc_private = (void *) ExecJustOuterVarVirt;
290  return;
291  }
292  else if (step0 == EEOP_SCAN_VAR)
293  {
294  state->evalfunc_private = (void *) ExecJustScanVarVirt;
295  return;
296  }
297  else if (step0 == EEOP_ASSIGN_INNER_VAR)
298  {
300  return;
301  }
302  else if (step0 == EEOP_ASSIGN_OUTER_VAR)
303  {
305  return;
306  }
307  else if (step0 == EEOP_ASSIGN_SCAN_VAR)
308  {
310  return;
311  }
312  }
313 
314 #if defined(EEO_USE_COMPUTED_GOTO)
315 
316  /*
317  * In the direct-threaded implementation, replace each opcode with the
318  * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
319  */
320  for (int off = 0; off < state->steps_len; off++)
321  {
322  ExprEvalStep *op = &state->steps[off];
323 
324  op->opcode = EEO_OPCODE(op->opcode);
325  }
326 
328 #endif /* EEO_USE_COMPUTED_GOTO */
329 
330  state->evalfunc_private = (void *) ExecInterpExpr;
331 }
332 
333 
334 /*
335  * Evaluate expression identified by "state" in the execution context
336  * given by "econtext". *isnull is set to the is-null flag for the result,
337  * and the Datum value is the function result.
338  *
339  * As a special case, return the dispatch table's address if state is NULL.
340  * This is used by ExecInitInterpreter to set up the dispatch_table global.
341  * (Only applies when EEO_USE_COMPUTED_GOTO is defined.)
342  */
343 static Datum
344 ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
345 {
346  ExprEvalStep *op;
347  TupleTableSlot *resultslot;
348  TupleTableSlot *innerslot;
349  TupleTableSlot *outerslot;
350  TupleTableSlot *scanslot;
351 
352  /*
353  * This array has to be in the same order as enum ExprEvalOp.
354  */
355 #if defined(EEO_USE_COMPUTED_GOTO)
356  static const void *const dispatch_table[] = {
357  &&CASE_EEOP_DONE,
358  &&CASE_EEOP_INNER_FETCHSOME,
359  &&CASE_EEOP_OUTER_FETCHSOME,
360  &&CASE_EEOP_SCAN_FETCHSOME,
361  &&CASE_EEOP_INNER_VAR,
362  &&CASE_EEOP_OUTER_VAR,
363  &&CASE_EEOP_SCAN_VAR,
364  &&CASE_EEOP_INNER_SYSVAR,
365  &&CASE_EEOP_OUTER_SYSVAR,
366  &&CASE_EEOP_SCAN_SYSVAR,
367  &&CASE_EEOP_WHOLEROW,
368  &&CASE_EEOP_ASSIGN_INNER_VAR,
369  &&CASE_EEOP_ASSIGN_OUTER_VAR,
370  &&CASE_EEOP_ASSIGN_SCAN_VAR,
371  &&CASE_EEOP_ASSIGN_TMP,
372  &&CASE_EEOP_ASSIGN_TMP_MAKE_RO,
373  &&CASE_EEOP_CONST,
374  &&CASE_EEOP_FUNCEXPR,
375  &&CASE_EEOP_FUNCEXPR_STRICT,
376  &&CASE_EEOP_FUNCEXPR_FUSAGE,
377  &&CASE_EEOP_FUNCEXPR_STRICT_FUSAGE,
378  &&CASE_EEOP_BOOL_AND_STEP_FIRST,
379  &&CASE_EEOP_BOOL_AND_STEP,
380  &&CASE_EEOP_BOOL_AND_STEP_LAST,
381  &&CASE_EEOP_BOOL_OR_STEP_FIRST,
382  &&CASE_EEOP_BOOL_OR_STEP,
383  &&CASE_EEOP_BOOL_OR_STEP_LAST,
384  &&CASE_EEOP_BOOL_NOT_STEP,
385  &&CASE_EEOP_QUAL,
386  &&CASE_EEOP_JUMP,
387  &&CASE_EEOP_JUMP_IF_NULL,
388  &&CASE_EEOP_JUMP_IF_NOT_NULL,
389  &&CASE_EEOP_JUMP_IF_NOT_TRUE,
390  &&CASE_EEOP_NULLTEST_ISNULL,
391  &&CASE_EEOP_NULLTEST_ISNOTNULL,
392  &&CASE_EEOP_NULLTEST_ROWISNULL,
393  &&CASE_EEOP_NULLTEST_ROWISNOTNULL,
394  &&CASE_EEOP_BOOLTEST_IS_TRUE,
395  &&CASE_EEOP_BOOLTEST_IS_NOT_TRUE,
396  &&CASE_EEOP_BOOLTEST_IS_FALSE,
397  &&CASE_EEOP_BOOLTEST_IS_NOT_FALSE,
398  &&CASE_EEOP_PARAM_EXEC,
399  &&CASE_EEOP_PARAM_EXTERN,
400  &&CASE_EEOP_PARAM_CALLBACK,
401  &&CASE_EEOP_CASE_TESTVAL,
402  &&CASE_EEOP_MAKE_READONLY,
403  &&CASE_EEOP_IOCOERCE,
404  &&CASE_EEOP_DISTINCT,
405  &&CASE_EEOP_NOT_DISTINCT,
406  &&CASE_EEOP_NULLIF,
407  &&CASE_EEOP_SQLVALUEFUNCTION,
408  &&CASE_EEOP_CURRENTOFEXPR,
409  &&CASE_EEOP_NEXTVALUEEXPR,
410  &&CASE_EEOP_ARRAYEXPR,
411  &&CASE_EEOP_ARRAYCOERCE,
412  &&CASE_EEOP_ROW,
413  &&CASE_EEOP_ROWCOMPARE_STEP,
414  &&CASE_EEOP_ROWCOMPARE_FINAL,
415  &&CASE_EEOP_MINMAX,
416  &&CASE_EEOP_FIELDSELECT,
417  &&CASE_EEOP_FIELDSTORE_DEFORM,
418  &&CASE_EEOP_FIELDSTORE_FORM,
419  &&CASE_EEOP_SBSREF_SUBSCRIPT,
420  &&CASE_EEOP_SBSREF_OLD,
421  &&CASE_EEOP_SBSREF_ASSIGN,
422  &&CASE_EEOP_SBSREF_FETCH,
423  &&CASE_EEOP_DOMAIN_TESTVAL,
424  &&CASE_EEOP_DOMAIN_NOTNULL,
425  &&CASE_EEOP_DOMAIN_CHECK,
426  &&CASE_EEOP_CONVERT_ROWTYPE,
427  &&CASE_EEOP_SCALARARRAYOP,
428  &&CASE_EEOP_XMLEXPR,
429  &&CASE_EEOP_AGGREF,
430  &&CASE_EEOP_GROUPING_FUNC,
431  &&CASE_EEOP_WINDOW_FUNC,
432  &&CASE_EEOP_SUBPLAN,
433  &&CASE_EEOP_ALTERNATIVE_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 
1539  {
1540  /* too complex for an inline implementation */
1541  ExecEvalAlternativeSubPlan(state, op, econtext);
1542 
1543  EEO_NEXT();
1544  }
1545 
1546  /* evaluate a strict aggregate deserialization function */
1548  {
1549  /* Don't call a strict deserialization function with NULL input */
1550  if (op->d.agg_deserialize.fcinfo_data->args[0].isnull)
1551  EEO_JUMP(op->d.agg_deserialize.jumpnull);
1552 
1553  /* fallthrough */
1554  }
1555 
1556  /* evaluate aggregate deserialization function (non-strict portion) */
1558  {
1559  FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
1560  AggState *aggstate = castNode(AggState, state->parent);
1561  MemoryContext oldContext;
1562 
1563  /*
1564  * We run the deserialization functions in per-input-tuple memory
1565  * context.
1566  */
1567  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
1568  fcinfo->isnull = false;
1569  *op->resvalue = FunctionCallInvoke(fcinfo);
1570  *op->resnull = fcinfo->isnull;
1571  MemoryContextSwitchTo(oldContext);
1572 
1573  EEO_NEXT();
1574  }
1575 
1576  /*
1577  * Check that a strict aggregate transition / combination function's
1578  * input is not NULL.
1579  */
1580 
1582  {
1584  int nargs = op->d.agg_strict_input_check.nargs;
1585 
1586  for (int argno = 0; argno < nargs; argno++)
1587  {
1588  if (args[argno].isnull)
1589  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1590  }
1591  EEO_NEXT();
1592  }
1593 
1595  {
1596  bool *nulls = op->d.agg_strict_input_check.nulls;
1597  int nargs = op->d.agg_strict_input_check.nargs;
1598 
1599  for (int argno = 0; argno < nargs; argno++)
1600  {
1601  if (nulls[argno])
1602  EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
1603  }
1604  EEO_NEXT();
1605  }
1606 
1607  /*
1608  * Check for a NULL pointer to the per-group states.
1609  */
1610 
1612  {
1613  AggState *aggstate = castNode(AggState, state->parent);
1614  AggStatePerGroup pergroup_allaggs = aggstate->all_pergroups
1615  [op->d.agg_plain_pergroup_nullcheck.setoff];
1616 
1617  if (pergroup_allaggs == NULL)
1618  EEO_JUMP(op->d.agg_plain_pergroup_nullcheck.jumpnull);
1619 
1620  EEO_NEXT();
1621  }
1622 
1623  /*
1624  * Different types of aggregate transition functions are implemented
1625  * as different types of steps, to avoid incurring unnecessary
1626  * overhead. There's a step type for each valid combination of having
1627  * a by value / by reference transition type, [not] needing to the
1628  * initialize the transition value for the first row in a group from
1629  * input, and [not] strict transition function.
1630  *
1631  * Could optimize further by splitting off by-reference for
1632  * fixed-length types, but currently that doesn't seem worth it.
1633  */
1634 
1636  {
1637  AggState *aggstate = castNode(AggState, state->parent);
1638  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1639  AggStatePerGroup pergroup = &aggstate->all_pergroups
1640  [op->d.agg_trans.setoff]
1641  [op->d.agg_trans.transno];
1642 
1643  Assert(pertrans->transtypeByVal);
1644 
1645  if (pergroup->noTransValue)
1646  {
1647  /* If transValue has not yet been initialized, do so now. */
1648  ExecAggInitGroup(aggstate, pertrans, pergroup,
1649  op->d.agg_trans.aggcontext);
1650  /* copied trans value from input, done this round */
1651  }
1652  else if (likely(!pergroup->transValueIsNull))
1653  {
1654  /* invoke transition function, unless prevented by strictness */
1655  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1656  op->d.agg_trans.aggcontext,
1657  op->d.agg_trans.setno);
1658  }
1659 
1660  EEO_NEXT();
1661  }
1662 
1663  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1665  {
1666  AggState *aggstate = castNode(AggState, state->parent);
1667  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1668  AggStatePerGroup pergroup = &aggstate->all_pergroups
1669  [op->d.agg_trans.setoff]
1670  [op->d.agg_trans.transno];
1671 
1672  Assert(pertrans->transtypeByVal);
1673 
1674  if (likely(!pergroup->transValueIsNull))
1675  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1676  op->d.agg_trans.aggcontext,
1677  op->d.agg_trans.setno);
1678 
1679  EEO_NEXT();
1680  }
1681 
1682  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1684  {
1685  AggState *aggstate = castNode(AggState, state->parent);
1686  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1687  AggStatePerGroup pergroup = &aggstate->all_pergroups
1688  [op->d.agg_trans.setoff]
1689  [op->d.agg_trans.transno];
1690 
1691  Assert(pertrans->transtypeByVal);
1692 
1693  ExecAggPlainTransByVal(aggstate, pertrans, pergroup,
1694  op->d.agg_trans.aggcontext,
1695  op->d.agg_trans.setno);
1696 
1697  EEO_NEXT();
1698  }
1699 
1700  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1702  {
1703  AggState *aggstate = castNode(AggState, state->parent);
1704  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1705  AggStatePerGroup pergroup = &aggstate->all_pergroups
1706  [op->d.agg_trans.setoff]
1707  [op->d.agg_trans.transno];
1708 
1709  Assert(!pertrans->transtypeByVal);
1710 
1711  if (pergroup->noTransValue)
1712  ExecAggInitGroup(aggstate, pertrans, pergroup,
1713  op->d.agg_trans.aggcontext);
1714  else if (likely(!pergroup->transValueIsNull))
1715  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1716  op->d.agg_trans.aggcontext,
1717  op->d.agg_trans.setno);
1718 
1719  EEO_NEXT();
1720  }
1721 
1722  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1724  {
1725  AggState *aggstate = castNode(AggState, state->parent);
1726  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1727  AggStatePerGroup pergroup = &aggstate->all_pergroups
1728  [op->d.agg_trans.setoff]
1729  [op->d.agg_trans.transno];
1730 
1731  Assert(!pertrans->transtypeByVal);
1732 
1733  if (likely(!pergroup->transValueIsNull))
1734  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1735  op->d.agg_trans.aggcontext,
1736  op->d.agg_trans.setno);
1737  EEO_NEXT();
1738  }
1739 
1740  /* see comments above EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL */
1742  {
1743  AggState *aggstate = castNode(AggState, state->parent);
1744  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
1745  AggStatePerGroup pergroup = &aggstate->all_pergroups
1746  [op->d.agg_trans.setoff]
1747  [op->d.agg_trans.transno];
1748 
1749  Assert(!pertrans->transtypeByVal);
1750 
1751  ExecAggPlainTransByRef(aggstate, pertrans, pergroup,
1752  op->d.agg_trans.aggcontext,
1753  op->d.agg_trans.setno);
1754 
1755  EEO_NEXT();
1756  }
1757 
1758  /* process single-column ordered aggregate datum */
1760  {
1761  /* too complex for an inline implementation */
1762  ExecEvalAggOrderedTransDatum(state, op, econtext);
1763 
1764  EEO_NEXT();
1765  }
1766 
1767  /* process multi-column ordered aggregate tuple */
1769  {
1770  /* too complex for an inline implementation */
1771  ExecEvalAggOrderedTransTuple(state, op, econtext);
1772 
1773  EEO_NEXT();
1774  }
1775 
1777  {
1778  /* unreachable */
1779  Assert(false);
1780  goto out;
1781  }
1782  }
1783 
1784 out:
1785  *isnull = state->resnull;
1786  return state->resvalue;
1787 }
1788 
1789 /*
1790  * Expression evaluation callback that performs extra checks before executing
1791  * the expression. Declared extern so other methods of execution can use it
1792  * too.
1793  */
1794 Datum
1796 {
1797  /*
1798  * First time through, check whether attribute matches Var. Might not be
1799  * ok anymore, due to schema changes.
1800  */
1801  CheckExprStillValid(state, econtext);
1802 
1803  /* skip the check during further executions */
1804  state->evalfunc = (ExprStateEvalFunc) state->evalfunc_private;
1805 
1806  /* and actually execute */
1807  return state->evalfunc(state, econtext, isNull);
1808 }
1809 
1810 /*
1811  * Check that an expression is still valid in the face of potential schema
1812  * changes since the plan has been created.
1813  */
1814 void
1816 {
1817  TupleTableSlot *innerslot;
1818  TupleTableSlot *outerslot;
1819  TupleTableSlot *scanslot;
1820 
1821  innerslot = econtext->ecxt_innertuple;
1822  outerslot = econtext->ecxt_outertuple;
1823  scanslot = econtext->ecxt_scantuple;
1824 
1825  for (int i = 0; i < state->steps_len; i++)
1826  {
1827  ExprEvalStep *op = &state->steps[i];
1828 
1829  switch (ExecEvalStepOp(state, op))
1830  {
1831  case EEOP_INNER_VAR:
1832  {
1833  int attnum = op->d.var.attnum;
1834 
1835  CheckVarSlotCompatibility(innerslot, attnum + 1, op->d.var.vartype);
1836  break;
1837  }
1838 
1839  case EEOP_OUTER_VAR:
1840  {
1841  int attnum = op->d.var.attnum;
1842 
1843  CheckVarSlotCompatibility(outerslot, attnum + 1, op->d.var.vartype);
1844  break;
1845  }
1846 
1847  case EEOP_SCAN_VAR:
1848  {
1849  int attnum = op->d.var.attnum;
1850 
1851  CheckVarSlotCompatibility(scanslot, attnum + 1, op->d.var.vartype);
1852  break;
1853  }
1854  default:
1855  break;
1856  }
1857  }
1858 }
1859 
1860 /*
1861  * Check whether a user attribute in a slot can be referenced by a Var
1862  * expression. This should succeed unless there have been schema changes
1863  * since the expression tree has been created.
1864  */
1865 static void
1867 {
1868  /*
1869  * What we have to check for here is the possibility of an attribute
1870  * having been dropped or changed in type since the plan tree was created.
1871  * Ideally the plan will get invalidated and not re-used, but just in
1872  * case, we keep these defenses. Fortunately it's sufficient to check
1873  * once on the first time through.
1874  *
1875  * Note: ideally we'd check typmod as well as typid, but that seems
1876  * impractical at the moment: in many cases the tupdesc will have been
1877  * generated by ExecTypeFromTL(), and that can't guarantee to generate an
1878  * accurate typmod in all cases, because some expression node types don't
1879  * carry typmod. Fortunately, for precisely that reason, there should be
1880  * no places with a critical dependency on the typmod of a value.
1881  *
1882  * System attributes don't require checking since their types never
1883  * change.
1884  */
1885  if (attnum > 0)
1886  {
1887  TupleDesc slot_tupdesc = slot->tts_tupleDescriptor;
1888  Form_pg_attribute attr;
1889 
1890  if (attnum > slot_tupdesc->natts) /* should never happen */
1891  elog(ERROR, "attribute number %d exceeds number of columns %d",
1892  attnum, slot_tupdesc->natts);
1893 
1894  attr = TupleDescAttr(slot_tupdesc, attnum - 1);
1895 
1896  if (attr->attisdropped)
1897  ereport(ERROR,
1898  (errcode(ERRCODE_UNDEFINED_COLUMN),
1899  errmsg("attribute %d of type %s has been dropped",
1900  attnum, format_type_be(slot_tupdesc->tdtypeid))));
1901 
1902  if (vartype != attr->atttypid)
1903  ereport(ERROR,
1904  (errcode(ERRCODE_DATATYPE_MISMATCH),
1905  errmsg("attribute %d of type %s has wrong type",
1906  attnum, format_type_be(slot_tupdesc->tdtypeid)),
1907  errdetail("Table has type %s, but query expects %s.",
1908  format_type_be(attr->atttypid),
1909  format_type_be(vartype))));
1910  }
1911 }
1912 
1913 /*
1914  * Verify that the slot is compatible with a EEOP_*_FETCHSOME operation.
1915  */
1916 static void
1918 {
1919 #ifdef USE_ASSERT_CHECKING
1920  /* there's nothing to check */
1921  if (!op->d.fetch.fixed)
1922  return;
1923 
1924  /*
1925  * Should probably fixed at some point, but for now it's easier to allow
1926  * buffer and heap tuples to be used interchangeably.
1927  */
1928  if (slot->tts_ops == &TTSOpsBufferHeapTuple &&
1929  op->d.fetch.kind == &TTSOpsHeapTuple)
1930  return;
1931  if (slot->tts_ops == &TTSOpsHeapTuple &&
1932  op->d.fetch.kind == &TTSOpsBufferHeapTuple)
1933  return;
1934 
1935  /*
1936  * At the moment we consider it OK if a virtual slot is used instead of a
1937  * specific type of slot, as a virtual slot never needs to be deformed.
1938  */
1939  if (slot->tts_ops == &TTSOpsVirtual)
1940  return;
1941 
1942  Assert(op->d.fetch.kind == slot->tts_ops);
1943 #endif
1944 }
1945 
1946 /*
1947  * get_cached_rowtype: utility function to lookup a rowtype tupdesc
1948  *
1949  * type_id, typmod: identity of the rowtype
1950  * cache_field: where to cache the TupleDesc pointer in expression state node
1951  * (field must be initialized to NULL)
1952  * econtext: expression context we are executing in
1953  *
1954  * NOTE: because the shutdown callback will be called during plan rescan,
1955  * must be prepared to re-do this during any node execution; cannot call
1956  * just once during expression initialization.
1957  */
1958 static TupleDesc
1959 get_cached_rowtype(Oid type_id, int32 typmod,
1960  TupleDesc *cache_field, ExprContext *econtext)
1961 {
1962  TupleDesc tupDesc = *cache_field;
1963 
1964  /* Do lookup if no cached value or if requested type changed */
1965  if (tupDesc == NULL ||
1966  type_id != tupDesc->tdtypeid ||
1967  typmod != tupDesc->tdtypmod)
1968  {
1969  tupDesc = lookup_rowtype_tupdesc(type_id, typmod);
1970 
1971  if (*cache_field)
1972  {
1973  /* Release old tupdesc; but callback is already registered */
1974  ReleaseTupleDesc(*cache_field);
1975  }
1976  else
1977  {
1978  /* Need to register shutdown callback to release tupdesc */
1979  RegisterExprContextCallback(econtext,
1981  PointerGetDatum(cache_field));
1982  }
1983  *cache_field = tupDesc;
1984  }
1985  return tupDesc;
1986 }
1987 
1988 /*
1989  * Callback function to release a tupdesc refcount at econtext shutdown
1990  */
1991 static void
1993 {
1994  TupleDesc *cache_field = (TupleDesc *) DatumGetPointer(arg);
1995 
1996  if (*cache_field)
1997  ReleaseTupleDesc(*cache_field);
1998  *cache_field = NULL;
1999 }
2000 
2001 /*
2002  * Fast-path functions, for very simple expressions
2003  */
2004 
2005 /* implementation of ExecJust(Inner|Outer|Scan)Var */
2008 {
2009  ExprEvalStep *op = &state->steps[1];
2010  int attnum = op->d.var.attnum + 1;
2011 
2012  CheckOpSlotCompatibility(&state->steps[0], slot);
2013 
2014  /*
2015  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2016  * step explicitly, and we also needn't Assert that the attnum is in range
2017  * --- slot_getattr() will take care of any problems.
2018  */
2019  return slot_getattr(slot, attnum, isnull);
2020 }
2021 
2022 /* Simple reference to inner Var */
2023 static Datum
2024 ExecJustInnerVar(ExprState *state, ExprContext *econtext, bool *isnull)
2025 {
2026  return ExecJustVarImpl(state, econtext->ecxt_innertuple, isnull);
2027 }
2028 
2029 /* Simple reference to outer Var */
2030 static Datum
2031 ExecJustOuterVar(ExprState *state, ExprContext *econtext, bool *isnull)
2032 {
2033  return ExecJustVarImpl(state, econtext->ecxt_outertuple, isnull);
2034 }
2035 
2036 /* Simple reference to scan Var */
2037 static Datum
2038 ExecJustScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
2039 {
2040  return ExecJustVarImpl(state, econtext->ecxt_scantuple, isnull);
2041 }
2042 
2043 /* implementation of ExecJustAssign(Inner|Outer|Scan)Var */
2046 {
2047  ExprEvalStep *op = &state->steps[1];
2048  int attnum = op->d.assign_var.attnum + 1;
2049  int resultnum = op->d.assign_var.resultnum;
2050  TupleTableSlot *outslot = state->resultslot;
2051 
2052  CheckOpSlotCompatibility(&state->steps[0], inslot);
2053 
2054  /*
2055  * We do not need CheckVarSlotCompatibility here; that was taken care of
2056  * at compilation time.
2057  *
2058  * Since we use slot_getattr(), we don't need to implement the FETCHSOME
2059  * step explicitly, and we also needn't Assert that the attnum is in range
2060  * --- slot_getattr() will take care of any problems.
2061  */
2062  outslot->tts_values[resultnum] =
2063  slot_getattr(inslot, attnum, &outslot->tts_isnull[resultnum]);
2064  return 0;
2065 }
2066 
2067 /* Evaluate inner Var and assign to appropriate column of result tuple */
2068 static Datum
2070 {
2071  return ExecJustAssignVarImpl(state, econtext->ecxt_innertuple, isnull);
2072 }
2073 
2074 /* Evaluate outer Var and assign to appropriate column of result tuple */
2075 static Datum
2077 {
2078  return ExecJustAssignVarImpl(state, econtext->ecxt_outertuple, isnull);
2079 }
2080 
2081 /* Evaluate scan Var and assign to appropriate column of result tuple */
2082 static Datum
2084 {
2085  return ExecJustAssignVarImpl(state, econtext->ecxt_scantuple, isnull);
2086 }
2087 
2088 /* Evaluate CASE_TESTVAL and apply a strict function to it */
2089 static Datum
2091 {
2092  ExprEvalStep *op = &state->steps[0];
2093  FunctionCallInfo fcinfo;
2095  int nargs;
2096  Datum d;
2097 
2098  /*
2099  * XXX with some redesign of the CaseTestExpr mechanism, maybe we could
2100  * get rid of this data shuffling?
2101  */
2102  *op->resvalue = *op->d.casetest.value;
2103  *op->resnull = *op->d.casetest.isnull;
2104 
2105  op++;
2106 
2107  nargs = op->d.func.nargs;
2108  fcinfo = op->d.func.fcinfo_data;
2109  args = fcinfo->args;
2110 
2111  /* strict function, so check for NULL args */
2112  for (int argno = 0; argno < nargs; argno++)
2113  {
2114  if (args[argno].isnull)
2115  {
2116  *isnull = true;
2117  return (Datum) 0;
2118  }
2119  }
2120  fcinfo->isnull = false;
2121  d = op->d.func.fn_addr(fcinfo);
2122  *isnull = fcinfo->isnull;
2123  return d;
2124 }
2125 
2126 /* Simple Const expression */
2127 static Datum
2128 ExecJustConst(ExprState *state, ExprContext *econtext, bool *isnull)
2129 {
2130  ExprEvalStep *op = &state->steps[0];
2131 
2132  *isnull = op->d.constval.isnull;
2133  return op->d.constval.value;
2134 }
2135 
2136 /* implementation of ExecJust(Inner|Outer|Scan)VarVirt */
2139 {
2140  ExprEvalStep *op = &state->steps[0];
2141  int attnum = op->d.var.attnum;
2142 
2143  /*
2144  * As it is guaranteed that a virtual slot is used, there never is a need
2145  * to perform tuple deforming (nor would it be possible). Therefore
2146  * execExpr.c has not emitted an EEOP_*_FETCHSOME step. Verify, as much as
2147  * possible, that that determination was accurate.
2148  */
2149  Assert(TTS_IS_VIRTUAL(slot));
2150  Assert(TTS_FIXED(slot));
2151  Assert(attnum >= 0 && attnum < slot->tts_nvalid);
2152 
2153  *isnull = slot->tts_isnull[attnum];
2154 
2155  return slot->tts_values[attnum];
2156 }
2157 
2158 /* Like ExecJustInnerVar, optimized for virtual slots */
2159 static Datum
2161 {
2162  return ExecJustVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2163 }
2164 
2165 /* Like ExecJustOuterVar, optimized for virtual slots */
2166 static Datum
2168 {
2169  return ExecJustVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2170 }
2171 
2172 /* Like ExecJustScanVar, optimized for virtual slots */
2173 static Datum
2175 {
2176  return ExecJustVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2177 }
2178 
2179 /* implementation of ExecJustAssign(Inner|Outer|Scan)VarVirt */
2182 {
2183  ExprEvalStep *op = &state->steps[0];
2184  int attnum = op->d.assign_var.attnum;
2185  int resultnum = op->d.assign_var.resultnum;
2186  TupleTableSlot *outslot = state->resultslot;
2187 
2188  /* see ExecJustVarVirtImpl for comments */
2189 
2190  Assert(TTS_IS_VIRTUAL(inslot));
2191  Assert(TTS_FIXED(inslot));
2192  Assert(attnum >= 0 && attnum < inslot->tts_nvalid);
2193 
2194  outslot->tts_values[resultnum] = inslot->tts_values[attnum];
2195  outslot->tts_isnull[resultnum] = inslot->tts_isnull[attnum];
2196 
2197  return 0;
2198 }
2199 
2200 /* Like ExecJustAssignInnerVar, optimized for virtual slots */
2201 static Datum
2203 {
2204  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_innertuple, isnull);
2205 }
2206 
2207 /* Like ExecJustAssignOuterVar, optimized for virtual slots */
2208 static Datum
2210 {
2211  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_outertuple, isnull);
2212 }
2213 
2214 /* Like ExecJustAssignScanVar, optimized for virtual slots */
2215 static Datum
2217 {
2218  return ExecJustAssignVarVirtImpl(state, econtext->ecxt_scantuple, isnull);
2219 }
2220 
2221 #if defined(EEO_USE_COMPUTED_GOTO)
2222 /*
2223  * Comparator used when building address->opcode lookup table for
2224  * ExecEvalStepOp() in the threaded dispatch case.
2225  */
2226 static int
2227 dispatch_compare_ptr(const void *a, const void *b)
2228 {
2229  const ExprEvalOpLookup *la = (const ExprEvalOpLookup *) a;
2230  const ExprEvalOpLookup *lb = (const ExprEvalOpLookup *) b;
2231 
2232  if (la->opcode < lb->opcode)
2233  return -1;
2234  else if (la->opcode > lb->opcode)
2235  return 1;
2236  return 0;
2237 }
2238 #endif
2239 
2240 /*
2241  * Do one-time initialization of interpretation machinery.
2242  */
2243 static void
2245 {
2246 #if defined(EEO_USE_COMPUTED_GOTO)
2247  /* Set up externally-visible pointer to dispatch table */
2248  if (dispatch_table == NULL)
2249  {
2250  dispatch_table = (const void **)
2251  DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
2252 
2253  /* build reverse lookup table */
2254  for (int i = 0; i < EEOP_LAST; i++)
2255  {
2256  reverse_dispatch_table[i].opcode = dispatch_table[i];
2257  reverse_dispatch_table[i].op = (ExprEvalOp) i;
2258  }
2259 
2260  /* make it bsearch()able */
2261  qsort(reverse_dispatch_table,
2262  EEOP_LAST /* nmembers */ ,
2263  sizeof(ExprEvalOpLookup),
2264  dispatch_compare_ptr);
2265  }
2266 #endif
2267 }
2268 
2269 /*
2270  * Function to return the opcode of an expression step.
2271  *
2272  * When direct-threading is in use, ExprState->opcode isn't easily
2273  * decipherable. This function returns the appropriate enum member.
2274  */
2275 ExprEvalOp
2277 {
2278 #if defined(EEO_USE_COMPUTED_GOTO)
2279  if (state->flags & EEO_FLAG_DIRECT_THREADED)
2280  {
2281  ExprEvalOpLookup key;
2282  ExprEvalOpLookup *res;
2283 
2284  key.opcode = (void *) op->opcode;
2285  res = bsearch(&key,
2286  reverse_dispatch_table,
2287  EEOP_LAST /* nmembers */ ,
2288  sizeof(ExprEvalOpLookup),
2289  dispatch_compare_ptr);
2290  Assert(res); /* unknown ops shouldn't get looked up */
2291  return res->op;
2292  }
2293 #endif
2294  return (ExprEvalOp) op->opcode;
2295 }
2296 
2297 
2298 /*
2299  * Out-of-line helper functions for complex instructions.
2300  */
2301 
2302 /*
2303  * Evaluate EEOP_FUNCEXPR_FUSAGE
2304  */
2305 void
2307  ExprContext *econtext)
2308 {
2309  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2310  PgStat_FunctionCallUsage fcusage;
2311  Datum d;
2312 
2313  pgstat_init_function_usage(fcinfo, &fcusage);
2314 
2315  fcinfo->isnull = false;
2316  d = op->d.func.fn_addr(fcinfo);
2317  *op->resvalue = d;
2318  *op->resnull = fcinfo->isnull;
2319 
2320  pgstat_end_function_usage(&fcusage, true);
2321 }
2322 
2323 /*
2324  * Evaluate EEOP_FUNCEXPR_STRICT_FUSAGE
2325  */
2326 void
2328  ExprContext *econtext)
2329 {
2330 
2331  FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
2332  PgStat_FunctionCallUsage fcusage;
2333  NullableDatum *args = fcinfo->args;
2334  int nargs = op->d.func.nargs;
2335  Datum d;
2336 
2337  /* strict function, so check for NULL args */
2338  for (int argno = 0; argno < nargs; argno++)
2339  {
2340  if (args[argno].isnull)
2341  {
2342  *op->resnull = true;
2343  return;
2344  }
2345  }
2346 
2347  pgstat_init_function_usage(fcinfo, &fcusage);
2348 
2349  fcinfo->isnull = false;
2350  d = op->d.func.fn_addr(fcinfo);
2351  *op->resvalue = d;
2352  *op->resnull = fcinfo->isnull;
2353 
2354  pgstat_end_function_usage(&fcusage, true);
2355 }
2356 
2357 /*
2358  * Evaluate a PARAM_EXEC parameter.
2359  *
2360  * PARAM_EXEC params (internal executor parameters) are stored in the
2361  * ecxt_param_exec_vals array, and can be accessed by array index.
2362  */
2363 void
2365 {
2366  ParamExecData *prm;
2367 
2368  prm = &(econtext->ecxt_param_exec_vals[op->d.param.paramid]);
2369  if (unlikely(prm->execPlan != NULL))
2370  {
2371  /* Parameter not evaluated yet, so go do it */
2372  ExecSetParamPlan(prm->execPlan, econtext);
2373  /* ExecSetParamPlan should have processed this param... */
2374  Assert(prm->execPlan == NULL);
2375  }
2376  *op->resvalue = prm->value;
2377  *op->resnull = prm->isnull;
2378 }
2379 
2380 /*
2381  * Evaluate a PARAM_EXTERN parameter.
2382  *
2383  * PARAM_EXTERN parameters must be sought in ecxt_param_list_info.
2384  */
2385 void
2387 {
2388  ParamListInfo paramInfo = econtext->ecxt_param_list_info;
2389  int paramId = op->d.param.paramid;
2390 
2391  if (likely(paramInfo &&
2392  paramId > 0 && paramId <= paramInfo->numParams))
2393  {
2394  ParamExternData *prm;
2395  ParamExternData prmdata;
2396 
2397  /* give hook a chance in case parameter is dynamic */
2398  if (paramInfo->paramFetch != NULL)
2399  prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata);
2400  else
2401  prm = &paramInfo->params[paramId - 1];
2402 
2403  if (likely(OidIsValid(prm->ptype)))
2404  {
2405  /* safety check in case hook did something unexpected */
2406  if (unlikely(prm->ptype != op->d.param.paramtype))
2407  ereport(ERROR,
2408  (errcode(ERRCODE_DATATYPE_MISMATCH),
2409  errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)",
2410  paramId,
2411  format_type_be(prm->ptype),
2412  format_type_be(op->d.param.paramtype))));
2413  *op->resvalue = prm->value;
2414  *op->resnull = prm->isnull;
2415  return;
2416  }
2417  }
2418 
2419  ereport(ERROR,
2420  (errcode(ERRCODE_UNDEFINED_OBJECT),
2421  errmsg("no value found for parameter %d", paramId)));
2422 }
2423 
2424 /*
2425  * Evaluate a SQLValueFunction expression.
2426  */
2427 void
2429 {
2430  LOCAL_FCINFO(fcinfo, 0);
2431  SQLValueFunction *svf = op->d.sqlvaluefunction.svf;
2432 
2433  *op->resnull = false;
2434 
2435  /*
2436  * Note: current_schema() can return NULL. current_user() etc currently
2437  * cannot, but might as well code those cases the same way for safety.
2438  */
2439  switch (svf->op)
2440  {
2441  case SVFOP_CURRENT_DATE:
2443  break;
2444  case SVFOP_CURRENT_TIME:
2445  case SVFOP_CURRENT_TIME_N:
2447  break;
2451  break;
2452  case SVFOP_LOCALTIME:
2453  case SVFOP_LOCALTIME_N:
2455  break;
2456  case SVFOP_LOCALTIMESTAMP:
2459  break;
2460  case SVFOP_CURRENT_ROLE:
2461  case SVFOP_CURRENT_USER:
2462  case SVFOP_USER:
2463  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2464  *op->resvalue = current_user(fcinfo);
2465  *op->resnull = fcinfo->isnull;
2466  break;
2467  case SVFOP_SESSION_USER:
2468  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2469  *op->resvalue = session_user(fcinfo);
2470  *op->resnull = fcinfo->isnull;
2471  break;
2472  case SVFOP_CURRENT_CATALOG:
2473  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2474  *op->resvalue = current_database(fcinfo);
2475  *op->resnull = fcinfo->isnull;
2476  break;
2477  case SVFOP_CURRENT_SCHEMA:
2478  InitFunctionCallInfoData(*fcinfo, NULL, 0, InvalidOid, NULL, NULL);
2479  *op->resvalue = current_schema(fcinfo);
2480  *op->resnull = fcinfo->isnull;
2481  break;
2482  }
2483 }
2484 
2485 /*
2486  * Raise error if a CURRENT OF expression is evaluated.
2487  *
2488  * The planner should convert CURRENT OF into a TidScan qualification, or some
2489  * other special handling in a ForeignScan node. So we have to be able to do
2490  * ExecInitExpr on a CurrentOfExpr, but we shouldn't ever actually execute it.
2491  * If we get here, we suppose we must be dealing with CURRENT OF on a foreign
2492  * table whose FDW doesn't handle it, and complain accordingly.
2493  */
2494 void
2496 {
2497  ereport(ERROR,
2498  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2499  errmsg("WHERE CURRENT OF is not supported for this table type")));
2500 }
2501 
2502 /*
2503  * Evaluate NextValueExpr.
2504  */
2505 void
2507 {
2508  int64 newval = nextval_internal(op->d.nextvalueexpr.seqid, false);
2509 
2510  switch (op->d.nextvalueexpr.seqtypid)
2511  {
2512  case INT2OID:
2513  *op->resvalue = Int16GetDatum((int16) newval);
2514  break;
2515  case INT4OID:
2516  *op->resvalue = Int32GetDatum((int32) newval);
2517  break;
2518  case INT8OID:
2519  *op->resvalue = Int64GetDatum((int64) newval);
2520  break;
2521  default:
2522  elog(ERROR, "unsupported sequence type %u",
2523  op->d.nextvalueexpr.seqtypid);
2524  }
2525  *op->resnull = false;
2526 }
2527 
2528 /*
2529  * Evaluate NullTest / IS NULL for rows.
2530  */
2531 void
2533 {
2534  ExecEvalRowNullInt(state, op, econtext, true);
2535 }
2536 
2537 /*
2538  * Evaluate NullTest / IS NOT NULL for rows.
2539  */
2540 void
2542 {
2543  ExecEvalRowNullInt(state, op, econtext, false);
2544 }
2545 
2546 /* Common code for IS [NOT] NULL on a row value */
2547 static void
2549  ExprContext *econtext, bool checkisnull)
2550 {
2551  Datum value = *op->resvalue;
2552  bool isnull = *op->resnull;
2553  HeapTupleHeader tuple;
2554  Oid tupType;
2555  int32 tupTypmod;
2556  TupleDesc tupDesc;
2557  HeapTupleData tmptup;
2558 
2559  *op->resnull = false;
2560 
2561  /* NULL row variables are treated just as NULL scalar columns */
2562  if (isnull)
2563  {
2564  *op->resvalue = BoolGetDatum(checkisnull);
2565  return;
2566  }
2567 
2568  /*
2569  * The SQL standard defines IS [NOT] NULL for a non-null rowtype argument
2570  * as:
2571  *
2572  * "R IS NULL" is true if every field is the null value.
2573  *
2574  * "R IS NOT NULL" is true if no field is the null value.
2575  *
2576  * This definition is (apparently intentionally) not recursive; so our
2577  * tests on the fields are primitive attisnull tests, not recursive checks
2578  * to see if they are all-nulls or no-nulls rowtypes.
2579  *
2580  * The standard does not consider the possibility of zero-field rows, but
2581  * here we consider them to vacuously satisfy both predicates.
2582  */
2583 
2584  tuple = DatumGetHeapTupleHeader(value);
2585 
2586  tupType = HeapTupleHeaderGetTypeId(tuple);
2587  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
2588 
2589  /* Lookup tupdesc if first time through or if type changes */
2590  tupDesc = get_cached_rowtype(tupType, tupTypmod,
2591  &op->d.nulltest_row.argdesc,
2592  econtext);
2593 
2594  /*
2595  * heap_attisnull needs a HeapTuple not a bare HeapTupleHeader.
2596  */
2597  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
2598  tmptup.t_data = tuple;
2599 
2600  for (int att = 1; att <= tupDesc->natts; att++)
2601  {
2602  /* ignore dropped columns */
2603  if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
2604  continue;
2605  if (heap_attisnull(&tmptup, att, tupDesc))
2606  {
2607  /* null field disproves IS NOT NULL */
2608  if (!checkisnull)
2609  {
2610  *op->resvalue = BoolGetDatum(false);
2611  return;
2612  }
2613  }
2614  else
2615  {
2616  /* non-null field disproves IS NULL */
2617  if (checkisnull)
2618  {
2619  *op->resvalue = BoolGetDatum(false);
2620  return;
2621  }
2622  }
2623  }
2624 
2625  *op->resvalue = BoolGetDatum(true);
2626 }
2627 
2628 /*
2629  * Evaluate an ARRAY[] expression.
2630  *
2631  * The individual array elements (or subarrays) have already been evaluated
2632  * into op->d.arrayexpr.elemvalues[]/elemnulls[].
2633  */
2634 void
2636 {
2637  ArrayType *result;
2638  Oid element_type = op->d.arrayexpr.elemtype;
2639  int nelems = op->d.arrayexpr.nelems;
2640  int ndims = 0;
2641  int dims[MAXDIM];
2642  int lbs[MAXDIM];
2643 
2644  /* Set non-null as default */
2645  *op->resnull = false;
2646 
2647  if (!op->d.arrayexpr.multidims)
2648  {
2649  /* Elements are presumably of scalar type */
2650  Datum *dvalues = op->d.arrayexpr.elemvalues;
2651  bool *dnulls = op->d.arrayexpr.elemnulls;
2652 
2653  /* setup for 1-D array of the given length */
2654  ndims = 1;
2655  dims[0] = nelems;
2656  lbs[0] = 1;
2657 
2658  result = construct_md_array(dvalues, dnulls, ndims, dims, lbs,
2659  element_type,
2660  op->d.arrayexpr.elemlength,
2661  op->d.arrayexpr.elembyval,
2662  op->d.arrayexpr.elemalign);
2663  }
2664  else
2665  {
2666  /* Must be nested array expressions */
2667  int nbytes = 0;
2668  int nitems = 0;
2669  int outer_nelems = 0;
2670  int elem_ndims = 0;
2671  int *elem_dims = NULL;
2672  int *elem_lbs = NULL;
2673  bool firstone = true;
2674  bool havenulls = false;
2675  bool haveempty = false;
2676  char **subdata;
2677  bits8 **subbitmaps;
2678  int *subbytes;
2679  int *subnitems;
2680  int32 dataoffset;
2681  char *dat;
2682  int iitem;
2683 
2684  subdata = (char **) palloc(nelems * sizeof(char *));
2685  subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
2686  subbytes = (int *) palloc(nelems * sizeof(int));
2687  subnitems = (int *) palloc(nelems * sizeof(int));
2688 
2689  /* loop through and get data area from each element */
2690  for (int elemoff = 0; elemoff < nelems; elemoff++)
2691  {
2692  Datum arraydatum;
2693  bool eisnull;
2694  ArrayType *array;
2695  int this_ndims;
2696 
2697  arraydatum = op->d.arrayexpr.elemvalues[elemoff];
2698  eisnull = op->d.arrayexpr.elemnulls[elemoff];
2699 
2700  /* temporarily ignore null subarrays */
2701  if (eisnull)
2702  {
2703  haveempty = true;
2704  continue;
2705  }
2706 
2707  array = DatumGetArrayTypeP(arraydatum);
2708 
2709  /* run-time double-check on element type */
2710  if (element_type != ARR_ELEMTYPE(array))
2711  ereport(ERROR,
2712  (errcode(ERRCODE_DATATYPE_MISMATCH),
2713  errmsg("cannot merge incompatible arrays"),
2714  errdetail("Array with element type %s cannot be "
2715  "included in ARRAY construct with element type %s.",
2716  format_type_be(ARR_ELEMTYPE(array)),
2717  format_type_be(element_type))));
2718 
2719  this_ndims = ARR_NDIM(array);
2720  /* temporarily ignore zero-dimensional subarrays */
2721  if (this_ndims <= 0)
2722  {
2723  haveempty = true;
2724  continue;
2725  }
2726 
2727  if (firstone)
2728  {
2729  /* Get sub-array details from first member */
2730  elem_ndims = this_ndims;
2731  ndims = elem_ndims + 1;
2732  if (ndims <= 0 || ndims > MAXDIM)
2733  ereport(ERROR,
2734  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
2735  errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
2736  ndims, MAXDIM)));
2737 
2738  elem_dims = (int *) palloc(elem_ndims * sizeof(int));
2739  memcpy(elem_dims, ARR_DIMS(array), elem_ndims * sizeof(int));
2740  elem_lbs = (int *) palloc(elem_ndims * sizeof(int));
2741  memcpy(elem_lbs, ARR_LBOUND(array), elem_ndims * sizeof(int));
2742 
2743  firstone = false;
2744  }
2745  else
2746  {
2747  /* Check other sub-arrays are compatible */
2748  if (elem_ndims != this_ndims ||
2749  memcmp(elem_dims, ARR_DIMS(array),
2750  elem_ndims * sizeof(int)) != 0 ||
2751  memcmp(elem_lbs, ARR_LBOUND(array),
2752  elem_ndims * sizeof(int)) != 0)
2753  ereport(ERROR,
2754  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2755  errmsg("multidimensional arrays must have array "
2756  "expressions with matching dimensions")));
2757  }
2758 
2759  subdata[outer_nelems] = ARR_DATA_PTR(array);
2760  subbitmaps[outer_nelems] = ARR_NULLBITMAP(array);
2761  subbytes[outer_nelems] = ARR_SIZE(array) - ARR_DATA_OFFSET(array);
2762  nbytes += subbytes[outer_nelems];
2763  subnitems[outer_nelems] = ArrayGetNItems(this_ndims,
2764  ARR_DIMS(array));
2765  nitems += subnitems[outer_nelems];
2766  havenulls |= ARR_HASNULL(array);
2767  outer_nelems++;
2768  }
2769 
2770  /*
2771  * If all items were null or empty arrays, return an empty array;
2772  * otherwise, if some were and some weren't, raise error. (Note: we
2773  * must special-case this somehow to avoid trying to generate a 1-D
2774  * array formed from empty arrays. It's not ideal...)
2775  */
2776  if (haveempty)
2777  {
2778  if (ndims == 0) /* didn't find any nonempty array */
2779  {
2780  *op->resvalue = PointerGetDatum(construct_empty_array(element_type));
2781  return;
2782  }
2783  ereport(ERROR,
2784  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
2785  errmsg("multidimensional arrays must have array "
2786  "expressions with matching dimensions")));
2787  }
2788 
2789  /* setup for multi-D array */
2790  dims[0] = outer_nelems;
2791  lbs[0] = 1;
2792  for (int i = 1; i < ndims; i++)
2793  {
2794  dims[i] = elem_dims[i - 1];
2795  lbs[i] = elem_lbs[i - 1];
2796  }
2797 
2798  if (havenulls)
2799  {
2800  dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
2801  nbytes += dataoffset;
2802  }
2803  else
2804  {
2805  dataoffset = 0; /* marker for no null bitmap */
2806  nbytes += ARR_OVERHEAD_NONULLS(ndims);
2807  }
2808 
2809  result = (ArrayType *) palloc(nbytes);
2810  SET_VARSIZE(result, nbytes);
2811  result->ndim = ndims;
2812  result->dataoffset = dataoffset;
2813  result->elemtype = element_type;
2814  memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
2815  memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
2816 
2817  dat = ARR_DATA_PTR(result);
2818  iitem = 0;
2819  for (int i = 0; i < outer_nelems; i++)
2820  {
2821  memcpy(dat, subdata[i], subbytes[i]);
2822  dat += subbytes[i];
2823  if (havenulls)
2824  array_bitmap_copy(ARR_NULLBITMAP(result), iitem,
2825  subbitmaps[i], 0,
2826  subnitems[i]);
2827  iitem += subnitems[i];
2828  }
2829  }
2830 
2831  *op->resvalue = PointerGetDatum(result);
2832 }
2833 
2834 /*
2835  * Evaluate an ArrayCoerceExpr expression.
2836  *
2837  * Source array is in step's result variable.
2838  */
2839 void
2841 {
2842  Datum arraydatum;
2843 
2844  /* NULL array -> NULL result */
2845  if (*op->resnull)
2846  return;
2847 
2848  arraydatum = *op->resvalue;
2849 
2850  /*
2851  * If it's binary-compatible, modify the element type in the array header,
2852  * but otherwise leave the array as we received it.
2853  */
2854  if (op->d.arraycoerce.elemexprstate == NULL)
2855  {
2856  /* Detoast input array if necessary, and copy in any case */
2857  ArrayType *array = DatumGetArrayTypePCopy(arraydatum);
2858 
2859  ARR_ELEMTYPE(array) = op->d.arraycoerce.resultelemtype;
2860  *op->resvalue = PointerGetDatum(array);
2861  return;
2862  }
2863 
2864  /*
2865  * Use array_map to apply the sub-expression to each array element.
2866  */
2867  *op->resvalue = array_map(arraydatum,
2868  op->d.arraycoerce.elemexprstate,
2869  econtext,
2870  op->d.arraycoerce.resultelemtype,
2871  op->d.arraycoerce.amstate);
2872 }
2873 
2874 /*
2875  * Evaluate a ROW() expression.
2876  *
2877  * The individual columns have already been evaluated into
2878  * op->d.row.elemvalues[]/elemnulls[].
2879  */
2880 void
2882 {
2883  HeapTuple tuple;
2884 
2885  /* build tuple from evaluated field values */
2886  tuple = heap_form_tuple(op->d.row.tupdesc,
2887  op->d.row.elemvalues,
2888  op->d.row.elemnulls);
2889 
2890  *op->resvalue = HeapTupleGetDatum(tuple);
2891  *op->resnull = false;
2892 }
2893 
2894 /*
2895  * Evaluate GREATEST() or LEAST() expression (note this is *not* MIN()/MAX()).
2896  *
2897  * All of the to-be-compared expressions have already been evaluated into
2898  * op->d.minmax.values[]/nulls[].
2899  */
2900 void
2902 {
2903  Datum *values = op->d.minmax.values;
2904  bool *nulls = op->d.minmax.nulls;
2905  FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
2906  MinMaxOp operator = op->d.minmax.op;
2907 
2908  /* set at initialization */
2909  Assert(fcinfo->args[0].isnull == false);
2910  Assert(fcinfo->args[1].isnull == false);
2911 
2912  /* default to null result */
2913  *op->resnull = true;
2914 
2915  for (int off = 0; off < op->d.minmax.nelems; off++)
2916  {
2917  /* ignore NULL inputs */
2918  if (nulls[off])
2919  continue;
2920 
2921  if (*op->resnull)
2922  {
2923  /* first nonnull input, adopt value */
2924  *op->resvalue = values[off];
2925  *op->resnull = false;
2926  }
2927  else
2928  {
2929  int cmpresult;
2930 
2931  /* apply comparison function */
2932  fcinfo->args[0].value = *op->resvalue;
2933  fcinfo->args[1].value = values[off];
2934 
2935  fcinfo->isnull = false;
2936  cmpresult = DatumGetInt32(FunctionCallInvoke(fcinfo));
2937  if (fcinfo->isnull) /* probably should not happen */
2938  continue;
2939 
2940  if (cmpresult > 0 && operator == IS_LEAST)
2941  *op->resvalue = values[off];
2942  else if (cmpresult < 0 && operator == IS_GREATEST)
2943  *op->resvalue = values[off];
2944  }
2945  }
2946 }
2947 
2948 /*
2949  * Evaluate a FieldSelect node.
2950  *
2951  * Source record is in step's result variable.
2952  */
2953 void
2955 {
2956  AttrNumber fieldnum = op->d.fieldselect.fieldnum;
2957  Datum tupDatum;
2958  HeapTupleHeader tuple;
2959  Oid tupType;
2960  int32 tupTypmod;
2961  TupleDesc tupDesc;
2962  Form_pg_attribute attr;
2963  HeapTupleData tmptup;
2964 
2965  /* NULL record -> NULL result */
2966  if (*op->resnull)
2967  return;
2968 
2969  tupDatum = *op->resvalue;
2970 
2971  /* We can special-case expanded records for speed */
2973  {
2975 
2976  Assert(erh->er_magic == ER_MAGIC);
2977 
2978  /* Extract record's TupleDesc */
2979  tupDesc = expanded_record_get_tupdesc(erh);
2980 
2981  /*
2982  * Find field's attr record. Note we don't support system columns
2983  * here: a datum tuple doesn't have valid values for most of the
2984  * interesting system columns anyway.
2985  */
2986  if (fieldnum <= 0) /* should never happen */
2987  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
2988  fieldnum);
2989  if (fieldnum > tupDesc->natts) /* should never happen */
2990  elog(ERROR, "attribute number %d exceeds number of columns %d",
2991  fieldnum, tupDesc->natts);
2992  attr = TupleDescAttr(tupDesc, fieldnum - 1);
2993 
2994  /* Check for dropped column, and force a NULL result if so */
2995  if (attr->attisdropped)
2996  {
2997  *op->resnull = true;
2998  return;
2999  }
3000 
3001  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3002  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3003  if (op->d.fieldselect.resulttype != attr->atttypid)
3004  ereport(ERROR,
3005  (errcode(ERRCODE_DATATYPE_MISMATCH),
3006  errmsg("attribute %d has wrong type", fieldnum),
3007  errdetail("Table has type %s, but query expects %s.",
3008  format_type_be(attr->atttypid),
3009  format_type_be(op->d.fieldselect.resulttype))));
3010 
3011  /* extract the field */
3012  *op->resvalue = expanded_record_get_field(erh, fieldnum,
3013  op->resnull);
3014  }
3015  else
3016  {
3017  /* Get the composite datum and extract its type fields */
3018  tuple = DatumGetHeapTupleHeader(tupDatum);
3019 
3020  tupType = HeapTupleHeaderGetTypeId(tuple);
3021  tupTypmod = HeapTupleHeaderGetTypMod(tuple);
3022 
3023  /* Lookup tupdesc if first time through or if type changes */
3024  tupDesc = get_cached_rowtype(tupType, tupTypmod,
3025  &op->d.fieldselect.argdesc,
3026  econtext);
3027 
3028  /*
3029  * Find field's attr record. Note we don't support system columns
3030  * here: a datum tuple doesn't have valid values for most of the
3031  * interesting system columns anyway.
3032  */
3033  if (fieldnum <= 0) /* should never happen */
3034  elog(ERROR, "unsupported reference to system column %d in FieldSelect",
3035  fieldnum);
3036  if (fieldnum > tupDesc->natts) /* should never happen */
3037  elog(ERROR, "attribute number %d exceeds number of columns %d",
3038  fieldnum, tupDesc->natts);
3039  attr = TupleDescAttr(tupDesc, fieldnum - 1);
3040 
3041  /* Check for dropped column, and force a NULL result if so */
3042  if (attr->attisdropped)
3043  {
3044  *op->resnull = true;
3045  return;
3046  }
3047 
3048  /* Check for type mismatch --- possible after ALTER COLUMN TYPE? */
3049  /* As in CheckVarSlotCompatibility, we should but can't check typmod */
3050  if (op->d.fieldselect.resulttype != attr->atttypid)
3051  ereport(ERROR,
3052  (errcode(ERRCODE_DATATYPE_MISMATCH),
3053  errmsg("attribute %d has wrong type", fieldnum),
3054  errdetail("Table has type %s, but query expects %s.",
3055  format_type_be(attr->atttypid),
3056  format_type_be(op->d.fieldselect.resulttype))));
3057 
3058  /* heap_getattr needs a HeapTuple not a bare HeapTupleHeader */
3059  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3060  tmptup.t_data = tuple;
3061 
3062  /* extract the field */
3063  *op->resvalue = heap_getattr(&tmptup,
3064  fieldnum,
3065  tupDesc,
3066  op->resnull);
3067  }
3068 }
3069 
3070 /*
3071  * Deform source tuple, filling in the step's values/nulls arrays, before
3072  * evaluating individual new values as part of a FieldStore expression.
3073  * Subsequent steps will overwrite individual elements of the values/nulls
3074  * arrays with the new field values, and then FIELDSTORE_FORM will build the
3075  * new tuple value.
3076  *
3077  * Source record is in step's result variable.
3078  */
3079 void
3081 {
3082  TupleDesc tupDesc;
3083 
3084  /* Lookup tupdesc if first time through or after rescan */
3085  tupDesc = get_cached_rowtype(op->d.fieldstore.fstore->resulttype, -1,
3086  op->d.fieldstore.argdesc, econtext);
3087 
3088  /* Check that current tupdesc doesn't have more fields than we allocated */
3089  if (unlikely(tupDesc->natts > op->d.fieldstore.ncolumns))
3090  elog(ERROR, "too many columns in composite type %u",
3091  op->d.fieldstore.fstore->resulttype);
3092 
3093  if (*op->resnull)
3094  {
3095  /* Convert null input tuple into an all-nulls row */
3096  memset(op->d.fieldstore.nulls, true,
3097  op->d.fieldstore.ncolumns * sizeof(bool));
3098  }
3099  else
3100  {
3101  /*
3102  * heap_deform_tuple needs a HeapTuple not a bare HeapTupleHeader. We
3103  * set all the fields in the struct just in case.
3104  */
3105  Datum tupDatum = *op->resvalue;
3106  HeapTupleHeader tuphdr;
3107  HeapTupleData tmptup;
3108 
3109  tuphdr = DatumGetHeapTupleHeader(tupDatum);
3110  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuphdr);
3111  ItemPointerSetInvalid(&(tmptup.t_self));
3112  tmptup.t_tableOid = InvalidOid;
3113  tmptup.t_data = tuphdr;
3114 
3115  heap_deform_tuple(&tmptup, tupDesc,
3116  op->d.fieldstore.values,
3117  op->d.fieldstore.nulls);
3118  }
3119 }
3120 
3121 /*
3122  * Compute the new composite datum after each individual field value of a
3123  * FieldStore expression has been evaluated.
3124  */
3125 void
3127 {
3128  HeapTuple tuple;
3129 
3130  /* argdesc should already be valid from the DeForm step */
3131  tuple = heap_form_tuple(*op->d.fieldstore.argdesc,
3132  op->d.fieldstore.values,
3133  op->d.fieldstore.nulls);
3134 
3135  *op->resvalue = HeapTupleGetDatum(tuple);
3136  *op->resnull = false;
3137 }
3138 
3139 /*
3140  * Process a subscript in a SubscriptingRef expression.
3141  *
3142  * If subscript is NULL, throw error in assignment case, or in fetch case
3143  * set result to NULL and return false (instructing caller to skip the rest
3144  * of the SubscriptingRef sequence).
3145  *
3146  * Subscript expression result is in subscriptvalue/subscriptnull.
3147  * On success, integer subscript value has been saved in upperindex[] or
3148  * lowerindex[] for use later.
3149  */
3150 bool
3152 {
3153  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3154  int *indexes;
3155  int off;
3156 
3157  /* If any index expr yields NULL, result is NULL or error */
3158  if (sbsrefstate->subscriptnull)
3159  {
3160  if (sbsrefstate->isassignment)
3161  ereport(ERROR,
3162  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3163  errmsg("array subscript in assignment must not be null")));
3164  *op->resnull = true;
3165  return false;
3166  }
3167 
3168  /* Convert datum to int, save in appropriate place */
3169  if (op->d.sbsref_subscript.isupper)
3170  indexes = sbsrefstate->upperindex;
3171  else
3172  indexes = sbsrefstate->lowerindex;
3173  off = op->d.sbsref_subscript.off;
3174 
3175  indexes[off] = DatumGetInt32(sbsrefstate->subscriptvalue);
3176 
3177  return true;
3178 }
3179 
3180 /*
3181  * Evaluate SubscriptingRef fetch.
3182  *
3183  * Source container is in step's result variable.
3184  */
3185 void
3187 {
3188  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3189 
3190  /* Should not get here if source container (or any subscript) is null */
3191  Assert(!(*op->resnull));
3192 
3193  if (sbsrefstate->numlower == 0)
3194  {
3195  /* Scalar case */
3196  *op->resvalue = array_get_element(*op->resvalue,
3197  sbsrefstate->numupper,
3198  sbsrefstate->upperindex,
3199  sbsrefstate->refattrlength,
3200  sbsrefstate->refelemlength,
3201  sbsrefstate->refelembyval,
3202  sbsrefstate->refelemalign,
3203  op->resnull);
3204  }
3205  else
3206  {
3207  /* Slice case */
3208  *op->resvalue = array_get_slice(*op->resvalue,
3209  sbsrefstate->numupper,
3210  sbsrefstate->upperindex,
3211  sbsrefstate->lowerindex,
3212  sbsrefstate->upperprovided,
3213  sbsrefstate->lowerprovided,
3214  sbsrefstate->refattrlength,
3215  sbsrefstate->refelemlength,
3216  sbsrefstate->refelembyval,
3217  sbsrefstate->refelemalign);
3218  }
3219 }
3220 
3221 /*
3222  * Compute old container element/slice value for a SubscriptingRef assignment
3223  * expression. Will only be generated if the new-value subexpression
3224  * contains SubscriptingRef or FieldStore. The value is stored into the
3225  * SubscriptingRefState's prevvalue/prevnull fields.
3226  */
3227 void
3229 {
3230  SubscriptingRefState *sbsrefstate = op->d.sbsref.state;
3231 
3232  if (*op->resnull)
3233  {
3234  /* whole array is null, so any element or slice is too */
3235  sbsrefstate->prevvalue = (Datum) 0;
3236  sbsrefstate->prevnull = true;
3237  }
3238  else if (sbsrefstate->numlower == 0)
3239  {
3240  /* Scalar case */
3241  sbsrefstate->prevvalue = array_get_element(*op->resvalue,
3242  sbsrefstate->numupper,
3243  sbsrefstate->upperindex,
3244  sbsrefstate->refattrlength,
3245  sbsrefstate->refelemlength,
3246  sbsrefstate->refelembyval,
3247  sbsrefstate->refelemalign,
3248  &sbsrefstate->prevnull);
3249  }
3250  else
3251  {
3252  /* Slice case */
3253  /* this is currently unreachable */
3254  sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
3255  sbsrefstate->numupper,
3256  sbsrefstate->upperindex,
3257  sbsrefstate->lowerindex,
3258  sbsrefstate->upperprovided,
3259  sbsrefstate->lowerprovided,
3260  sbsrefstate->refattrlength,
3261  sbsrefstate->refelemlength,
3262  sbsrefstate->refelembyval,
3263  sbsrefstate->refelemalign);
3264  sbsrefstate->prevnull = false;
3265  }
3266 }
3267 
3268 /*
3269  * Evaluate SubscriptingRef assignment.
3270  *
3271  * Input container (possibly null) is in result area, replacement value is in
3272  * SubscriptingRefState's replacevalue/replacenull.
3273  */
3274 void
3276 {
3277  SubscriptingRefState *sbsrefstate = op->d.sbsref_subscript.state;
3278 
3279  /*
3280  * For an assignment to a fixed-length container type, both the original
3281  * container and the value to be assigned into it must be non-NULL, else
3282  * we punt and return the original container.
3283  */
3284  if (sbsrefstate->refattrlength > 0)
3285  {
3286  if (*op->resnull || sbsrefstate->replacenull)
3287  return;
3288  }
3289 
3290  /*
3291  * For assignment to varlena arrays, we handle a NULL original array by
3292  * substituting an empty (zero-dimensional) array; insertion of the new
3293  * element will result in a singleton array value. It does not matter
3294  * whether the new element is NULL.
3295  */
3296  if (*op->resnull)
3297  {
3299  *op->resnull = false;
3300  }
3301 
3302  if (sbsrefstate->numlower == 0)
3303  {
3304  /* Scalar case */
3305  *op->resvalue = array_set_element(*op->resvalue,
3306  sbsrefstate->numupper,
3307  sbsrefstate->upperindex,
3308  sbsrefstate->replacevalue,
3309  sbsrefstate->replacenull,
3310  sbsrefstate->refattrlength,
3311  sbsrefstate->refelemlength,
3312  sbsrefstate->refelembyval,
3313  sbsrefstate->refelemalign);
3314  }
3315  else
3316  {
3317  /* Slice case */
3318  *op->resvalue = array_set_slice(*op->resvalue,
3319  sbsrefstate->numupper,
3320  sbsrefstate->upperindex,
3321  sbsrefstate->lowerindex,
3322  sbsrefstate->upperprovided,
3323  sbsrefstate->lowerprovided,
3324  sbsrefstate->replacevalue,
3325  sbsrefstate->replacenull,
3326  sbsrefstate->refattrlength,
3327  sbsrefstate->refelemlength,
3328  sbsrefstate->refelembyval,
3329  sbsrefstate->refelemalign);
3330  }
3331 }
3332 
3333 /*
3334  * Evaluate a rowtype coercion operation.
3335  * This may require rearranging field positions.
3336  *
3337  * Source record is in step's result variable.
3338  */
3339 void
3341 {
3343  HeapTuple result;
3344  Datum tupDatum;
3345  HeapTupleHeader tuple;
3346  HeapTupleData tmptup;
3347  TupleDesc indesc,
3348  outdesc;
3349 
3350  /* NULL in -> NULL out */
3351  if (*op->resnull)
3352  return;
3353 
3354  tupDatum = *op->resvalue;
3355  tuple = DatumGetHeapTupleHeader(tupDatum);
3356 
3357  /* Lookup tupdescs if first time through or after rescan */
3358  if (op->d.convert_rowtype.indesc == NULL)
3359  {
3360  get_cached_rowtype(exprType((Node *) convert->arg), -1,
3361  &op->d.convert_rowtype.indesc,
3362  econtext);
3363  op->d.convert_rowtype.initialized = false;
3364  }
3365  if (op->d.convert_rowtype.outdesc == NULL)
3366  {
3367  get_cached_rowtype(convert->resulttype, -1,
3368  &op->d.convert_rowtype.outdesc,
3369  econtext);
3370  op->d.convert_rowtype.initialized = false;
3371  }
3372 
3373  indesc = op->d.convert_rowtype.indesc;
3374  outdesc = op->d.convert_rowtype.outdesc;
3375 
3376  /*
3377  * We used to be able to assert that incoming tuples are marked with
3378  * exactly the rowtype of indesc. However, now that ExecEvalWholeRowVar
3379  * might change the tuples' marking to plain RECORD due to inserting
3380  * aliases, we can only make this weak test:
3381  */
3382  Assert(HeapTupleHeaderGetTypeId(tuple) == indesc->tdtypeid ||
3383  HeapTupleHeaderGetTypeId(tuple) == RECORDOID);
3384 
3385  /* if first time through, initialize conversion map */
3386  if (!op->d.convert_rowtype.initialized)
3387  {
3388  MemoryContext old_cxt;
3389 
3390  /* allocate map in long-lived memory context */
3391  old_cxt = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
3392 
3393  /* prepare map from old to new attribute numbers */
3394  op->d.convert_rowtype.map = convert_tuples_by_name(indesc, outdesc);
3395  op->d.convert_rowtype.initialized = true;
3396 
3397  MemoryContextSwitchTo(old_cxt);
3398  }
3399 
3400  /* Following steps need a HeapTuple not a bare HeapTupleHeader */
3401  tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
3402  tmptup.t_data = tuple;
3403 
3404  if (op->d.convert_rowtype.map != NULL)
3405  {
3406  /* Full conversion with attribute rearrangement needed */
3407  result = execute_attr_map_tuple(&tmptup, op->d.convert_rowtype.map);
3408  /* Result already has appropriate composite-datum header fields */
3409  *op->resvalue = HeapTupleGetDatum(result);
3410  }
3411  else
3412  {
3413  /*
3414  * The tuple is physically compatible as-is, but we need to insert the
3415  * destination rowtype OID in its composite-datum header field, so we
3416  * have to copy it anyway. heap_copy_tuple_as_datum() is convenient
3417  * for this since it will both make the physical copy and insert the
3418  * correct composite header fields. Note that we aren't expecting to
3419  * have to flatten any toasted fields: the input was a composite
3420  * datum, so it shouldn't contain any. So heap_copy_tuple_as_datum()
3421  * is overkill here, but its check for external fields is cheap.
3422  */
3423  *op->resvalue = heap_copy_tuple_as_datum(&tmptup, outdesc);
3424  }
3425 }
3426 
3427 /*
3428  * Evaluate "scalar op ANY/ALL (array)".
3429  *
3430  * Source array is in our result area, scalar arg is already evaluated into
3431  * fcinfo->args[0].
3432  *
3433  * The operator always yields boolean, and we combine the results across all
3434  * array elements using OR and AND (for ANY and ALL respectively). Of course
3435  * we short-circuit as soon as the result is known.
3436  */
3437 void
3439 {
3440  FunctionCallInfo fcinfo = op->d.scalararrayop.fcinfo_data;
3441  bool useOr = op->d.scalararrayop.useOr;
3442  bool strictfunc = op->d.scalararrayop.finfo->fn_strict;
3443  ArrayType *arr;
3444  int nitems;
3445  Datum result;
3446  bool resultnull;
3447  int16 typlen;
3448  bool typbyval;
3449  char typalign;
3450  char *s;
3451  bits8 *bitmap;
3452  int bitmask;
3453 
3454  /*
3455  * If the array is NULL then we return NULL --- it's not very meaningful
3456  * to do anything else, even if the operator isn't strict.
3457  */
3458  if (*op->resnull)
3459  return;
3460 
3461  /* Else okay to fetch and detoast the array */
3462  arr = DatumGetArrayTypeP(*op->resvalue);
3463 
3464  /*
3465  * If the array is empty, we return either FALSE or TRUE per the useOr
3466  * flag. This is correct even if the scalar is NULL; since we would
3467  * evaluate the operator zero times, it matters not whether it would want
3468  * to return NULL.
3469  */
3470  nitems = ArrayGetNItems(ARR_NDIM(arr), ARR_DIMS(arr));
3471  if (nitems <= 0)
3472  {
3473  *op->resvalue = BoolGetDatum(!useOr);
3474  *op->resnull = false;
3475  return;
3476  }
3477 
3478  /*
3479  * If the scalar is NULL, and the function is strict, return NULL; no
3480  * point in iterating the loop.
3481  */
3482  if (fcinfo->args[0].isnull && strictfunc)
3483  {
3484  *op->resnull = true;
3485  return;
3486  }
3487 
3488  /*
3489  * We arrange to look up info about the element type only once per series
3490  * of calls, assuming the element type doesn't change underneath us.
3491  */
3492  if (op->d.scalararrayop.element_type != ARR_ELEMTYPE(arr))
3493  {
3495  &op->d.scalararrayop.typlen,
3496  &op->d.scalararrayop.typbyval,
3497  &op->d.scalararrayop.typalign);
3498  op->d.scalararrayop.element_type = ARR_ELEMTYPE(arr);
3499  }
3500 
3501  typlen = op->d.scalararrayop.typlen;
3502  typbyval = op->d.scalararrayop.typbyval;
3503  typalign = op->d.scalararrayop.typalign;
3504 
3505  /* Initialize result appropriately depending on useOr */
3506  result = BoolGetDatum(!useOr);
3507  resultnull = false;
3508 
3509  /* Loop over the array elements */
3510  s = (char *) ARR_DATA_PTR(arr);
3511  bitmap = ARR_NULLBITMAP(arr);
3512  bitmask = 1;
3513 
3514  for (int i = 0; i < nitems; i++)
3515  {
3516  Datum elt;
3517  Datum thisresult;
3518 
3519  /* Get array element, checking for NULL */
3520  if (bitmap && (*bitmap & bitmask) == 0)
3521  {
3522  fcinfo->args[1].value = (Datum) 0;
3523  fcinfo->args[1].isnull = true;
3524  }
3525  else
3526  {
3527  elt = fetch_att(s, typbyval, typlen);
3528  s = att_addlength_pointer(s, typlen, s);
3529  s = (char *) att_align_nominal(s, typalign);
3530  fcinfo->args[1].value = elt;
3531  fcinfo->args[1].isnull = false;
3532  }
3533 
3534  /* Call comparison function */
3535  if (fcinfo->args[1].isnull && strictfunc)
3536  {
3537  fcinfo->isnull = true;
3538  thisresult = (Datum) 0;
3539  }
3540  else
3541  {
3542  fcinfo->isnull = false;
3543  thisresult = op->d.scalararrayop.fn_addr(fcinfo);
3544  }
3545 
3546  /* Combine results per OR or AND semantics */
3547  if (fcinfo->isnull)
3548  resultnull = true;
3549  else if (useOr)
3550  {
3551  if (DatumGetBool(thisresult))
3552  {
3553  result = BoolGetDatum(true);
3554  resultnull = false;
3555  break; /* needn't look at any more elements */
3556  }
3557  }
3558  else
3559  {
3560  if (!DatumGetBool(thisresult))
3561  {
3562  result = BoolGetDatum(false);
3563  resultnull = false;
3564  break; /* needn't look at any more elements */
3565  }
3566  }
3567 
3568  /* advance bitmap pointer if any */
3569  if (bitmap)
3570  {
3571  bitmask <<= 1;
3572  if (bitmask == 0x100)
3573  {
3574  bitmap++;
3575  bitmask = 1;
3576  }
3577  }
3578  }
3579 
3580  *op->resvalue = result;
3581  *op->resnull = resultnull;
3582 }
3583 
3584 /*
3585  * Evaluate a NOT NULL domain constraint.
3586  */
3587 void
3589 {
3590  if (*op->resnull)
3591  ereport(ERROR,
3592  (errcode(ERRCODE_NOT_NULL_VIOLATION),
3593  errmsg("domain %s does not allow null values",
3594  format_type_be(op->d.domaincheck.resulttype)),
3595  errdatatype(op->d.domaincheck.resulttype)));
3596 }
3597 
3598 /*
3599  * Evaluate a CHECK domain constraint.
3600  */
3601 void
3603 {
3604  if (!*op->d.domaincheck.checknull &&
3605  !DatumGetBool(*op->d.domaincheck.checkvalue))
3606  ereport(ERROR,
3607  (errcode(ERRCODE_CHECK_VIOLATION),
3608  errmsg("value for domain %s violates check constraint \"%s\"",
3609  format_type_be(op->d.domaincheck.resulttype),
3610  op->d.domaincheck.constraintname),
3611  errdomainconstraint(op->d.domaincheck.resulttype,
3612  op->d.domaincheck.constraintname)));
3613 }
3614 
3615 /*
3616  * Evaluate the various forms of XmlExpr.
3617  *
3618  * Arguments have been evaluated into named_argvalue/named_argnull
3619  * and/or argvalue/argnull arrays.
3620  */
3621 void
3623 {
3624  XmlExpr *xexpr = op->d.xmlexpr.xexpr;
3625  Datum value;
3626 
3627  *op->resnull = true; /* until we get a result */
3628  *op->resvalue = (Datum) 0;
3629 
3630  switch (xexpr->op)
3631  {
3632  case IS_XMLCONCAT:
3633  {
3634  Datum *argvalue = op->d.xmlexpr.argvalue;
3635  bool *argnull = op->d.xmlexpr.argnull;
3636  List *values = NIL;
3637 
3638  for (int i = 0; i < list_length(xexpr->args); i++)
3639  {
3640  if (!argnull[i])
3641  values = lappend(values, DatumGetPointer(argvalue[i]));
3642  }
3643 
3644  if (values != NIL)
3645  {
3646  *op->resvalue = PointerGetDatum(xmlconcat(values));
3647  *op->resnull = false;
3648  }
3649  }
3650  break;
3651 
3652  case IS_XMLFOREST:
3653  {
3654  Datum *argvalue = op->d.xmlexpr.named_argvalue;
3655  bool *argnull = op->d.xmlexpr.named_argnull;
3657  ListCell *lc;
3658  ListCell *lc2;
3659  int i;
3660 
3661  initStringInfo(&buf);
3662 
3663  i = 0;
3664  forboth(lc, xexpr->named_args, lc2, xexpr->arg_names)
3665  {
3666  Expr *e = (Expr *) lfirst(lc);
3667  char *argname = strVal(lfirst(lc2));
3668 
3669  if (!argnull[i])
3670  {
3671  value = argvalue[i];
3672  appendStringInfo(&buf, "<%s>%s</%s>",
3673  argname,
3675  exprType((Node *) e), true),
3676  argname);
3677  *op->resnull = false;
3678  }
3679  i++;
3680  }
3681 
3682  if (!*op->resnull)
3683  {
3684  text *result;
3685 
3686  result = cstring_to_text_with_len(buf.data, buf.len);
3687  *op->resvalue = PointerGetDatum(result);
3688  }
3689 
3690  pfree(buf.data);
3691  }
3692  break;
3693 
3694  case IS_XMLELEMENT:
3695  *op->resvalue = PointerGetDatum(xmlelement(xexpr,
3696  op->d.xmlexpr.named_argvalue,
3697  op->d.xmlexpr.named_argnull,
3698  op->d.xmlexpr.argvalue,
3699  op->d.xmlexpr.argnull));
3700  *op->resnull = false;
3701  break;
3702 
3703  case IS_XMLPARSE:
3704  {
3705  Datum *argvalue = op->d.xmlexpr.argvalue;
3706  bool *argnull = op->d.xmlexpr.argnull;
3707  text *data;
3708  bool preserve_whitespace;
3709 
3710  /* arguments are known to be text, bool */
3711  Assert(list_length(xexpr->args) == 2);
3712 
3713  if (argnull[0])
3714  return;
3715  value = argvalue[0];
3716  data = DatumGetTextPP(value);
3717 
3718  if (argnull[1]) /* probably can't happen */
3719  return;
3720  value = argvalue[1];
3721  preserve_whitespace = DatumGetBool(value);
3722 
3723  *op->resvalue = PointerGetDatum(xmlparse(data,
3724  xexpr->xmloption,
3725  preserve_whitespace));
3726  *op->resnull = false;
3727  }
3728  break;
3729 
3730  case IS_XMLPI:
3731  {
3732  text *arg;
3733  bool isnull;
3734 
3735  /* optional argument is known to be text */
3736  Assert(list_length(xexpr->args) <= 1);
3737 
3738  if (xexpr->args)
3739  {
3740  isnull = op->d.xmlexpr.argnull[0];
3741  if (isnull)
3742  arg = NULL;
3743  else
3744  arg = DatumGetTextPP(op->d.xmlexpr.argvalue[0]);
3745  }
3746  else
3747  {
3748  arg = NULL;
3749  isnull = false;
3750  }
3751 
3752  *op->resvalue = PointerGetDatum(xmlpi(xexpr->name,
3753  arg,
3754  isnull,
3755  op->resnull));
3756  }
3757  break;
3758 
3759  case IS_XMLROOT:
3760  {
3761  Datum *argvalue = op->d.xmlexpr.argvalue;
3762  bool *argnull = op->d.xmlexpr.argnull;
3763  xmltype *data;
3764  text *version;
3765  int standalone;
3766 
3767  /* arguments are known to be xml, text, int */
3768  Assert(list_length(xexpr->args) == 3);
3769 
3770  if (argnull[0])
3771  return;
3772  data = DatumGetXmlP(argvalue[0]);
3773 
3774  if (argnull[1])
3775  version = NULL;
3776  else
3777  version = DatumGetTextPP(argvalue[1]);
3778 
3779  Assert(!argnull[2]); /* always present */
3780  standalone = DatumGetInt32(argvalue[2]);
3781 
3782  *op->resvalue = PointerGetDatum(xmlroot(data,
3783  version,
3784  standalone));
3785  *op->resnull = false;
3786  }
3787  break;
3788 
3789  case IS_XMLSERIALIZE:
3790  {
3791  Datum *argvalue = op->d.xmlexpr.argvalue;
3792  bool *argnull = op->d.xmlexpr.argnull;
3793 
3794  /* argument type is known to be xml */
3795  Assert(list_length(xexpr->args) == 1);
3796 
3797  if (argnull[0])
3798  return;
3799  value = argvalue[0];
3800 
3802  xexpr->xmloption));
3803  *op->resnull = false;
3804  }
3805  break;
3806 
3807  case IS_DOCUMENT:
3808  {
3809  Datum *argvalue = op->d.xmlexpr.argvalue;
3810  bool *argnull = op->d.xmlexpr.argnull;
3811 
3812  /* optional argument is known to be xml */
3813  Assert(list_length(xexpr->args) == 1);
3814 
3815  if (argnull[0])
3816  return;
3817  value = argvalue[0];
3818 
3819  *op->resvalue =
3821  *op->resnull = false;
3822  }
3823  break;
3824 
3825  default:
3826  elog(ERROR, "unrecognized XML operation");
3827  break;
3828  }
3829 }
3830 
3831 /*
3832  * ExecEvalGroupingFunc
3833  *
3834  * Computes a bitmask with a bit for each (unevaluated) argument expression
3835  * (rightmost arg is least significant bit).
3836  *
3837  * A bit is set if the corresponding expression is NOT part of the set of
3838  * grouping expressions in the current grouping set.
3839  */
3840 void
3842 {
3843  AggState *aggstate = castNode(AggState, state->parent);
3844  int result = 0;
3845  Bitmapset *grouped_cols = aggstate->grouped_cols;
3846  ListCell *lc;
3847 
3848  foreach(lc, op->d.grouping_func.clauses)
3849  {
3850  int attnum = lfirst_int(lc);
3851 
3852  result <<= 1;
3853 
3854  if (!bms_is_member(attnum, grouped_cols))
3855  result |= 1;
3856  }
3857 
3858  *op->resvalue = Int32GetDatum(result);
3859  *op->resnull = false;
3860 }
3861 
3862 /*
3863  * Hand off evaluation of a subplan to nodeSubplan.c
3864  */
3865 void
3867 {
3868  SubPlanState *sstate = op->d.subplan.sstate;
3869 
3870  /* could potentially be nested, so make sure there's enough stack */
3872 
3873  *op->resvalue = ExecSubPlan(sstate, econtext, op->resnull);
3874 }
3875 
3876 /*
3877  * Hand off evaluation of an alternative subplan to nodeSubplan.c
3878  */
3879 void
3881 {
3882  AlternativeSubPlanState *asstate = op->d.alternative_subplan.asstate;
3883 
3884  /* could potentially be nested, so make sure there's enough stack */
3886 
3887  *op->resvalue = ExecAlternativeSubPlan(asstate, econtext, op->resnull);
3888 }
3889 
3890 /*
3891  * Evaluate a wholerow Var expression.
3892  *
3893  * Returns a Datum whose value is the value of a whole-row range variable
3894  * with respect to given expression context.
3895  */
3896 void
3898 {
3899  Var *variable = op->d.wholerow.var;
3900  TupleTableSlot *slot;
3901  TupleDesc output_tupdesc;
3902  MemoryContext oldcontext;
3903  HeapTupleHeader dtuple;
3904  HeapTuple tuple;
3905 
3906  /* This was checked by ExecInitExpr */
3907  Assert(variable->varattno == InvalidAttrNumber);
3908 
3909  /* Get the input slot we want */
3910  switch (variable->varno)
3911  {
3912  case INNER_VAR:
3913  /* get the tuple from the inner node */
3914  slot = econtext->ecxt_innertuple;
3915  break;
3916 
3917  case OUTER_VAR:
3918  /* get the tuple from the outer node */
3919  slot = econtext->ecxt_outertuple;
3920  break;
3921 
3922  /* INDEX_VAR is handled by default case */
3923 
3924  default:
3925  /* get the tuple from the relation being scanned */
3926  slot = econtext->ecxt_scantuple;
3927  break;
3928  }
3929 
3930  /* Apply the junkfilter if any */
3931  if (op->d.wholerow.junkFilter != NULL)
3932  slot = ExecFilterJunk(op->d.wholerow.junkFilter, slot);
3933 
3934  /*
3935  * If first time through, obtain tuple descriptor and check compatibility.
3936  *
3937  * XXX: It'd be great if this could be moved to the expression
3938  * initialization phase, but due to using slots that's currently not
3939  * feasible.
3940  */
3941  if (op->d.wholerow.first)
3942  {
3943  /* optimistically assume we don't need slow path */
3944  op->d.wholerow.slow = false;
3945 
3946  /*
3947  * If the Var identifies a named composite type, we must check that
3948  * the actual tuple type is compatible with it.
3949  */
3950  if (variable->vartype != RECORDOID)
3951  {
3952  TupleDesc var_tupdesc;
3953  TupleDesc slot_tupdesc;
3954 
3955  /*
3956  * We really only care about numbers of attributes and data types.
3957  * Also, we can ignore type mismatch on columns that are dropped
3958  * in the destination type, so long as (1) the physical storage
3959  * matches or (2) the actual column value is NULL. Case (1) is
3960  * helpful in some cases involving out-of-date cached plans, while
3961  * case (2) is expected behavior in situations such as an INSERT
3962  * into a table with dropped columns (the planner typically
3963  * generates an INT4 NULL regardless of the dropped column type).
3964  * If we find a dropped column and cannot verify that case (1)
3965  * holds, we have to use the slow path to check (2) for each row.
3966  *
3967  * If vartype is a domain over composite, just look through that
3968  * to the base composite type.
3969  */
3970  var_tupdesc = lookup_rowtype_tupdesc_domain(variable->vartype,
3971  -1, false);
3972 
3973  slot_tupdesc = slot->tts_tupleDescriptor;
3974 
3975  if (var_tupdesc->natts != slot_tupdesc->natts)
3976  ereport(ERROR,
3977  (errcode(ERRCODE_DATATYPE_MISMATCH),
3978  errmsg("table row type and query-specified row type do not match"),
3979  errdetail_plural("Table row contains %d attribute, but query expects %d.",
3980  "Table row contains %d attributes, but query expects %d.",
3981  slot_tupdesc->natts,
3982  slot_tupdesc->natts,
3983  var_tupdesc->natts)));
3984 
3985  for (int i = 0; i < var_tupdesc->natts; i++)
3986  {
3987  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
3988  Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
3989 
3990  if (vattr->atttypid == sattr->atttypid)
3991  continue; /* no worries */
3992  if (!vattr->attisdropped)
3993  ereport(ERROR,
3994  (errcode(ERRCODE_DATATYPE_MISMATCH),
3995  errmsg("table row type and query-specified row type do not match"),
3996  errdetail("Table has type %s at ordinal position %d, but query expects %s.",
3997  format_type_be(sattr->atttypid),
3998  i + 1,
3999  format_type_be(vattr->atttypid))));
4000 
4001  if (vattr->attlen != sattr->attlen ||
4002  vattr->attalign != sattr->attalign)
4003  op->d.wholerow.slow = true; /* need to check for nulls */
4004  }
4005 
4006  /*
4007  * Use the variable's declared rowtype as the descriptor for the
4008  * output values, modulo possibly assigning new column names
4009  * below. In particular, we *must* absorb any attisdropped
4010  * markings.
4011  */
4012  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4013  output_tupdesc = CreateTupleDescCopy(var_tupdesc);
4014  MemoryContextSwitchTo(oldcontext);
4015 
4016  ReleaseTupleDesc(var_tupdesc);
4017  }
4018  else
4019  {
4020  /*
4021  * In the RECORD case, we use the input slot's rowtype as the
4022  * descriptor for the output values, modulo possibly assigning new
4023  * column names below.
4024  */
4025  oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
4026  output_tupdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
4027  MemoryContextSwitchTo(oldcontext);
4028  }
4029 
4030  /*
4031  * Construct a tuple descriptor for the composite values we'll
4032  * produce, and make sure its record type is "blessed". The main
4033  * reason to do this is to be sure that operations such as
4034  * row_to_json() will see the desired column names when they look up
4035  * the descriptor from the type information embedded in the composite
4036  * values.
4037  *
4038  * We already got the correct physical datatype info above, but now we
4039  * should try to find the source RTE and adopt its column aliases, in
4040  * case they are different from the original rowtype's names. For
4041  * example, in "SELECT foo(t) FROM tab t(x,y)", the first two columns
4042  * in the composite output should be named "x" and "y" regardless of
4043  * tab's column names.
4044  *
4045  * If we can't locate the RTE, assume the column names we've got are
4046  * OK. (As of this writing, the only cases where we can't locate the
4047  * RTE are in execution of trigger WHEN clauses, and then the Var will
4048  * have the trigger's relation's rowtype, so its names are fine.)
4049  * Also, if the creator of the RTE didn't bother to fill in an eref
4050  * field, assume our column names are OK. (This happens in COPY, and
4051  * perhaps other places.)
4052  */
4053  if (econtext->ecxt_estate &&
4054  variable->varno <= econtext->ecxt_estate->es_range_table_size)
4055  {
4056  RangeTblEntry *rte = exec_rt_fetch(variable->varno,
4057  econtext->ecxt_estate);
4058 
4059  if (rte->eref)
4060  ExecTypeSetColNames(output_tupdesc, rte->eref->colnames);
4061  }
4062 
4063  /* Bless the tupdesc if needed, and save it in the execution state */
4064  op->d.wholerow.tupdesc = BlessTupleDesc(output_tupdesc);
4065 
4066  op->d.wholerow.first = false;
4067  }
4068 
4069  /*
4070  * Make sure all columns of the slot are accessible in the slot's
4071  * Datum/isnull arrays.
4072  */
4073  slot_getallattrs(slot);
4074 
4075  if (op->d.wholerow.slow)
4076  {
4077  /* Check to see if any dropped attributes are non-null */
4078  TupleDesc tupleDesc = slot->tts_tupleDescriptor;
4079  TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
4080 
4081  Assert(var_tupdesc->natts == tupleDesc->natts);
4082 
4083  for (int i = 0; i < var_tupdesc->natts; i++)
4084  {
4085  Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
4086  Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
4087 
4088  if (!vattr->attisdropped)
4089  continue; /* already checked non-dropped cols */
4090  if (slot->tts_isnull[i])
4091  continue; /* null is always okay */
4092  if (vattr->attlen != sattr->attlen ||
4093  vattr->attalign != sattr->attalign)
4094  ereport(ERROR,
4095  (errcode(ERRCODE_DATATYPE_MISMATCH),
4096  errmsg("table row type and query-specified row type do not match"),
4097  errdetail("Physical storage mismatch on dropped attribute at ordinal position %d.",
4098  i + 1)));
4099  }
4100  }
4101 
4102  /*
4103  * Build a composite datum, making sure any toasted fields get detoasted.
4104  *
4105  * (Note: it is critical that we not change the slot's state here.)
4106  */
4108  slot->tts_values,
4109  slot->tts_isnull);
4110  dtuple = tuple->t_data;
4111 
4112  /*
4113  * Label the datum with the composite type info we identified before.
4114  *
4115  * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to
4116  * the tuple build step; but that seems a tad risky so let's not.)
4117  */
4118  HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid);
4119  HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod);
4120 
4121  *op->resvalue = PointerGetDatum(dtuple);
4122  *op->resnull = false;
4123 }
4124 
4125 void
4127  TupleTableSlot *slot)
4128 {
4129  Datum d;
4130 
4131  /* slot_getsysattr has sufficient defenses against bad attnums */
4132  d = slot_getsysattr(slot,
4133  op->d.var.attnum,
4134  op->resnull);
4135  *op->resvalue = d;
4136  /* this ought to be unreachable, but it's cheap enough to check */
4137  if (unlikely(*op->resnull))
4138  elog(ERROR, "failed to fetch attribute from slot");
4139 }
4140 
4141 /*
4142  * Transition value has not been initialized. This is the first non-NULL input
4143  * value for a group. We use it as the initial value for transValue.
4144  */
4145 void
4147  ExprContext *aggcontext)
4148 {
4149  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4150  MemoryContext oldContext;
4151 
4152  /*
4153  * We must copy the datum into aggcontext if it is pass-by-ref. We do not
4154  * need to pfree the old transValue, since it's NULL. (We already checked
4155  * that the agg's input type is binary-compatible with its transtype, so
4156  * straight copy here is OK.)
4157  */
4158  oldContext = MemoryContextSwitchTo(aggcontext->ecxt_per_tuple_memory);
4159  pergroup->transValue = datumCopy(fcinfo->args[1].value,
4160  pertrans->transtypeByVal,
4161  pertrans->transtypeLen);
4162  pergroup->transValueIsNull = false;
4163  pergroup->noTransValue = false;
4164  MemoryContextSwitchTo(oldContext);
4165 }
4166 
4167 /*
4168  * Ensure that the current transition value is a child of the aggcontext,
4169  * rather than the per-tuple context.
4170  *
4171  * NB: This can change the current memory context.
4172  */
4173 Datum
4175  Datum newValue, bool newValueIsNull,
4176  Datum oldValue, bool oldValueIsNull)
4177 {
4178  Assert(newValue != oldValue);
4179 
4180  if (!newValueIsNull)
4181  {
4183  if (DatumIsReadWriteExpandedObject(newValue,
4184  false,
4185  pertrans->transtypeLen) &&
4186  MemoryContextGetParent(DatumGetEOHP(newValue)->eoh_context) == CurrentMemoryContext)
4187  /* do nothing */ ;
4188  else
4189  newValue = datumCopy(newValue,
4190  pertrans->transtypeByVal,
4191  pertrans->transtypeLen);
4192  }
4193  else
4194  {
4195  /*
4196  * Ensure that AggStatePerGroup->transValue ends up being 0, so
4197  * callers can safely compare newValue/oldValue without having to
4198  * check their respective nullness.
4199  */
4200  newValue = (Datum) 0;
4201  }
4202 
4203  if (!oldValueIsNull)
4204  {
4205  if (DatumIsReadWriteExpandedObject(oldValue,
4206  false,
4207  pertrans->transtypeLen))
4208  DeleteExpandedObject(oldValue);
4209  else
4210  pfree(DatumGetPointer(oldValue));
4211  }
4212 
4213  return newValue;
4214 }
4215 
4216 /*
4217  * Invoke ordered transition function, with a datum argument.
4218  */
4219 void
4221  ExprContext *econtext)
4222 {
4223  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4224  int setno = op->d.agg_trans.setno;
4225 
4226  tuplesort_putdatum(pertrans->sortstates[setno],
4227  *op->resvalue, *op->resnull);
4228 }
4229 
4230 /*
4231  * Invoke ordered transition function, with a tuple argument.
4232  */
4233 void
4235  ExprContext *econtext)
4236 {
4237  AggStatePerTrans pertrans = op->d.agg_trans.pertrans;
4238  int setno = op->d.agg_trans.setno;
4239 
4240  ExecClearTuple(pertrans->sortslot);
4241  pertrans->sortslot->tts_nvalid = pertrans->numInputs;
4242  ExecStoreVirtualTuple(pertrans->sortslot);
4243  tuplesort_puttupleslot(pertrans->sortstates[setno], pertrans->sortslot);
4244 }
4245 
4246 /* implementation of transition function invocation for byval types */
4247 static pg_attribute_always_inline void
4249  AggStatePerGroup pergroup,
4250  ExprContext *aggcontext, int setno)
4251 {
4252  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4253  MemoryContext oldContext;
4254  Datum newVal;
4255 
4256  /* cf. select_current_set() */
4257  aggstate->curaggcontext = aggcontext;
4258  aggstate->current_set = setno;
4259 
4260  /* set up aggstate->curpertrans for AggGetAggref() */
4261  aggstate->curpertrans = pertrans;
4262 
4263  /* invoke transition function in per-tuple context */
4264  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4265 
4266  fcinfo->args[0].value = pergroup->transValue;
4267  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4268  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4269 
4270  newVal = FunctionCallInvoke(fcinfo);
4271 
4272  pergroup->transValue = newVal;
4273  pergroup->transValueIsNull = fcinfo->isnull;
4274 
4275  MemoryContextSwitchTo(oldContext);
4276 }
4277 
4278 /* implementation of transition function invocation for byref types */
4279 static pg_attribute_always_inline void
4281  AggStatePerGroup pergroup,
4282  ExprContext *aggcontext, int setno)
4283 {
4284  FunctionCallInfo fcinfo = pertrans->transfn_fcinfo;
4285  MemoryContext oldContext;
4286  Datum newVal;
4287 
4288  /* cf. select_current_set() */
4289  aggstate->curaggcontext = aggcontext;
4290  aggstate->current_set = setno;
4291 
4292  /* set up aggstate->curpertrans for AggGetAggref() */
4293  aggstate->curpertrans = pertrans;
4294 
4295  /* invoke transition function in per-tuple context */
4296  oldContext = MemoryContextSwitchTo(aggstate->tmpcontext->ecxt_per_tuple_memory);
4297 
4298  fcinfo->args[0].value = pergroup->transValue;
4299  fcinfo->args[0].isnull = pergroup->transValueIsNull;
4300  fcinfo->isnull = false; /* just in case transfn doesn't set it */
4301 
4302  newVal = FunctionCallInvoke(fcinfo);
4303 
4304  /*
4305  * For pass-by-ref datatype, must copy the new value into
4306  * aggcontext and free the prior transValue. But if transfn
4307  * returned a pointer to its first input, we don't need to do
4308  * anything. Also, if transfn returned a pointer to a R/W
4309  * expanded object that is already a child of the aggcontext,
4310  * assume we can adopt that value without copying it.
4311  *
4312  * It's safe to compare newVal with pergroup->transValue without
4313  * regard for either being NULL, because ExecAggTransReparent()
4314  * takes care to set transValue to 0 when NULL. Otherwise we could
4315  * end up accidentally not reparenting, when the transValue has
4316  * the same numerical value as newValue, despite being NULL. This
4317  * is a somewhat hot path, making it undesirable to instead solve
4318  * this with another branch for the common case of the transition
4319  * function returning its (modified) input argument.
4320  */
4321  if (DatumGetPointer(newVal) != DatumGetPointer(pergroup->transValue))
4322  newVal = ExecAggTransReparent(aggstate, pertrans,
4323  newVal, fcinfo->isnull,
4324  pergroup->transValue,
4325  pergroup->transValueIsNull);
4326 
4327  pergroup->transValue = newVal;
4328  pergroup->transValueIsNull = fcinfo->isnull;
4329 
4330  MemoryContextSwitchTo(oldContext);
4331 }
#define TTS_FIXED(slot)
Definition: tuptable.h:109
signed short int16
Definition: c.h:354
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:2028
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:419
#define ARR_OVERHEAD_NONULLS(ndims)
Definition: array.h:298
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Definition: tuplesort.c:1556
Datum current_schema(PG_FUNCTION_ARGS)
Definition: name.c:319
#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:1182
#define ARR_SIZE(a)
Definition: array.h:277
#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:253
List * colnames
Definition: primnodes.h:43
#define DatumGetInt32(X)
Definition: postgres.h:472
MemoryContext MemoryContextGetParent(MemoryContext context)
Definition: mcxt.c:439
#define MAXDIM
Definition: c.h:535
static Datum ExecJustInnerVarVirt(ExprState *state, ExprContext *econtext, bool *isnull)
struct ExprEvalStep::@51::@80 domaincheck
#define castNode(_type_, nodeptr)
Definition: nodes.h:595
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:2110
#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
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:4687
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:286
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:254
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
Datum ExecAlternativeSubPlan(AlternativeSubPlanState *node, ExprContext *econtext, bool *isNull)
Definition: nodeSubplan.c:1376
xmltype * xmlconcat(List *args)
Definition: xml.c:512
static void slot_getsomeattrs(TupleTableSlot *slot, int attnum)
Definition: tuptable.h:341
Definition: nodes.h:526
#define strVal(v)
Definition: value.h:54
const TupleTableSlotOps *const tts_ops
Definition: tuptable.h:122
TimestampTz GetSQLCurrentTimestamp(int32 typmod)
Definition: timestamp.c:1601
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:327
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:2199
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:668
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3410
DateADT GetSQLCurrentDate(void)
Definition: date.c:299
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:1184
Definition: primnodes.h:181
struct ExprEvalStep::@51::@58 func
#define DatumGetXmlP(X)
Definition: xml.h:50
int current_set
Definition: execnodes.h:2068
#define OidIsValid(objectId)
Definition: c.h:644
struct ExprEvalStep::@51::@82 scalararrayop
void ExecEvalFieldStoreForm(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
#define DatumGetHeapTupleHeader(X)
Definition: fmgr.h:289
FunctionCallInfo transfn_fcinfo
Definition: nodeAgg.h:161
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:1143
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
Definition: typcache.c:1766
ExprContext * tmpcontext
Definition: execnodes.h:2058
signed int int32
Definition: c.h:355
Datum current_database(PG_FUNCTION_ARGS)
Definition: misc.c:169
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:852
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:2759
static void CheckVarSlotCompatibility(TupleTableSlot *slot, int attnum, Oid vartype)
ParamFetchHook paramFetch
Definition: params.h:112
void pfree(void *pointer)
Definition: mcxt.c:1056
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
MinMaxOp
Definition: primnodes.h:1093
static void convert(const int32 val, char *const buf)
Definition: zic.c:1959
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:1669
Oid elemtype
Definition: array.h:85
#define lfirst_int(lc)
Definition: pg_list.h:191
void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
Definition: nodeSubplan.c:1050
bool isnull
Definition: params.h:150
Oid vartype
Definition: primnodes.h:188
struct ExprEvalStep::@51::@92 agg_trans
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:321
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:153
ExprStateEvalFunc evalfunc
Definition: execnodes.h:91
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:167
static void ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ExprContext *econtext, bool checkisnull)
static char * buf
Definition: pg_test_fsync.c:67
Datum current_user(PG_FUNCTION_ARGS)
Definition: name.c:303
text * cstring_to_text_with_len(const char *s, int len)
Definition: varlena.c:184
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:661
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:542
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:2069
struct ExprEvalStep::@51::@90 agg_strict_input_check
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:347
union ExprEvalStep::@51 d
List * lappend(List *list, void *datum)
Definition: list.c:322
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:1181
Datum session_user(PG_FUNCTION_ARGS)
Definition: name.c:309
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
ExprContext * curaggcontext
Definition: execnodes.h:2060
bool * ecxt_aggnulls
Definition: execnodes.h:247
uint8 bits8
Definition: c.h:374
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:666
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:1615
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:1183
static struct @143 value
#define ereport(elevel,...)
Definition: elog.h:144
RowCompareType
Definition: primnodes.h:1056
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:1185
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:1819
#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:3131
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:738
#define lfirst(lc)
Definition: pg_list.h:190
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
Definition: execUtils.c:863
struct ExprEvalStep::@51::@64 cparam
struct ExprEvalStep::@51::@56 assign_tmp
Definition: regguts.h:298
intptr_t opcode
Definition: execExpr.h:250
static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool *isnull)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
XmlOptionType xmloption
Definition: primnodes.h:1186
int lowerindex[MAXDIM]
Definition: execExpr.h:667
#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:169
#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:511
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)
#define DatumGetPointer(X)
Definition: postgres.h:549
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1741
int upperindex[MAXDIM]
Definition: execExpr.h:662
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:167
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
struct ExprEvalStep::@51::@91 agg_plain_pergroup_nullcheck
void * palloc(Size size)
Definition: mcxt.c:949
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
struct ExprEvalStep::@51::@88 alternative_subplan
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:2063
#define unlikely(x)
Definition: c.h:206
Definition: c.h:555
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:135
Alias * eref
Definition: parsenodes.h:1114
struct ExprEvalStep::@51::@54 wholerow
#define qsort(a, b, c, d)
Definition: port.h:479
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:3326
#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
void ExecEvalAlternativeSubPlan(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
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
struct ExprEvalStep::@51::@89 agg_deserialize
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:1435
void ExecEvalSQLValueFunction(ExprState *state, ExprEvalStep *op)
AggStatePerGroup * all_pergroups
Definition: execnodes.h:2110
void ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:452
#define DatumGetArrayTypeP(X)
Definition: array.h:249