PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
regress.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------------
2  *
3  * regress.c
4  * Code for various C-language functions defined as part of the
5  * regression tests.
6  *
7  * This code is released under the terms of the PostgreSQL License.
8  *
9  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  * src/test/regress/regress.c
13  *
14  *-------------------------------------------------------------------------
15  */
16 
17 #include "postgres.h"
18 
19 #include <float.h>
20 #include <math.h>
21 #include <signal.h>
22 
23 #include "access/htup_details.h"
24 #include "access/transam.h"
25 #include "access/tuptoaster.h"
26 #include "access/xact.h"
27 #include "catalog/pg_type.h"
28 #include "commands/sequence.h"
29 #include "commands/trigger.h"
30 #include "executor/executor.h"
31 #include "executor/spi.h"
32 #include "miscadmin.h"
33 #include "port/atomics.h"
34 #include "utils/builtins.h"
35 #include "utils/geo_decls.h"
36 #include "utils/rel.h"
37 #include "utils/typcache.h"
38 #include "utils/memutils.h"
39 
40 
41 #define P_MAXDIG 12
42 #define LDELIM '('
43 #define RDELIM ')'
44 #define DELIM ','
45 
46 extern PATH *poly2path(POLYGON *poly);
47 extern void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
48 extern char *reverse_name(char *string);
49 extern int oldstyle_length(int n, text *t);
50 
51 #ifdef PG_MODULE_MAGIC
53 #endif
54 
55 
56 /*
57  * Distance from a point to a path
58  */
60 
61 Datum
63 {
64  Point *pt = PG_GETARG_POINT_P(0);
65  PATH *path = PG_GETARG_PATH_P(1);
66  float8 result = 0.0; /* keep compiler quiet */
67  float8 tmp;
68  int i;
69  LSEG lseg;
70 
71  switch (path->npts)
72  {
73  case 0:
75  case 1:
76  result = point_dt(pt, &path->p[0]);
77  break;
78  default:
79 
80  /*
81  * the distance from a point to a path is the smallest distance
82  * from the point to any of its constituent segments.
83  */
84  Assert(path->npts > 1);
85  for (i = 0; i < path->npts - 1; ++i)
86  {
87  regress_lseg_construct(&lseg, &path->p[i], &path->p[i + 1]);
89  PointPGetDatum(pt),
90  LsegPGetDatum(&lseg)));
91  if (i == 0 || tmp < result)
92  result = tmp;
93  }
94  break;
95  }
96  PG_RETURN_FLOAT8(result);
97 }
98 
99 /*
100  * this essentially does a cartesian product of the lsegs in the
101  * two paths, and finds the min distance between any two lsegs
102  */
104 
105 Datum
107 {
108  PATH *p1 = PG_GETARG_PATH_P(0);
109  PATH *p2 = PG_GETARG_PATH_P(1);
110  bool have_min = false;
111  float8 min = 0.0; /* initialize to keep compiler quiet */
112  float8 tmp;
113  int i,
114  j;
115  LSEG seg1,
116  seg2;
117 
118  for (i = 0; i < p1->npts - 1; i++)
119  {
120  for (j = 0; j < p2->npts - 1; j++)
121  {
122  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
123  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
124 
126  LsegPGetDatum(&seg1),
127  LsegPGetDatum(&seg2)));
128  if (!have_min || tmp < min)
129  {
130  min = tmp;
131  have_min = true;
132  }
133  }
134  }
135 
136  if (!have_min)
137  PG_RETURN_NULL();
138 
139  PG_RETURN_FLOAT8(min);
140 }
141 
142 PATH *
144 {
145  int i;
146  char *output = (char *) palloc(2 * (P_MAXDIG + 1) * poly->npts + 64);
147  char buf[2 * (P_MAXDIG) + 20];
148 
149  sprintf(output, "(1, %*d", P_MAXDIG, poly->npts);
150 
151  for (i = 0; i < poly->npts; i++)
152  {
153  snprintf(buf, sizeof(buf), ",%*g,%*g",
154  P_MAXDIG, poly->p[i].x, P_MAXDIG, poly->p[i].y);
155  strcat(output, buf);
156  }
157 
158  snprintf(buf, sizeof(buf), "%c", RDELIM);
159  strcat(output, buf);
161  CStringGetDatum(output)));
162 }
163 
164 /* return the point where two paths intersect, or NULL if no intersection. */
166 
167 Datum
169 {
170  PATH *p1 = PG_GETARG_PATH_P(0);
171  PATH *p2 = PG_GETARG_PATH_P(1);
172  int i,
173  j;
174  LSEG seg1,
175  seg2;
176  bool found; /* We've found the intersection */
177 
178  found = false; /* Haven't found it yet */
179 
180  for (i = 0; i < p1->npts - 1 && !found; i++)
181  {
182  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
183  for (j = 0; j < p2->npts - 1 && !found; j++)
184  {
185  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
187  LsegPGetDatum(&seg1),
188  LsegPGetDatum(&seg2))))
189  found = true;
190  }
191  }
192 
193  if (!found)
194  PG_RETURN_NULL();
195 
196  /*
197  * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
198  * returns NULL, but that should be impossible since we know the two
199  * segments intersect.
200  */
202  LsegPGetDatum(&seg1),
203  LsegPGetDatum(&seg2)));
204 }
205 
206 
207 /* like lseg_construct, but assume space already allocated */
208 void
210 {
211  lseg->p[0].x = pt1->x;
212  lseg->p[0].y = pt1->y;
213  lseg->p[1].x = pt2->x;
214  lseg->p[1].y = pt2->y;
215 }
216 
218 
219 Datum
221 {
223  bool isnull;
224  int32 salary;
225 
226  salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
227  if (isnull)
228  PG_RETURN_NULL();
229  PG_RETURN_BOOL(salary > 699);
230 }
231 
232 /* New type "widget"
233  * This used to be "circle", but I added circle to builtins,
234  * so needed to make sure the names do not collide. - tgl 97/04/21
235  */
236 
237 typedef struct
238 {
240  double radius;
241 } WIDGET;
242 
243 WIDGET *widget_in(char *str);
244 char *widget_out(WIDGET *widget);
245 
246 #define NARGS 3
247 
248 WIDGET *
250 {
251  char *p,
252  *coord[NARGS];
253  int i;
254  WIDGET *result;
255 
256  for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
257  {
258  if (*p == DELIM || (*p == LDELIM && i == 0))
259  coord[i++] = p + 1;
260  }
261 
262  if (i < NARGS)
263  ereport(ERROR,
264  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
265  errmsg("invalid input syntax for type widget: \"%s\"",
266  str)));
267 
268  result = (WIDGET *) palloc(sizeof(WIDGET));
269  result->center.x = atof(coord[0]);
270  result->center.y = atof(coord[1]);
271  result->radius = atof(coord[2]);
272 
273  return result;
274 }
275 
276 char *
278 {
279  return psprintf("(%g,%g,%g)",
280  widget->center.x, widget->center.y, widget->radius);
281 }
282 
284 
285 Datum
287 {
288  Point *point = PG_GETARG_POINT_P(0);
289  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
290 
291  PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
292 }
293 
295 
296 Datum
298 {
299  BOX *box = PG_GETARG_BOX_P(0);
300  double width,
301  height;
302 
303  width = Abs(box->high.x - box->low.x);
304  height = Abs(box->high.y - box->low.y);
305  PG_RETURN_FLOAT8(width * height);
306 }
307 
308 char *
309 reverse_name(char *string)
310 {
311  int i;
312  int len;
313  char *new_string;
314 
315  new_string = palloc0(NAMEDATALEN);
316  for (i = 0; i < NAMEDATALEN && string[i]; ++i)
317  ;
318  if (i == NAMEDATALEN || !string[i])
319  --i;
320  len = i;
321  for (; i >= 0; --i)
322  new_string[len - i] = string[i];
323  return new_string;
324 }
325 
326 /*
327  * This rather silly function is just to test that oldstyle functions
328  * work correctly on toast-able inputs.
329  */
330 int
332 {
333  int len = 0;
334 
335  if (t)
336  len = VARSIZE(t) - VARHDRSZ;
337 
338  return n + len;
339 }
340 
341 
344 static int fd17b_level = 0;
345 static int fd17a_level = 0;
346 static bool fd17b_recursion = true;
347 static bool fd17a_recursion = true;
348 
350 
351 Datum
353 {
354  TriggerData *trigdata = (TriggerData *) fcinfo->context;
355  TransactionId *xid;
356  int *level;
357  bool *recursion;
358  Relation rel;
359  TupleDesc tupdesc;
360  HeapTuple tuple;
361  char *query,
362  *fieldval,
363  *fieldtype;
364  char *when;
365  uint64 inserted;
366  int selected = 0;
367  int ret;
368 
369  if (!CALLED_AS_TRIGGER(fcinfo))
370  elog(ERROR, "funny_dup17: not fired by trigger manager");
371 
372  tuple = trigdata->tg_trigtuple;
373  rel = trigdata->tg_relation;
374  tupdesc = rel->rd_att;
375  if (TRIGGER_FIRED_BEFORE(trigdata->tg_event))
376  {
377  xid = &fd17b_xid;
378  level = &fd17b_level;
379  recursion = &fd17b_recursion;
380  when = "BEFORE";
381  }
382  else
383  {
384  xid = &fd17a_xid;
385  level = &fd17a_level;
386  recursion = &fd17a_recursion;
387  when = "AFTER ";
388  }
389 
391  {
392  *xid = GetCurrentTransactionId();
393  *level = 0;
394  *recursion = true;
395  }
396 
397  if (*level == 17)
398  {
399  *recursion = false;
400  return PointerGetDatum(tuple);
401  }
402 
403  if (!(*recursion))
404  return PointerGetDatum(tuple);
405 
406  (*level)++;
407 
408  SPI_connect();
409 
410  fieldval = SPI_getvalue(tuple, tupdesc, 1);
411  fieldtype = SPI_gettype(tupdesc, 1);
412 
413  query = (char *) palloc(100 + NAMEDATALEN * 3 +
414  strlen(fieldval) + strlen(fieldtype));
415 
416  sprintf(query, "insert into %s select * from %s where %s = '%s'::%s",
417  SPI_getrelname(rel), SPI_getrelname(rel),
418  SPI_fname(tupdesc, 1),
419  fieldval, fieldtype);
420 
421  if ((ret = SPI_exec(query, 0)) < 0)
422  elog(ERROR, "funny_dup17 (fired %s) on level %3d: SPI_exec (insert ...) returned %d",
423  when, *level, ret);
424 
425  inserted = SPI_processed;
426 
427  sprintf(query, "select count (*) from %s where %s = '%s'::%s",
428  SPI_getrelname(rel),
429  SPI_fname(tupdesc, 1),
430  fieldval, fieldtype);
431 
432  if ((ret = SPI_exec(query, 0)) < 0)
433  elog(ERROR, "funny_dup17 (fired %s) on level %3d: SPI_exec (select ...) returned %d",
434  when, *level, ret);
435 
436  if (SPI_processed > 0)
437  {
440  SPI_tuptable->vals[0],
442  1
443  ))));
444  }
445 
446  elog(DEBUG4, "funny_dup17 (fired %s) on level %3d: " UINT64_FORMAT "/%d tuples inserted/selected",
447  when, *level, inserted, selected);
448 
449  SPI_finish();
450 
451  (*level)--;
452 
453  if (*level == 0)
454  *xid = InvalidTransactionId;
455 
456  return PointerGetDatum(tuple);
457 }
458 
459 #define TTDUMMY_INFINITY 999999
460 
462 static bool ttoff = false;
463 
465 
466 Datum
468 {
469  TriggerData *trigdata = (TriggerData *) fcinfo->context;
470  Trigger *trigger; /* to get trigger name */
471  char **args; /* arguments */
472  int attnum[2]; /* fnumbers of start/stop columns */
473  Datum oldon,
474  oldoff;
475  Datum newon,
476  newoff;
477  Datum *cvals; /* column values */
478  char *cnulls; /* column nulls */
479  char *relname; /* triggered relation name */
480  Relation rel; /* triggered relation */
481  HeapTuple trigtuple;
482  HeapTuple newtuple = NULL;
483  HeapTuple rettuple;
484  TupleDesc tupdesc; /* tuple description */
485  int natts; /* # of attributes */
486  bool isnull; /* to know is some column NULL or not */
487  int ret;
488  int i;
489 
490  if (!CALLED_AS_TRIGGER(fcinfo))
491  elog(ERROR, "ttdummy: not fired by trigger manager");
492  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
493  elog(ERROR, "ttdummy: must be fired for row");
494  if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
495  elog(ERROR, "ttdummy: must be fired before event");
496  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
497  elog(ERROR, "ttdummy: cannot process INSERT event");
498  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
499  newtuple = trigdata->tg_newtuple;
500 
501  trigtuple = trigdata->tg_trigtuple;
502 
503  rel = trigdata->tg_relation;
504  relname = SPI_getrelname(rel);
505 
506  /* check if TT is OFF for this relation */
507  if (ttoff) /* OFF - nothing to do */
508  {
509  pfree(relname);
510  return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
511  }
512 
513  trigger = trigdata->tg_trigger;
514 
515  if (trigger->tgnargs != 2)
516  elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
517  relname, trigger->tgnargs);
518 
519  args = trigger->tgargs;
520  tupdesc = rel->rd_att;
521  natts = tupdesc->natts;
522 
523  for (i = 0; i < 2; i++)
524  {
525  attnum[i] = SPI_fnumber(tupdesc, args[i]);
526  if (attnum[i] <= 0)
527  elog(ERROR, "ttdummy (%s): there is no attribute %s",
528  relname, args[i]);
529  if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
530  elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
531  relname, args[i]);
532  }
533 
534  oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
535  if (isnull)
536  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
537 
538  oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
539  if (isnull)
540  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
541 
542  if (newtuple != NULL) /* UPDATE */
543  {
544  newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
545  if (isnull)
546  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
547  newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
548  if (isnull)
549  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
550 
551  if (oldon != newon || oldoff != newoff)
552  ereport(ERROR,
553  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
554  errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
555  relname, args[0], args[1])));
556 
557  if (newoff != TTDUMMY_INFINITY)
558  {
559  pfree(relname); /* allocated in upper executor context */
560  return PointerGetDatum(NULL);
561  }
562  }
563  else if (oldoff != TTDUMMY_INFINITY) /* DELETE */
564  {
565  pfree(relname);
566  return PointerGetDatum(NULL);
567  }
568 
569  newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
570  /* nextval now returns int64; coerce down to int32 */
571  newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
572 
573  /* Connect to SPI manager */
574  if ((ret = SPI_connect()) < 0)
575  elog(ERROR, "ttdummy (%s): SPI_connect returned %d", relname, ret);
576 
577  /* Fetch tuple values and nulls */
578  cvals = (Datum *) palloc(natts * sizeof(Datum));
579  cnulls = (char *) palloc(natts * sizeof(char));
580  for (i = 0; i < natts; i++)
581  {
582  cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
583  tupdesc, i + 1, &isnull);
584  cnulls[i] = (isnull) ? 'n' : ' ';
585  }
586 
587  /* change date column(s) */
588  if (newtuple) /* UPDATE */
589  {
590  cvals[attnum[0] - 1] = newoff; /* start_date eq current date */
591  cnulls[attnum[0] - 1] = ' ';
592  cvals[attnum[1] - 1] = TTDUMMY_INFINITY; /* stop_date eq INFINITY */
593  cnulls[attnum[1] - 1] = ' ';
594  }
595  else
596  /* DELETE */
597  {
598  cvals[attnum[1] - 1] = newoff; /* stop_date eq current date */
599  cnulls[attnum[1] - 1] = ' ';
600  }
601 
602  /* if there is no plan ... */
603  if (splan == NULL)
604  {
605  SPIPlanPtr pplan;
606  Oid *ctypes;
607  char *query;
608 
609  /* allocate space in preparation */
610  ctypes = (Oid *) palloc(natts * sizeof(Oid));
611  query = (char *) palloc(100 + 16 * natts);
612 
613  /*
614  * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
615  */
616  sprintf(query, "INSERT INTO %s VALUES (", relname);
617  for (i = 1; i <= natts; i++)
618  {
619  sprintf(query + strlen(query), "$%d%s",
620  i, (i < natts) ? ", " : ")");
621  ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
622  }
623 
624  /* Prepare plan for query */
625  pplan = SPI_prepare(query, natts, ctypes);
626  if (pplan == NULL)
627  elog(ERROR, "ttdummy (%s): SPI_prepare returned %d", relname, SPI_result);
628 
629  if (SPI_keepplan(pplan))
630  elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
631 
632  splan = pplan;
633  }
634 
635  ret = SPI_execp(splan, cvals, cnulls, 0);
636 
637  if (ret < 0)
638  elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
639 
640  /* Tuple to return to upper Executor ... */
641  if (newtuple) /* UPDATE */
642  rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
643  else /* DELETE */
644  rettuple = trigtuple;
645 
646  SPI_finish(); /* don't forget say Bye to SPI mgr */
647 
648  pfree(relname);
649 
650  return PointerGetDatum(rettuple);
651 }
652 
654 
655 Datum
657 {
658  int32 on = PG_GETARG_INT32(0);
659 
660  if (ttoff) /* OFF currently */
661  {
662  if (on == 0)
663  PG_RETURN_INT32(0);
664 
665  /* turn ON */
666  ttoff = false;
667  PG_RETURN_INT32(0);
668  }
669 
670  /* ON currently */
671  if (on != 0)
672  PG_RETURN_INT32(1);
673 
674  /* turn OFF */
675  ttoff = true;
676 
677  PG_RETURN_INT32(1);
678 }
679 
680 
681 /*
682  * Type int44 has no real-world use, but the regression tests use it.
683  * It's a four-element vector of int4's.
684  */
685 
686 /*
687  * int44in - converts "num num ..." to internal form
688  *
689  * Note: Fills any missing positions with zeroes.
690  */
692 
693 Datum
695 {
696  char *input_string = PG_GETARG_CSTRING(0);
697  int32 *result = (int32 *) palloc(4 * sizeof(int32));
698  int i;
699 
700  i = sscanf(input_string,
701  "%d, %d, %d, %d",
702  &result[0],
703  &result[1],
704  &result[2],
705  &result[3]);
706  while (i < 4)
707  result[i++] = 0;
708 
709  PG_RETURN_POINTER(result);
710 }
711 
712 /*
713  * int44out - converts internal form to "num num ..."
714  */
716 
717 Datum
719 {
720  int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
721  char *result = (char *) palloc(16 * 4); /* Allow 14 digits +
722  * sign */
723  int i;
724  char *walk;
725 
726  walk = result;
727  for (i = 0; i < 4; i++)
728  {
729  pg_ltoa(an_array[i], walk);
730  while (*++walk != '\0')
731  ;
732  *walk++ = ' ';
733  }
734  *--walk = '\0';
735  PG_RETURN_CSTRING(result);
736 }
737 
739 Datum
741 {
743  HeapTupleData tuple;
744  int ncolumns;
745  Datum *values;
746  bool *nulls;
747 
748  Oid tupType;
749  int32 tupTypmod;
750  TupleDesc tupdesc;
751 
752  HeapTuple newtup;
753 
754  int i;
755 
756  MemoryContext old_context;
757 
758  /* Extract type info from the tuple itself */
759  tupType = HeapTupleHeaderGetTypeId(rec);
760  tupTypmod = HeapTupleHeaderGetTypMod(rec);
761  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
762  ncolumns = tupdesc->natts;
763 
764  /* Build a temporary HeapTuple control structure */
766  ItemPointerSetInvalid(&(tuple.t_self));
767  tuple.t_tableOid = InvalidOid;
768  tuple.t_data = rec;
769 
770  values = (Datum *) palloc(ncolumns * sizeof(Datum));
771  nulls = (bool *) palloc(ncolumns * sizeof(bool));
772 
773  heap_deform_tuple(&tuple, tupdesc, values, nulls);
774 
776 
777  for (i = 0; i < ncolumns; i++)
778  {
779  struct varlena *attr;
780  struct varlena *new_attr;
781  struct varatt_indirect redirect_pointer;
782 
783  /* only work on existing, not-null varlenas */
784  if (tupdesc->attrs[i]->attisdropped ||
785  nulls[i] ||
786  tupdesc->attrs[i]->attlen != -1)
787  continue;
788 
789  attr = (struct varlena *) DatumGetPointer(values[i]);
790 
791  /* don't recursively indirect */
792  if (VARATT_IS_EXTERNAL_INDIRECT(attr))
793  continue;
794 
795  /* copy datum, so it still lives later */
796  if (VARATT_IS_EXTERNAL_ONDISK(attr))
797  attr = heap_tuple_fetch_attr(attr);
798  else
799  {
800  struct varlena *oldattr = attr;
801 
802  attr = palloc0(VARSIZE_ANY(oldattr));
803  memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
804  }
805 
806  /* build indirection Datum */
807  new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
808  redirect_pointer.pointer = attr;
810  memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
811  sizeof(redirect_pointer));
812 
813  values[i] = PointerGetDatum(new_attr);
814  }
815 
816  newtup = heap_form_tuple(tupdesc, values, nulls);
817  pfree(values);
818  pfree(nulls);
819  ReleaseTupleDesc(tupdesc);
820 
821  MemoryContextSwitchTo(old_context);
822 
823  /*
824  * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
825  * would cause the indirect toast pointers to be flattened out of the
826  * tuple immediately, rendering subsequent testing irrelevant. So just
827  * return the HeapTupleHeader pointer as-is. This violates the general
828  * rule that composite Datums shouldn't contain toast pointers, but so
829  * long as the regression test scripts don't insert the result of this
830  * function into a container type (record, array, etc) it should be OK.
831  */
832  PG_RETURN_POINTER(newtup->t_data);
833 }
834 
836 
837 Datum
839 {
840  MemoryContext oldcontext;
841  char *envbuf;
842 
843  if (!superuser())
844  elog(ERROR, "must be superuser to change environment variables");
845 
847  envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0));
848  MemoryContextSwitchTo(oldcontext);
849 
850  if (putenv(envbuf) != 0)
851  elog(ERROR, "could not set environment variable: %m");
852 
853  PG_RETURN_VOID();
854 }
855 
856 /* Sleep until no process has a given PID. */
858 
859 Datum
861 {
862  int pid = PG_GETARG_INT32(0);
863 
864  if (!superuser())
865  elog(ERROR, "must be superuser to check PID liveness");
866 
867  while (kill(pid, 0) == 0)
868  {
870  pg_usleep(50000);
871  }
872 
873  if (errno != ESRCH)
874  elog(ERROR, "could not check PID %d liveness: %m", pid);
875 
876  PG_RETURN_VOID();
877 }
878 
879 #ifndef PG_HAVE_ATOMIC_FLAG_SIMULATION
880 static void
881 test_atomic_flag(void)
882 {
884 
885  pg_atomic_init_flag(&flag);
886 
887  if (!pg_atomic_unlocked_test_flag(&flag))
888  elog(ERROR, "flag: unexpectedly set");
889 
890  if (!pg_atomic_test_set_flag(&flag))
891  elog(ERROR, "flag: couldn't set");
892 
893  if (pg_atomic_unlocked_test_flag(&flag))
894  elog(ERROR, "flag: unexpectedly unset");
895 
896  if (pg_atomic_test_set_flag(&flag))
897  elog(ERROR, "flag: set spuriously #2");
898 
899  pg_atomic_clear_flag(&flag);
900 
901  if (!pg_atomic_unlocked_test_flag(&flag))
902  elog(ERROR, "flag: unexpectedly set #2");
903 
904  if (!pg_atomic_test_set_flag(&flag))
905  elog(ERROR, "flag: couldn't set");
906 
907  pg_atomic_clear_flag(&flag);
908 }
909 #endif /* PG_HAVE_ATOMIC_FLAG_SIMULATION */
910 
911 static void
913 {
914  pg_atomic_uint32 var;
915  uint32 expected;
916  int i;
917 
918  pg_atomic_init_u32(&var, 0);
919 
920  if (pg_atomic_read_u32(&var) != 0)
921  elog(ERROR, "atomic_read_u32() #1 wrong");
922 
923  pg_atomic_write_u32(&var, 3);
924 
925  if (pg_atomic_read_u32(&var) != 3)
926  elog(ERROR, "atomic_read_u32() #2 wrong");
927 
928  if (pg_atomic_fetch_add_u32(&var, 1) != 3)
929  elog(ERROR, "atomic_fetch_add_u32() #1 wrong");
930 
931  if (pg_atomic_fetch_sub_u32(&var, 1) != 4)
932  elog(ERROR, "atomic_fetch_sub_u32() #1 wrong");
933 
934  if (pg_atomic_sub_fetch_u32(&var, 3) != 0)
935  elog(ERROR, "atomic_sub_fetch_u32() #1 wrong");
936 
937  if (pg_atomic_add_fetch_u32(&var, 10) != 10)
938  elog(ERROR, "atomic_add_fetch_u32() #1 wrong");
939 
940  if (pg_atomic_exchange_u32(&var, 5) != 10)
941  elog(ERROR, "pg_atomic_exchange_u32() #1 wrong");
942 
943  if (pg_atomic_exchange_u32(&var, 0) != 5)
944  elog(ERROR, "pg_atomic_exchange_u32() #0 wrong");
945 
946  /* test around numerical limits */
947  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != 0)
948  elog(ERROR, "pg_atomic_fetch_add_u32() #2 wrong");
949 
950  if (pg_atomic_fetch_add_u32(&var, INT_MAX) != INT_MAX)
951  elog(ERROR, "pg_atomic_add_fetch_u32() #3 wrong");
952 
953  pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
954 
955  if (pg_atomic_read_u32(&var) != UINT_MAX)
956  elog(ERROR, "atomic_read_u32() #2 wrong");
957 
958  if (pg_atomic_fetch_sub_u32(&var, INT_MAX) != UINT_MAX)
959  elog(ERROR, "pg_atomic_fetch_sub_u32() #2 wrong");
960 
961  if (pg_atomic_read_u32(&var) != (uint32) INT_MAX + 1)
962  elog(ERROR, "atomic_read_u32() #3 wrong: %u", pg_atomic_read_u32(&var));
963 
964  expected = pg_atomic_sub_fetch_u32(&var, INT_MAX);
965  if (expected != 1)
966  elog(ERROR, "pg_atomic_sub_fetch_u32() #3 wrong: %u", expected);
967 
968  pg_atomic_sub_fetch_u32(&var, 1);
969 
970  /* fail exchange because of old expected */
971  expected = 10;
972  if (pg_atomic_compare_exchange_u32(&var, &expected, 1))
973  elog(ERROR, "atomic_compare_exchange_u32() changed value spuriously");
974 
975  /* CAS is allowed to fail due to interrupts, try a couple of times */
976  for (i = 0; i < 1000; i++)
977  {
978  expected = 0;
979  if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
980  break;
981  }
982  if (i == 1000)
983  elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
984  if (pg_atomic_read_u32(&var) != 1)
985  elog(ERROR, "atomic_compare_exchange_u32() didn't set value properly");
986 
987  pg_atomic_write_u32(&var, 0);
988 
989  /* try setting flagbits */
990  if (pg_atomic_fetch_or_u32(&var, 1) & 1)
991  elog(ERROR, "pg_atomic_fetch_or_u32() #1 wrong");
992 
993  if (!(pg_atomic_fetch_or_u32(&var, 2) & 1))
994  elog(ERROR, "pg_atomic_fetch_or_u32() #2 wrong");
995 
996  if (pg_atomic_read_u32(&var) != 3)
997  elog(ERROR, "invalid result after pg_atomic_fetch_or_u32()");
998 
999  /* try clearing flagbits */
1000  if ((pg_atomic_fetch_and_u32(&var, ~2) & 3) != 3)
1001  elog(ERROR, "pg_atomic_fetch_and_u32() #1 wrong");
1002 
1003  if (pg_atomic_fetch_and_u32(&var, ~1) != 1)
1004  elog(ERROR, "pg_atomic_fetch_and_u32() #2 wrong: is %u",
1005  pg_atomic_read_u32(&var));
1006  /* no bits set anymore */
1007  if (pg_atomic_fetch_and_u32(&var, ~0) != 0)
1008  elog(ERROR, "pg_atomic_fetch_and_u32() #3 wrong");
1009 }
1010 
1011 #ifdef PG_HAVE_ATOMIC_U64_SUPPORT
1012 static void
1013 test_atomic_uint64(void)
1014 {
1015  pg_atomic_uint64 var;
1016  uint64 expected;
1017  int i;
1018 
1019  pg_atomic_init_u64(&var, 0);
1020 
1021  if (pg_atomic_read_u64(&var) != 0)
1022  elog(ERROR, "atomic_read_u64() #1 wrong");
1023 
1024  pg_atomic_write_u64(&var, 3);
1025 
1026  if (pg_atomic_read_u64(&var) != 3)
1027  elog(ERROR, "atomic_read_u64() #2 wrong");
1028 
1029  if (pg_atomic_fetch_add_u64(&var, 1) != 3)
1030  elog(ERROR, "atomic_fetch_add_u64() #1 wrong");
1031 
1032  if (pg_atomic_fetch_sub_u64(&var, 1) != 4)
1033  elog(ERROR, "atomic_fetch_sub_u64() #1 wrong");
1034 
1035  if (pg_atomic_sub_fetch_u64(&var, 3) != 0)
1036  elog(ERROR, "atomic_sub_fetch_u64() #1 wrong");
1037 
1038  if (pg_atomic_add_fetch_u64(&var, 10) != 10)
1039  elog(ERROR, "atomic_add_fetch_u64() #1 wrong");
1040 
1041  if (pg_atomic_exchange_u64(&var, 5) != 10)
1042  elog(ERROR, "pg_atomic_exchange_u64() #1 wrong");
1043 
1044  if (pg_atomic_exchange_u64(&var, 0) != 5)
1045  elog(ERROR, "pg_atomic_exchange_u64() #0 wrong");
1046 
1047  /* fail exchange because of old expected */
1048  expected = 10;
1049  if (pg_atomic_compare_exchange_u64(&var, &expected, 1))
1050  elog(ERROR, "atomic_compare_exchange_u64() changed value spuriously");
1051 
1052  /* CAS is allowed to fail due to interrupts, try a couple of times */
1053  for (i = 0; i < 100; i++)
1054  {
1055  expected = 0;
1056  if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
1057  break;
1058  }
1059  if (i == 100)
1060  elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
1061  if (pg_atomic_read_u64(&var) != 1)
1062  elog(ERROR, "atomic_compare_exchange_u64() didn't set value properly");
1063 
1064  pg_atomic_write_u64(&var, 0);
1065 
1066  /* try setting flagbits */
1067  if (pg_atomic_fetch_or_u64(&var, 1) & 1)
1068  elog(ERROR, "pg_atomic_fetch_or_u64() #1 wrong");
1069 
1070  if (!(pg_atomic_fetch_or_u64(&var, 2) & 1))
1071  elog(ERROR, "pg_atomic_fetch_or_u64() #2 wrong");
1072 
1073  if (pg_atomic_read_u64(&var) != 3)
1074  elog(ERROR, "invalid result after pg_atomic_fetch_or_u64()");
1075 
1076  /* try clearing flagbits */
1077  if ((pg_atomic_fetch_and_u64(&var, ~2) & 3) != 3)
1078  elog(ERROR, "pg_atomic_fetch_and_u64() #1 wrong");
1079 
1080  if (pg_atomic_fetch_and_u64(&var, ~1) != 1)
1081  elog(ERROR, "pg_atomic_fetch_and_u64() #2 wrong: is " UINT64_FORMAT,
1082  pg_atomic_read_u64(&var));
1083  /* no bits set anymore */
1084  if (pg_atomic_fetch_and_u64(&var, ~0) != 0)
1085  elog(ERROR, "pg_atomic_fetch_and_u64() #3 wrong");
1086 }
1087 #endif /* PG_HAVE_ATOMIC_U64_SUPPORT */
1088 
1089 
1091 Datum
1093 {
1094  /* ---
1095  * Can't run the test under the semaphore emulation, it doesn't handle
1096  * checking two edge cases well:
1097  * - pg_atomic_unlocked_test_flag() always returns true
1098  * - locking a already locked flag blocks
1099  * it seems better to not test the semaphore fallback here, than weaken
1100  * the checks for the other cases. The semaphore code will be the same
1101  * everywhere, whereas the efficient implementations wont.
1102  * ---
1103  */
1104 #ifndef PG_HAVE_ATOMIC_FLAG_SIMULATION
1105  test_atomic_flag();
1106 #endif
1107 
1109 
1110 #ifdef PG_HAVE_ATOMIC_U64_SUPPORT
1111  test_atomic_uint64();
1112 #endif
1113 
1114  PG_RETURN_BOOL(true);
1115 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:760
PG_FUNCTION_INFO_V1(regress_dist_ptpath)
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:305
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:217
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:317
#define PG_GETARG_INT32(n)
Definition: fmgr.h:225
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:891
double radius
Definition: regress.c:240
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:353
static TransactionId fd17a_xid
Definition: regress.c:343
Definition: geo_decls.h:102
Datum boxarea(PG_FUNCTION_ARGS)
Definition: regress.c:297
Datum make_tuple_indirect(PG_FUNCTION_ARGS)
Definition: regress.c:740
#define PG_GETARG_BOX_P(n)
Definition: geo_decls.h:161
#define DatumGetPathP(X)
Definition: geo_decls.h:147
#define RDELIM
Definition: regress.c:43
MemoryContext TopTransactionContext
Definition: mcxt.c:48
WIDGET * widget_in(char *str)
Definition: regress.c:249
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1245
uint32 TransactionId
Definition: c.h:393
Datum int44in(PG_FUNCTION_ARGS)
Definition: regress.c:694
#define DatumGetInt32(X)
Definition: postgres.h:480
char * str
Definition: pg_regress.h:25
bool TransactionIdIsCurrentTransactionId(TransactionId xid)
Definition: xact.c:772
int SPI_connect(void)
Definition: spi.c:84
static void test_atomic_uint32(void)
Definition: regress.c:912
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:321
#define VARSIZE(PTR)
Definition: postgres.h:306
char * widget_out(WIDGET *widget)
Definition: regress.c:277
static void output(uint64 loop_count)
#define PointerGetDatum(X)
Definition: postgres.h:564
struct varlena * heap_tuple_fetch_attr(struct varlena *attr)
Definition: tuptoaster.c:101
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:411
void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:209
#define VARHDRSZ
Definition: c.h:440
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:481
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Datum regress_dist_ptpath(PG_FUNCTION_ARGS)
Definition: regress.c:62
Definition: geo_decls.h:68
Datum int4in(PG_FUNCTION_ARGS)
Definition: int.c:266
int SPI_finish(void)
Definition: spi.c:147
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:310
PATH * poly2path(POLYGON *poly)
Definition: regress.c:143
Datum nextval(PG_FUNCTION_ARGS)
Definition: sequence.c:539
Form_pg_attribute * attrs
Definition: tupdesc.h:74
double y
Definition: geo_decls.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_INT32(x)
Definition: fmgr.h:298
#define INT4OID
Definition: pg_type.h:316
SPITupleTable * SPI_tuptable
Definition: spi.c:41
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2310
bool superuser(void)
Definition: superuser.c:47
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:396
int oldstyle_length(int n, text *t)
Definition: regress.c:331
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:232
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:555
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:275
unsigned int Oid
Definition: postgres_ext.h:31
HeapTuple * vals
Definition: spi.h:27
#define putenv(x)
Definition: win32.h:421
#define DEBUG4
Definition: elog.h:22
int32 npts
Definition: geo_decls.h:116
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:313
int natts
Definition: tupdesc.h:73
uint64 SPI_processed
Definition: spi.c:39
Datum set_ttdummy(PG_FUNCTION_ARGS)
Definition: regress.c:656
HeapTuple tg_trigtuple
Definition: trigger.h:35
signed int int32
Definition: c.h:253
char * SPI_gettype(TupleDesc tupdesc, int fnumber)
Definition: spi.c:851
#define Abs(x)
Definition: c.h:807
double x
Definition: geo_decls.h:60
char * SPI_fname(TupleDesc tupdesc, int fnumber)
Definition: spi.c:781
HeapTupleHeader t_data
Definition: htup.h:67
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:302
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Definition: spi.c:803
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:455
static bool ttoff
Definition: regress.c:462
#define NAMEDATALEN
#define P_MAXDIG
Definition: regress.c:41
int SPI_result
Definition: spi.c:42
void pg_usleep(long microsec)
Definition: signal.c:53
void pfree(void *pointer)
Definition: mcxt.c:992
#define LsegPGetDatum(X)
Definition: geo_decls.h:143
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: postgres.h:319
Datum regress_putenv(PG_FUNCTION_ARGS)
Definition: regress.c:838
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:377
int SPI_exec(const char *src, long tcount)
Definition: spi.c:331
Datum test_atomic_ops(PG_FUNCTION_ARGS)
Definition: regress.c:1092
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:139
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:83
int32 npts
Definition: geo_decls.h:80
ItemPointerData t_self
Definition: htup.h:65
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:835
#define DatumGetInt64(X)
Definition: postgres.h:615
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execQual.c:1209
static int fd17b_level
Definition: regress.c:344
static bool fd17a_recursion
Definition: regress.c:347
static int fd17a_level
Definition: regress.c:345
TransactionId GetCurrentTransactionId(void)
Definition: xact.c:416
uint32 t_len
Definition: htup.h:64
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:559
static char * buf
Definition: pg_test_fsync.c:65
Datum funny_dup17(PG_FUNCTION_ARGS)
Definition: regress.c:352
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:334
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:189
char * flag(int b)
Definition: test-ctype.c:33
char * reverse_name(char *string)
Definition: regress.c:309
#define CStringGetDatum(X)
Definition: postgres.h:586
#define DatumGetBool(X)
Definition: postgres.h:401
#define InvalidTransactionId
Definition: transam.h:31
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:368
unsigned int uint32
Definition: c.h:265
Oid t_tableOid
Definition: htup.h:66
Datum dist_ps(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2358
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:118
static SPIPlanPtr splan
Definition: regress.c:461
Definition: type.h:83
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:689
Datum lseg_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2209
#define ereport(elevel, rest)
Definition: elog.h:122
static TransactionId fd17b_xid
Definition: regress.c:342
MemoryContext TopMemoryContext
Definition: mcxt.c:43
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:150
static bool fd17b_recursion
Definition: regress.c:346
Point low
Definition: geo_decls.h:104
Datum path_in(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1307
#define INDIRECT_POINTER_SIZE
Definition: tuptoaster.h:102
#define DELIM
Definition: regress.c:44
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2051
#define TTDUMMY_INFINITY
Definition: regress.c:459
PG_MODULE_MAGIC
Definition: regress.c:52
void * palloc0(Size size)
Definition: mcxt.c:920
#define DatumGetFloat8(X)
Definition: postgres.h:736
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:303
uintptr_t Datum
Definition: postgres.h:374
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:297
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:445
TupleDesc tupdesc
Definition: spi.h:26
Trigger * tg_trigger
Definition: trigger.h:37
TupleDesc rd_att
Definition: rel.h:114
HeapTuple tg_newtuple
Definition: trigger.h:36
#define VARSIZE_ANY(PTR)
Definition: postgres.h:336
char * SPI_getrelname(Relation rel)
Definition: spi.c:909
#define InvalidOid
Definition: postgres_ext.h:36
Datum pt_in_widget(PG_FUNCTION_ARGS)
Definition: regress.c:286
#define PG_RETURN_VOID()
Definition: fmgr.h:293
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:338
#define NULL
Definition: c.h:226
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
#define Assert(condition)
Definition: c.h:670
TriggerEvent tg_event
Definition: trigger.h:33
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:306
#define NARGS
Definition: regress.c:246
Datum interpt_pp(PG_FUNCTION_ARGS)
Definition: regress.c:168
Point p[2]
Definition: geo_decls.h:70
struct varlena * pointer
Definition: postgres.h:87
Point high
Definition: geo_decls.h:104
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:204
Datum overpaid(PG_FUNCTION_ARGS)
Definition: regress.c:220
#define DatumGetPointer(X)
Definition: postgres.h:557
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:935
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:88
static Datum values[MAXATTR]
Definition: bootstrap.c:162
Datum wait_pid(PG_FUNCTION_ARGS)
Definition: regress.c:860
char * text_to_cstring(const text *t)
Definition: varlena.c:184
double point_dt(Point *pt1, Point *pt2)
Definition: geo_ops.c:1906
#define Int32GetDatum(X)
Definition: postgres.h:487
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:70
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:131
Definition: geo_decls.h:77
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
Point center
Definition: regress.c:239
int i
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:365
Datum regress_path_dist(PG_FUNCTION_ARGS)
Definition: regress.c:106
#define CStringGetTextDatum(s)
Definition: builtins.h:90
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:233
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:382
Datum int44out(PG_FUNCTION_ARGS)
Definition: regress.c:718
Definition: c.h:434
#define PG_FUNCTION_ARGS
Definition: fmgr.h:150
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:233
#define elog
Definition: elog.h:219
Datum ttdummy(PG_FUNCTION_ARGS)
Definition: regress.c:467
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:268
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:107
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:82
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:174
void pg_ltoa(int32 value, char *a)
Definition: numutils.c:132
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:76
#define UINT64_FORMAT
Definition: c.h:313
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:557
#define PG_RETURN_NULL()
Definition: fmgr.h:289
#define PointPGetDatum(X)
Definition: geo_decls.h:138
#define LDELIM
Definition: regress.c:42
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:251
Relation tg_relation
Definition: trigger.h:34
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:439