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