PostgreSQL Source Code  git master
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-2021, 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 <math.h>
20 #include <signal.h>
21 
22 #include "access/detoast.h"
23 #include "access/htup_details.h"
24 #include "access/transam.h"
25 #include "access/xact.h"
26 #include "catalog/namespace.h"
27 #include "catalog/pg_operator.h"
28 #include "catalog/pg_type.h"
29 #include "commands/sequence.h"
30 #include "commands/trigger.h"
31 #include "executor/executor.h"
32 #include "executor/spi.h"
33 #include "funcapi.h"
34 #include "mb/pg_wchar.h"
35 #include "miscadmin.h"
36 #include "nodes/supportnodes.h"
37 #include "optimizer/optimizer.h"
38 #include "optimizer/plancat.h"
39 #include "port/atomics.h"
40 #include "storage/spin.h"
41 #include "utils/builtins.h"
42 #include "utils/geo_decls.h"
43 #include "utils/memutils.h"
44 #include "utils/rel.h"
45 #include "utils/typcache.h"
46 
47 #define EXPECT_TRUE(expr) \
48  do { \
49  if (!(expr)) \
50  elog(ERROR, \
51  "%s was unexpectedly false in file \"%s\" line %u", \
52  #expr, __FILE__, __LINE__); \
53  } while (0)
54 
55 #define EXPECT_EQ_U32(result_expr, expected_expr) \
56  do { \
57  uint32 result = (result_expr); \
58  uint32 expected = (expected_expr); \
59  if (result != expected) \
60  elog(ERROR, \
61  "%s yielded %u, expected %s in file \"%s\" line %u", \
62  #result_expr, result, #expected_expr, __FILE__, __LINE__); \
63  } while (0)
64 
65 #define EXPECT_EQ_U64(result_expr, expected_expr) \
66  do { \
67  uint64 result = (result_expr); \
68  uint64 expected = (expected_expr); \
69  if (result != expected) \
70  elog(ERROR, \
71  "%s yielded " UINT64_FORMAT ", expected %s in file \"%s\" line %u", \
72  #result_expr, result, #expected_expr, __FILE__, __LINE__); \
73  } while (0)
74 
75 #define LDELIM '('
76 #define RDELIM ')'
77 #define DELIM ','
78 
79 static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
80 
82 
83 
84 /* return the point where two paths intersect, or NULL if no intersection. */
86 
87 Datum
89 {
90  PATH *p1 = PG_GETARG_PATH_P(0);
91  PATH *p2 = PG_GETARG_PATH_P(1);
92  int i,
93  j;
94  LSEG seg1,
95  seg2;
96  bool found; /* We've found the intersection */
97 
98  found = false; /* Haven't found it yet */
99 
100  for (i = 0; i < p1->npts - 1 && !found; i++)
101  {
102  regress_lseg_construct(&seg1, &p1->p[i], &p1->p[i + 1]);
103  for (j = 0; j < p2->npts - 1 && !found; j++)
104  {
105  regress_lseg_construct(&seg2, &p2->p[j], &p2->p[j + 1]);
107  LsegPGetDatum(&seg1),
108  LsegPGetDatum(&seg2))))
109  found = true;
110  }
111  }
112 
113  if (!found)
114  PG_RETURN_NULL();
115 
116  /*
117  * Note: DirectFunctionCall2 will kick out an error if lseg_interpt()
118  * returns NULL, but that should be impossible since we know the two
119  * segments intersect.
120  */
122  LsegPGetDatum(&seg1),
123  LsegPGetDatum(&seg2)));
124 }
125 
126 
127 /* like lseg_construct, but assume space already allocated */
128 static void
130 {
131  lseg->p[0].x = pt1->x;
132  lseg->p[0].y = pt1->y;
133  lseg->p[1].x = pt2->x;
134  lseg->p[1].y = pt2->y;
135 }
136 
138 
139 Datum
141 {
143  bool isnull;
144  int32 salary;
145 
146  salary = DatumGetInt32(GetAttributeByName(tuple, "salary", &isnull));
147  if (isnull)
148  PG_RETURN_NULL();
149  PG_RETURN_BOOL(salary > 699);
150 }
151 
152 /* New type "widget"
153  * This used to be "circle", but I added circle to builtins,
154  * so needed to make sure the names do not collide. - tgl 97/04/21
155  */
156 
157 typedef struct
158 {
160  double radius;
161 } WIDGET;
162 
165 
166 #define NARGS 3
167 
168 Datum
170 {
171  char *str = PG_GETARG_CSTRING(0);
172  char *p,
173  *coord[NARGS];
174  int i;
175  WIDGET *result;
176 
177  for (i = 0, p = str; *p && i < NARGS && *p != RDELIM; p++)
178  {
179  if (*p == DELIM || (*p == LDELIM && i == 0))
180  coord[i++] = p + 1;
181  }
182 
183  if (i < NARGS)
184  ereport(ERROR,
185  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
186  errmsg("invalid input syntax for type %s: \"%s\"",
187  "widget", str)));
188 
189  result = (WIDGET *) palloc(sizeof(WIDGET));
190  result->center.x = atof(coord[0]);
191  result->center.y = atof(coord[1]);
192  result->radius = atof(coord[2]);
193 
194  PG_RETURN_POINTER(result);
195 }
196 
197 Datum
199 {
200  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
201  char *str = psprintf("(%g,%g,%g)",
202  widget->center.x, widget->center.y, widget->radius);
203 
204  PG_RETURN_CSTRING(str);
205 }
206 
208 
209 Datum
211 {
212  Point *point = PG_GETARG_POINT_P(0);
213  WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(1);
214  float8 distance;
215 
217  PointPGetDatum(point),
218  PointPGetDatum(&widget->center)));
219 
220  PG_RETURN_BOOL(distance < widget->radius);
221 }
222 
224 
225 Datum
227 {
228  char *string = PG_GETARG_CSTRING(0);
229  int i;
230  int len;
231  char *new_string;
232 
233  new_string = palloc0(NAMEDATALEN);
234  for (i = 0; i < NAMEDATALEN && string[i]; ++i)
235  ;
236  if (i == NAMEDATALEN || !string[i])
237  --i;
238  len = i;
239  for (; i >= 0; --i)
240  new_string[len - i] = string[i];
241  PG_RETURN_CSTRING(new_string);
242 }
243 
245 
246 Datum
248 {
249  TriggerData *trigdata = (TriggerData *) fcinfo->context;
250  HeapTuple tuple;
251 
252  if (!CALLED_AS_TRIGGER(fcinfo))
253  elog(ERROR, "trigger_return_old: not fired by trigger manager");
254 
255  tuple = trigdata->tg_trigtuple;
256 
257  return PointerGetDatum(tuple);
258 }
259 
260 #define TTDUMMY_INFINITY 999999
261 
262 static SPIPlanPtr splan = NULL;
263 static bool ttoff = false;
264 
266 
267 Datum
269 {
270  TriggerData *trigdata = (TriggerData *) fcinfo->context;
271  Trigger *trigger; /* to get trigger name */
272  char **args; /* arguments */
273  int attnum[2]; /* fnumbers of start/stop columns */
274  Datum oldon,
275  oldoff;
276  Datum newon,
277  newoff;
278  Datum *cvals; /* column values */
279  char *cnulls; /* column nulls */
280  char *relname; /* triggered relation name */
281  Relation rel; /* triggered relation */
282  HeapTuple trigtuple;
283  HeapTuple newtuple = NULL;
284  HeapTuple rettuple;
285  TupleDesc tupdesc; /* tuple description */
286  int natts; /* # of attributes */
287  bool isnull; /* to know is some column NULL or not */
288  int ret;
289  int i;
290 
291  if (!CALLED_AS_TRIGGER(fcinfo))
292  elog(ERROR, "ttdummy: not fired by trigger manager");
293  if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
294  elog(ERROR, "ttdummy: must be fired for row");
295  if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
296  elog(ERROR, "ttdummy: must be fired before event");
297  if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
298  elog(ERROR, "ttdummy: cannot process INSERT event");
299  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
300  newtuple = trigdata->tg_newtuple;
301 
302  trigtuple = trigdata->tg_trigtuple;
303 
304  rel = trigdata->tg_relation;
305  relname = SPI_getrelname(rel);
306 
307  /* check if TT is OFF for this relation */
308  if (ttoff) /* OFF - nothing to do */
309  {
310  pfree(relname);
311  return PointerGetDatum((newtuple != NULL) ? newtuple : trigtuple);
312  }
313 
314  trigger = trigdata->tg_trigger;
315 
316  if (trigger->tgnargs != 2)
317  elog(ERROR, "ttdummy (%s): invalid (!= 2) number of arguments %d",
318  relname, trigger->tgnargs);
319 
320  args = trigger->tgargs;
321  tupdesc = rel->rd_att;
322  natts = tupdesc->natts;
323 
324  for (i = 0; i < 2; i++)
325  {
326  attnum[i] = SPI_fnumber(tupdesc, args[i]);
327  if (attnum[i] <= 0)
328  elog(ERROR, "ttdummy (%s): there is no attribute %s",
329  relname, args[i]);
330  if (SPI_gettypeid(tupdesc, attnum[i]) != INT4OID)
331  elog(ERROR, "ttdummy (%s): attribute %s must be of integer type",
332  relname, args[i]);
333  }
334 
335  oldon = SPI_getbinval(trigtuple, tupdesc, attnum[0], &isnull);
336  if (isnull)
337  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
338 
339  oldoff = SPI_getbinval(trigtuple, tupdesc, attnum[1], &isnull);
340  if (isnull)
341  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
342 
343  if (newtuple != NULL) /* UPDATE */
344  {
345  newon = SPI_getbinval(newtuple, tupdesc, attnum[0], &isnull);
346  if (isnull)
347  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[0]);
348  newoff = SPI_getbinval(newtuple, tupdesc, attnum[1], &isnull);
349  if (isnull)
350  elog(ERROR, "ttdummy (%s): %s must be NOT NULL", relname, args[1]);
351 
352  if (oldon != newon || oldoff != newoff)
353  ereport(ERROR,
354  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
355  errmsg("ttdummy (%s): you cannot change %s and/or %s columns (use set_ttdummy)",
356  relname, args[0], args[1])));
357 
358  if (newoff != TTDUMMY_INFINITY)
359  {
360  pfree(relname); /* allocated in upper executor context */
361  return PointerGetDatum(NULL);
362  }
363  }
364  else if (oldoff != TTDUMMY_INFINITY) /* DELETE */
365  {
366  pfree(relname);
367  return PointerGetDatum(NULL);
368  }
369 
370  newoff = DirectFunctionCall1(nextval, CStringGetTextDatum("ttdummy_seq"));
371  /* nextval now returns int64; coerce down to int32 */
372  newoff = Int32GetDatum((int32) DatumGetInt64(newoff));
373 
374  /* Connect to SPI manager */
375  if ((ret = SPI_connect()) < 0)
376  elog(ERROR, "ttdummy (%s): SPI_connect returned %d", relname, ret);
377 
378  /* Fetch tuple values and nulls */
379  cvals = (Datum *) palloc(natts * sizeof(Datum));
380  cnulls = (char *) palloc(natts * sizeof(char));
381  for (i = 0; i < natts; i++)
382  {
383  cvals[i] = SPI_getbinval((newtuple != NULL) ? newtuple : trigtuple,
384  tupdesc, i + 1, &isnull);
385  cnulls[i] = (isnull) ? 'n' : ' ';
386  }
387 
388  /* change date column(s) */
389  if (newtuple) /* UPDATE */
390  {
391  cvals[attnum[0] - 1] = newoff; /* start_date eq current date */
392  cnulls[attnum[0] - 1] = ' ';
393  cvals[attnum[1] - 1] = TTDUMMY_INFINITY; /* stop_date eq INFINITY */
394  cnulls[attnum[1] - 1] = ' ';
395  }
396  else
397  /* DELETE */
398  {
399  cvals[attnum[1] - 1] = newoff; /* stop_date eq current date */
400  cnulls[attnum[1] - 1] = ' ';
401  }
402 
403  /* if there is no plan ... */
404  if (splan == NULL)
405  {
406  SPIPlanPtr pplan;
407  Oid *ctypes;
408  char *query;
409 
410  /* allocate space in preparation */
411  ctypes = (Oid *) palloc(natts * sizeof(Oid));
412  query = (char *) palloc(100 + 16 * natts);
413 
414  /*
415  * Construct query: INSERT INTO _relation_ VALUES ($1, ...)
416  */
417  sprintf(query, "INSERT INTO %s VALUES (", relname);
418  for (i = 1; i <= natts; i++)
419  {
420  sprintf(query + strlen(query), "$%d%s",
421  i, (i < natts) ? ", " : ")");
422  ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
423  }
424 
425  /* Prepare plan for query */
426  pplan = SPI_prepare(query, natts, ctypes);
427  if (pplan == NULL)
428  elog(ERROR, "ttdummy (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
429 
430  if (SPI_keepplan(pplan))
431  elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);
432 
433  splan = pplan;
434  }
435 
436  ret = SPI_execp(splan, cvals, cnulls, 0);
437 
438  if (ret < 0)
439  elog(ERROR, "ttdummy (%s): SPI_execp returned %d", relname, ret);
440 
441  /* Tuple to return to upper Executor ... */
442  if (newtuple) /* UPDATE */
443  rettuple = SPI_modifytuple(rel, trigtuple, 1, &(attnum[1]), &newoff, NULL);
444  else /* DELETE */
445  rettuple = trigtuple;
446 
447  SPI_finish(); /* don't forget say Bye to SPI mgr */
448 
449  pfree(relname);
450 
451  return PointerGetDatum(rettuple);
452 }
453 
455 
456 Datum
458 {
459  int32 on = PG_GETARG_INT32(0);
460 
461  if (ttoff) /* OFF currently */
462  {
463  if (on == 0)
464  PG_RETURN_INT32(0);
465 
466  /* turn ON */
467  ttoff = false;
468  PG_RETURN_INT32(0);
469  }
470 
471  /* ON currently */
472  if (on != 0)
473  PG_RETURN_INT32(1);
474 
475  /* turn OFF */
476  ttoff = true;
477 
478  PG_RETURN_INT32(1);
479 }
480 
481 
482 /*
483  * Type int44 has no real-world use, but the regression tests use it
484  * (under the alias "city_budget"). It's a four-element vector of int4's.
485  */
486 
487 /*
488  * int44in - converts "num, num, ..." to internal form
489  *
490  * Note: Fills any missing positions with zeroes.
491  */
493 
494 Datum
496 {
497  char *input_string = PG_GETARG_CSTRING(0);
498  int32 *result = (int32 *) palloc(4 * sizeof(int32));
499  int i;
500 
501  i = sscanf(input_string,
502  "%d, %d, %d, %d",
503  &result[0],
504  &result[1],
505  &result[2],
506  &result[3]);
507  while (i < 4)
508  result[i++] = 0;
509 
510  PG_RETURN_POINTER(result);
511 }
512 
513 /*
514  * int44out - converts internal form to "num, num, ..."
515  */
517 
518 Datum
520 {
521  int32 *an_array = (int32 *) PG_GETARG_POINTER(0);
522  char *result = (char *) palloc(16 * 4);
523 
524  snprintf(result, 16 * 4, "%d,%d,%d,%d",
525  an_array[0],
526  an_array[1],
527  an_array[2],
528  an_array[3]);
529 
530  PG_RETURN_CSTRING(result);
531 }
532 
534 Datum
536 {
538  HeapTupleData tuple;
539  int ncolumns;
540  Datum *values;
541  bool *nulls;
542 
543  Oid tupType;
544  int32 tupTypmod;
545  TupleDesc tupdesc;
546 
547  HeapTuple newtup;
548 
549  int i;
550 
551  MemoryContext old_context;
552 
553  /* Extract type info from the tuple itself */
554  tupType = HeapTupleHeaderGetTypeId(rec);
555  tupTypmod = HeapTupleHeaderGetTypMod(rec);
556  tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
557  ncolumns = tupdesc->natts;
558 
559  /* Build a temporary HeapTuple control structure */
561  ItemPointerSetInvalid(&(tuple.t_self));
562  tuple.t_tableOid = InvalidOid;
563  tuple.t_data = rec;
564 
565  values = (Datum *) palloc(ncolumns * sizeof(Datum));
566  nulls = (bool *) palloc(ncolumns * sizeof(bool));
567 
568  heap_deform_tuple(&tuple, tupdesc, values, nulls);
569 
571 
572  for (i = 0; i < ncolumns; i++)
573  {
574  struct varlena *attr;
575  struct varlena *new_attr;
576  struct varatt_indirect redirect_pointer;
577 
578  /* only work on existing, not-null varlenas */
579  if (TupleDescAttr(tupdesc, i)->attisdropped ||
580  nulls[i] ||
581  TupleDescAttr(tupdesc, i)->attlen != -1)
582  continue;
583 
584  attr = (struct varlena *) DatumGetPointer(values[i]);
585 
586  /* don't recursively indirect */
587  if (VARATT_IS_EXTERNAL_INDIRECT(attr))
588  continue;
589 
590  /* copy datum, so it still lives later */
591  if (VARATT_IS_EXTERNAL_ONDISK(attr))
592  attr = detoast_external_attr(attr);
593  else
594  {
595  struct varlena *oldattr = attr;
596 
597  attr = palloc0(VARSIZE_ANY(oldattr));
598  memcpy(attr, oldattr, VARSIZE_ANY(oldattr));
599  }
600 
601  /* build indirection Datum */
602  new_attr = (struct varlena *) palloc0(INDIRECT_POINTER_SIZE);
603  redirect_pointer.pointer = attr;
605  memcpy(VARDATA_EXTERNAL(new_attr), &redirect_pointer,
606  sizeof(redirect_pointer));
607 
608  values[i] = PointerGetDatum(new_attr);
609  }
610 
611  newtup = heap_form_tuple(tupdesc, values, nulls);
612  pfree(values);
613  pfree(nulls);
614  ReleaseTupleDesc(tupdesc);
615 
616  MemoryContextSwitchTo(old_context);
617 
618  /*
619  * We intentionally don't use PG_RETURN_HEAPTUPLEHEADER here, because that
620  * would cause the indirect toast pointers to be flattened out of the
621  * tuple immediately, rendering subsequent testing irrelevant. So just
622  * return the HeapTupleHeader pointer as-is. This violates the general
623  * rule that composite Datums shouldn't contain toast pointers, but so
624  * long as the regression test scripts don't insert the result of this
625  * function into a container type (record, array, etc) it should be OK.
626  */
627  PG_RETURN_POINTER(newtup->t_data);
628 }
629 
631 
632 Datum
634 {
635  char *envvar = text_to_cstring(PG_GETARG_TEXT_PP(0));
636  char *envval = text_to_cstring(PG_GETARG_TEXT_PP(1));
637 
638  if (!superuser())
639  elog(ERROR, "must be superuser to change environment variables");
640 
641  if (setenv(envvar, envval, 1) != 0)
642  elog(ERROR, "could not set environment variable: %m");
643 
644  PG_RETURN_VOID();
645 }
646 
647 /* Sleep until no process has a given PID. */
649 
650 Datum
652 {
653  int pid = PG_GETARG_INT32(0);
654 
655  if (!superuser())
656  elog(ERROR, "must be superuser to check PID liveness");
657 
658  while (kill(pid, 0) == 0)
659  {
661  pg_usleep(50000);
662  }
663 
664  if (errno != ESRCH)
665  elog(ERROR, "could not check PID %d liveness: %m", pid);
666 
667  PG_RETURN_VOID();
668 }
669 
670 static void
672 {
674 
675  pg_atomic_init_flag(&flag);
680  pg_atomic_clear_flag(&flag);
683  pg_atomic_clear_flag(&flag);
684 }
685 
686 static void
688 {
689  pg_atomic_uint32 var;
690  uint32 expected;
691  int i;
692 
693  pg_atomic_init_u32(&var, 0);
695  pg_atomic_write_u32(&var, 3);
698  3);
701  EXPECT_EQ_U32(pg_atomic_add_fetch_u32(&var, 10), 10);
704 
705  /* test around numerical limits */
706  EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), 0);
707  EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&var, INT_MAX), INT_MAX);
708  pg_atomic_fetch_add_u32(&var, 2); /* wrap to 0 */
711  PG_INT16_MAX);
713  2 * PG_INT16_MAX + 1);
715  PG_INT16_MAX);
716  pg_atomic_fetch_add_u32(&var, 1); /* top up to UINT_MAX */
717  EXPECT_EQ_U32(pg_atomic_read_u32(&var), UINT_MAX);
718  EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&var, INT_MAX), UINT_MAX);
719  EXPECT_EQ_U32(pg_atomic_read_u32(&var), (uint32) INT_MAX + 1);
720  EXPECT_EQ_U32(pg_atomic_sub_fetch_u32(&var, INT_MAX), 1);
721  pg_atomic_sub_fetch_u32(&var, 1);
722  expected = PG_INT16_MAX;
723  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
724  expected = PG_INT16_MAX + 1;
725  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
726  expected = PG_INT16_MIN;
727  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
728  expected = PG_INT16_MIN - 1;
729  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
730 
731  /* fail exchange because of old expected */
732  expected = 10;
733  EXPECT_TRUE(!pg_atomic_compare_exchange_u32(&var, &expected, 1));
734 
735  /* CAS is allowed to fail due to interrupts, try a couple of times */
736  for (i = 0; i < 1000; i++)
737  {
738  expected = 0;
739  if (!pg_atomic_compare_exchange_u32(&var, &expected, 1))
740  break;
741  }
742  if (i == 1000)
743  elog(ERROR, "atomic_compare_exchange_u32() never succeeded");
745  pg_atomic_write_u32(&var, 0);
746 
747  /* try setting flagbits */
748  EXPECT_TRUE(!(pg_atomic_fetch_or_u32(&var, 1) & 1));
749  EXPECT_TRUE(pg_atomic_fetch_or_u32(&var, 2) & 1);
751  /* try clearing flagbits */
752  EXPECT_EQ_U32(pg_atomic_fetch_and_u32(&var, ~2) & 3, 3);
754  /* no bits set anymore */
756 }
757 
758 static void
760 {
761  pg_atomic_uint64 var;
762  uint64 expected;
763  int i;
764 
765  pg_atomic_init_u64(&var, 0);
767  pg_atomic_write_u64(&var, 3);
770  3);
773  EXPECT_EQ_U64(pg_atomic_add_fetch_u64(&var, 10), 10);
776 
777  /* fail exchange because of old expected */
778  expected = 10;
779  EXPECT_TRUE(!pg_atomic_compare_exchange_u64(&var, &expected, 1));
780 
781  /* CAS is allowed to fail due to interrupts, try a couple of times */
782  for (i = 0; i < 100; i++)
783  {
784  expected = 0;
785  if (!pg_atomic_compare_exchange_u64(&var, &expected, 1))
786  break;
787  }
788  if (i == 100)
789  elog(ERROR, "atomic_compare_exchange_u64() never succeeded");
791 
792  pg_atomic_write_u64(&var, 0);
793 
794  /* try setting flagbits */
795  EXPECT_TRUE(!(pg_atomic_fetch_or_u64(&var, 1) & 1));
796  EXPECT_TRUE(pg_atomic_fetch_or_u64(&var, 2) & 1);
798  /* try clearing flagbits */
799  EXPECT_EQ_U64((pg_atomic_fetch_and_u64(&var, ~2) & 3), 3);
801  /* no bits set anymore */
803 }
804 
805 /*
806  * Perform, fairly minimal, testing of the spinlock implementation.
807  *
808  * It's likely worth expanding these to actually test concurrency etc, but
809  * having some regularly run tests is better than none.
810  */
811 static void
813 {
814  /*
815  * Basic tests for spinlocks, as well as the underlying operations.
816  *
817  * We embed the spinlock in a struct with other members to test that the
818  * spinlock operations don't perform too wide writes.
819  */
820  {
821  struct test_lock_struct
822  {
823  char data_before[4];
824  slock_t lock;
825  char data_after[4];
826  } struct_w_lock;
827 
828  memcpy(struct_w_lock.data_before, "abcd", 4);
829  memcpy(struct_w_lock.data_after, "ef12", 4);
830 
831  /* test basic operations via the SpinLock* API */
832  SpinLockInit(&struct_w_lock.lock);
833  SpinLockAcquire(&struct_w_lock.lock);
834  SpinLockRelease(&struct_w_lock.lock);
835 
836  /* test basic operations via underlying S_* API */
837  S_INIT_LOCK(&struct_w_lock.lock);
838  S_LOCK(&struct_w_lock.lock);
839  S_UNLOCK(&struct_w_lock.lock);
840 
841  /* and that "contended" acquisition works */
842  s_lock(&struct_w_lock.lock, "testfile", 17, "testfunc");
843  S_UNLOCK(&struct_w_lock.lock);
844 
845  /*
846  * Check, using TAS directly, that a single spin cycle doesn't block
847  * when acquiring an already acquired lock.
848  */
849 #ifdef TAS
850  S_LOCK(&struct_w_lock.lock);
851 
852  if (!TAS(&struct_w_lock.lock))
853  elog(ERROR, "acquired already held spinlock");
854 
855 #ifdef TAS_SPIN
856  if (!TAS_SPIN(&struct_w_lock.lock))
857  elog(ERROR, "acquired already held spinlock");
858 #endif /* defined(TAS_SPIN) */
859 
860  S_UNLOCK(&struct_w_lock.lock);
861 #endif /* defined(TAS) */
862 
863  /*
864  * Verify that after all of this the non-lock contents are still
865  * correct.
866  */
867  if (memcmp(struct_w_lock.data_before, "abcd", 4) != 0)
868  elog(ERROR, "padding before spinlock modified");
869  if (memcmp(struct_w_lock.data_after, "ef12", 4) != 0)
870  elog(ERROR, "padding after spinlock modified");
871  }
872 
873  /*
874  * Ensure that allocating more than INT32_MAX emulated spinlocks
875  * works. That's interesting because the spinlock emulation uses a 32bit
876  * integer to map spinlocks onto semaphores. There've been bugs...
877  */
878 #ifndef HAVE_SPINLOCKS
879  {
880  /*
881  * Initialize enough spinlocks to advance counter close to
882  * wraparound. It's too expensive to perform acquire/release for each,
883  * as those may be syscalls when the spinlock emulation is used (and
884  * even just atomic TAS would be expensive).
885  */
886  for (uint32 i = 0; i < INT32_MAX - 100000; i++)
887  {
888  slock_t lock;
889 
890  SpinLockInit(&lock);
891  }
892 
893  for (uint32 i = 0; i < 200000; i++)
894  {
895  slock_t lock;
896 
897  SpinLockInit(&lock);
898 
899  SpinLockAcquire(&lock);
900  SpinLockRelease(&lock);
901  SpinLockAcquire(&lock);
902  SpinLockRelease(&lock);
903  }
904  }
905 #endif
906 }
907 
908 /*
909  * Verify that performing atomic ops inside a spinlock isn't a
910  * problem. Realistically that's only going to be a problem when both
911  * --disable-spinlocks and --disable-atomics are used, but it's cheap enough
912  * to just always test.
913  *
914  * The test works by initializing enough atomics that we'd conflict if there
915  * were an overlap between a spinlock and an atomic by holding a spinlock
916  * while manipulating more than NUM_SPINLOCK_SEMAPHORES atomics.
917  *
918  * NUM_TEST_ATOMICS doesn't really need to be more than
919  * NUM_SPINLOCK_SEMAPHORES, but it seems better to test a bit more
920  * extensively.
921  */
922 static void
924 {
925  slock_t lock;
926 #define NUM_TEST_ATOMICS (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES + 27)
929 
930  SpinLockInit(&lock);
931 
932  for (int i = 0; i < NUM_TEST_ATOMICS; i++)
933  {
934  pg_atomic_init_u32(&atomics32[i], 0);
935  pg_atomic_init_u64(&atomics64[i], 0);
936  }
937 
938  /* just so it's not all zeroes */
939  for (int i = 0; i < NUM_TEST_ATOMICS; i++)
940  {
941  EXPECT_EQ_U32(pg_atomic_fetch_add_u32(&atomics32[i], i), 0);
942  EXPECT_EQ_U64(pg_atomic_fetch_add_u64(&atomics64[i], i), 0);
943  }
944 
945  /* test whether we can do atomic op with lock held */
946  SpinLockAcquire(&lock);
947  for (int i = 0; i < NUM_TEST_ATOMICS; i++)
948  {
949  EXPECT_EQ_U32(pg_atomic_fetch_sub_u32(&atomics32[i], i), i);
950  EXPECT_EQ_U32(pg_atomic_read_u32(&atomics32[i]), 0);
951  EXPECT_EQ_U64(pg_atomic_fetch_sub_u64(&atomics64[i], i), i);
952  EXPECT_EQ_U64(pg_atomic_read_u64(&atomics64[i]), 0);
953  }
954  SpinLockRelease(&lock);
955 }
956 #undef NUM_TEST_ATOMICS
957 
959 Datum
961 {
963 
965 
967 
968  /*
969  * Arguably this shouldn't be tested as part of this function, but it's
970  * closely enough related that that seems ok for now.
971  */
972  test_spinlock();
973 
975 
976  PG_RETURN_BOOL(true);
977 }
978 
980 Datum
982 {
983  elog(ERROR, "test_fdw_handler is not implemented");
984  PG_RETURN_NULL();
985 }
986 
988 Datum
990 {
991  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
992  Node *ret = NULL;
993 
994  if (IsA(rawreq, SupportRequestSelectivity))
995  {
996  /*
997  * Assume that the target is int4eq; that's safe as long as we don't
998  * attach this to any other boolean-returning function.
999  */
1001  Selectivity s1;
1002 
1003  if (req->is_join)
1004  s1 = join_selectivity(req->root, Int4EqualOperator,
1005  req->args,
1006  req->inputcollid,
1007  req->jointype,
1008  req->sjinfo);
1009  else
1010  s1 = restriction_selectivity(req->root, Int4EqualOperator,
1011  req->args,
1012  req->inputcollid,
1013  req->varRelid);
1014 
1015  req->selectivity = s1;
1016  ret = (Node *) req;
1017  }
1018 
1019  if (IsA(rawreq, SupportRequestCost))
1020  {
1021  /* Provide some generic estimate */
1022  SupportRequestCost *req = (SupportRequestCost *) rawreq;
1023 
1024  req->startup = 0;
1025  req->per_tuple = 2 * cpu_operator_cost;
1026  ret = (Node *) req;
1027  }
1028 
1029  if (IsA(rawreq, SupportRequestRows))
1030  {
1031  /*
1032  * Assume that the target is generate_series_int4; that's safe as long
1033  * as we don't attach this to any other set-returning function.
1034  */
1035  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1036 
1037  if (req->node && IsA(req->node, FuncExpr)) /* be paranoid */
1038  {
1039  List *args = ((FuncExpr *) req->node)->args;
1040  Node *arg1 = linitial(args);
1041  Node *arg2 = lsecond(args);
1042 
1043  if (IsA(arg1, Const) &&
1044  !((Const *) arg1)->constisnull &&
1045  IsA(arg2, Const) &&
1046  !((Const *) arg2)->constisnull)
1047  {
1048  int32 val1 = DatumGetInt32(((Const *) arg1)->constvalue);
1049  int32 val2 = DatumGetInt32(((Const *) arg2)->constvalue);
1050 
1051  req->rows = val2 - val1 + 1;
1052  ret = (Node *) req;
1053  }
1054  }
1055  }
1056 
1057  PG_RETURN_POINTER(ret);
1058 }
1059 
1061 Datum
1063 {
1064  PG_RETURN_NULL();
1065 }
1066 
1067 /*
1068  * Call an encoding conversion or verification function.
1069  *
1070  * Arguments:
1071  * string bytea -- string to convert
1072  * src_enc name -- source encoding
1073  * dest_enc name -- destination encoding
1074  * noError bool -- if set, don't ereport() on invalid or untranslatable
1075  * input
1076  *
1077  * Result is a tuple with two attributes:
1078  * int4 -- number of input bytes successfully converted
1079  * bytea -- converted string
1080  */
1082 Datum
1084 {
1085  bytea *string = PG_GETARG_BYTEA_PP(0);
1086  char *src_encoding_name = NameStr(*PG_GETARG_NAME(1));
1087  int src_encoding = pg_char_to_encoding(src_encoding_name);
1088  char *dest_encoding_name = NameStr(*PG_GETARG_NAME(2));
1089  int dest_encoding = pg_char_to_encoding(dest_encoding_name);
1090  bool noError = PG_GETARG_BOOL(3);
1091  TupleDesc tupdesc;
1092  char *src;
1093  char *dst;
1094  bytea *retval;
1095  Size srclen;
1096  Size dstsize;
1097  Oid proc;
1098  int convertedbytes;
1099  int dstlen;
1100  Datum values[2];
1101  bool nulls[2];
1102  HeapTuple tuple;
1103 
1104  if (src_encoding < 0)
1105  ereport(ERROR,
1106  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1107  errmsg("invalid source encoding name \"%s\"",
1108  src_encoding_name)));
1109  if (dest_encoding < 0)
1110  ereport(ERROR,
1111  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1112  errmsg("invalid destination encoding name \"%s\"",
1113  dest_encoding_name)));
1114 
1115  /* Build a tuple descriptor for our result type */
1116  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1117  elog(ERROR, "return type must be a row type");
1118  tupdesc = BlessTupleDesc(tupdesc);
1119 
1120  srclen = VARSIZE_ANY_EXHDR(string);
1121  src = VARDATA_ANY(string);
1122 
1123  if (src_encoding == dest_encoding)
1124  {
1125  /* just check that the source string is valid */
1126  int oklen;
1127 
1128  oklen = pg_encoding_verifymbstr(src_encoding, src, srclen);
1129 
1130  if (oklen == srclen)
1131  {
1132  convertedbytes = oklen;
1133  retval = string;
1134  }
1135  else if (!noError)
1136  {
1137  report_invalid_encoding(src_encoding, src + oklen, srclen - oklen);
1138  }
1139  else
1140  {
1141  /*
1142  * build bytea data type structure.
1143  */
1144  Assert(oklen < srclen);
1145  convertedbytes = oklen;
1146  retval = (bytea *) palloc(oklen + VARHDRSZ);
1147  SET_VARSIZE(retval, oklen + VARHDRSZ);
1148  memcpy(VARDATA(retval), src, oklen);
1149  }
1150  }
1151  else
1152  {
1153  proc = FindDefaultConversionProc(src_encoding, dest_encoding);
1154  if (!OidIsValid(proc))
1155  ereport(ERROR,
1156  (errcode(ERRCODE_UNDEFINED_FUNCTION),
1157  errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
1158  pg_encoding_to_char(src_encoding),
1159  pg_encoding_to_char(dest_encoding))));
1160 
1161  if (srclen >= (MaxAllocSize / (Size) MAX_CONVERSION_GROWTH))
1162  ereport(ERROR,
1163  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
1164  errmsg("out of memory"),
1165  errdetail("String of %d bytes is too long for encoding conversion.",
1166  (int) srclen)));
1167 
1168  dstsize = (Size) srclen * MAX_CONVERSION_GROWTH + 1;
1169  dst = MemoryContextAlloc(CurrentMemoryContext, dstsize);
1170 
1171  /* perform conversion */
1172  convertedbytes = pg_do_encoding_conversion_buf(proc,
1173  src_encoding,
1174  dest_encoding,
1175  (unsigned char *) src, srclen,
1176  (unsigned char *) dst, dstsize,
1177  noError);
1178  dstlen = strlen(dst);
1179 
1180  /*
1181  * build bytea data type structure.
1182  */
1183  retval = (bytea *) palloc(dstlen + VARHDRSZ);
1184  SET_VARSIZE(retval, dstlen + VARHDRSZ);
1185  memcpy(VARDATA(retval), dst, dstlen);
1186 
1187  pfree(dst);
1188  }
1189 
1190  MemSet(nulls, 0, sizeof(nulls));
1191  values[0] = Int32GetDatum(convertedbytes);
1192  values[1] = PointerGetDatum(retval);
1193  tuple = heap_form_tuple(tupdesc, values, nulls);
1194 
1196 }
int SPI_fnumber(TupleDesc tupdesc, const char *fname)
Definition: spi.c:1071
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int slock_t
Definition: s_lock.h:934
static void pg_atomic_clear_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:209
#define VARATT_IS_EXTERNAL_ONDISK(PTR)
Definition: postgres.h:327
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
Oid SPI_gettypeid(TupleDesc tupdesc, int fnumber)
Definition: spi.c:1204
double radius
Definition: regress.c:160
#define S_INIT_LOCK(lock)
Definition: s_lock.h:943
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:343
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
Datum make_tuple_indirect(PG_FUNCTION_ARGS)
Definition: regress.c:535
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:467
int pg_char_to_encoding(const char *name)
Definition: encnames.c:550
#define VARDATA_ANY(PTR)
Definition: postgres.h:361
#define VARDATA(PTR)
Definition: postgres.h:315
#define TAS(lock)
Definition: s_lock.h:944
#define RDELIM
Definition: regress.c:76
MemoryContext TopTransactionContext
Definition: mcxt.c:53
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
Definition: typcache.c:1826
Datum int44in(PG_FUNCTION_ARGS)
Definition: regress.c:495
#define DatumGetInt32(X)
Definition: postgres.h:516
#define NUM_TEST_ATOMICS
Datum test_fdw_handler(PG_FUNCTION_ARGS)
Definition: regress.c:981
float8 x
Definition: geo_decls.h:98
int SPI_connect(void)
Definition: spi.c:98
static void test_atomic_uint32(void)
Definition: regress.c:687
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
Definition: atomics.h:311
Selectivity restriction_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
Definition: plancat.c:1834
#define PointerGetDatum(X)
Definition: postgres.h:600
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
Definition: atomics.h:401
#define VARHDRSZ
Definition: c.h:627
static uint64 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:513
int pg_encoding_verifymbstr(int encoding, const char *mbstr, int len)
Definition: wchar.c:1953
struct varlena * detoast_external_attr(struct varlena *attr)
Definition: detoast.c:45
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
Definition: spi.c:756
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define SpinLockInit(lock)
Definition: spin.h:60
void report_invalid_encoding(int encoding, const char *mbstr, int len)
Definition: mbutils.c:1647
int SPI_finish(void)
Definition: spi.c:185
Datum nextval(PG_FUNCTION_ARGS)
Definition: sequence.c:549
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
Definition: nodes.h:539
int errcode(int sqlerrcode)
Definition: elog.c:698
Datum lseg_interpt(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2326
bool superuser(void)
Definition: superuser.c:46
#define MemSet(start, val, len)
Definition: c.h:1008
static uint32 pg_atomic_add_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:386
#define kill(pid, sig)
Definition: win32_port.h:454
Datum test_support_func(PG_FUNCTION_ARGS)
Definition: regress.c:989
Datum GetAttributeByName(HeapTupleHeader tuple, const char *attname, bool *isNull)
Definition: execUtils.c:1023
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:626
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
double Selectivity
Definition: nodes.h:672
#define PG_GETARG_HEAPTUPLEHEADER(n)
Definition: fmgr.h:312
NameData relname
Definition: pg_class.h:38
unsigned int Oid
Definition: postgres_ext.h:31
static uint64 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
Definition: atomics.h:476
#define OidIsValid(objectId)
Definition: c.h:710
#define VARDATA_EXTERNAL(PTR)
Definition: postgres.h:323
#define lsecond(l)
Definition: pg_list.h:179
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:438
Datum set_ttdummy(PG_FUNCTION_ARGS)
Definition: regress.c:457
HeapTuple tg_trigtuple
Definition: trigger.h:35
static bool pg_atomic_compare_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 *expected, uint64 newval)
Definition: atomics.h:456
signed int int32
Definition: c.h:429
#define EXPECT_TRUE(expr)
Definition: regress.c:47
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:309
Datum reverse_name(PG_FUNCTION_ARGS)
Definition: regress.c:226
Datum point_distance(PG_FUNCTION_ARGS)
Definition: geo_ops.c:1962
HeapTupleHeader t_data
Definition: htup.h:68
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
Definition: atomics.h:292
#define HeapTupleHeaderGetTypMod(tup)
Definition: htup_details.h:467
static bool ttoff
Definition: regress.c:263
#define NAMEDATALEN
int SPI_result
Definition: spi.c:47
#define sprintf
Definition: port.h:218
#define setenv(x, y, z)
Definition: win32_port.h:497
#define SpinLockAcquire(lock)
Definition: spin.h:62
void pg_usleep(long microsec)
Definition: signal.c:53
static uint64 pg_atomic_exchange_u64(volatile pg_atomic_uint64 *ptr, uint64 newval)
Definition: atomics.h:447
void pfree(void *pointer)
Definition: mcxt.c:1169
#define LsegPGetDatum(X)
Definition: geo_decls.h:181
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:415
#define VARATT_IS_EXTERNAL_INDIRECT(PTR)
Definition: postgres.h:329
#define linitial(l)
Definition: pg_list.h:174
#define ERROR
Definition: elog.h:46
double float8
Definition: c.h:565
char * s1
struct PlannerInfo * root
Definition: supportnodes.h:96
struct SpecialJoinInfo * sjinfo
Definition: supportnodes.h:103
Datum test_atomic_ops(PG_FUNCTION_ARGS)
Definition: regress.c:960
#define PG_GETARG_POINT_P(n)
Definition: geo_decls.h:177
Point p[FLEXIBLE_ARRAY_MEMBER]
Definition: geo_decls.h:121
int32 npts
Definition: geo_decls.h:118
ItemPointerData t_self
Definition: htup.h:65
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
Definition: spi.c:1148
#define DatumGetInt64(X)
Definition: postgres.h:651
const char * SPI_result_code_string(int code)
Definition: spi.c:1862
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
uint32 t_len
Definition: htup.h:64
int SPI_keepplan(SPIPlanPtr plan)
Definition: spi.c:872
static void test_spinlock(void)
Definition: regress.c:812
#define SET_VARTAG_EXTERNAL(PTR, tag)
Definition: postgres.h:346
static bool pg_atomic_test_set_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:185
char * flag(int b)
Definition: test-ctype.c:33
int errdetail(const char *fmt,...)
Definition: elog.c:1042
static uint64 pg_atomic_fetch_or_u64(volatile pg_atomic_uint64 *ptr, uint64 or_)
Definition: atomics.h:495
char string[11]
Definition: preproc-type.c:46
#define DatumGetBool(X)
Definition: postgres.h:437
static uint32 pg_atomic_fetch_and_u32(volatile pg_atomic_uint32 *ptr, uint32 and_)
Definition: atomics.h:358
Datum test_opclass_options_func(PG_FUNCTION_ARGS)
Definition: regress.c:1062
unsigned int uint32
Definition: c.h:441
Oid t_tableOid
Definition: htup.h:66
double cpu_operator_cost
Definition: costsize.c:123
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
PG_FUNCTION_INFO_V1(interpt_pp)
static SPIPlanPtr splan
Definition: regress.c:262
#define INDIRECT_POINTER_SIZE
Definition: detoast.h:34
#define PG_INT16_MIN
Definition: c.h:520
HeapTuple SPI_modifytuple(Relation rel, HeapTuple tuple, int natts, int *attnum, Datum *Values, const char *Nulls)
Definition: spi.c:1002
#define PG_GETARG_PATH_P(n)
Definition: geo_decls.h:188
static void test_atomic_flag(void)
Definition: regress.c:671
#define MaxAllocSize
Definition: memutils.h:40
#define EXPECT_EQ_U32(result_expr, expected_expr)
Definition: regress.c:55
int16 attlen
Definition: pg_attribute.h:68
#define EXPECT_EQ_U64(result_expr, expected_expr)
Definition: regress.c:65
static void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2)
Definition: regress.c:129
#define SpinLockRelease(lock)
Definition: spin.h:64
#define DELIM
Definition: regress.c:77
Datum lseg_intersect(PG_FUNCTION_ARGS)
Definition: geo_ops.c:2153
#define TTDUMMY_INFINITY
Definition: regress.c:260
PG_MODULE_MAGIC
Definition: regress.c:81
void * palloc0(Size size)
Definition: mcxt.c:1093
#define DatumGetFloat8(X)
Definition: postgres.h:758
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
uintptr_t Datum
Definition: postgres.h:411
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define TAS_SPIN(lock)
Definition: s_lock.h:1001
#define HeapTupleHeaderGetTypeId(tup)
Definition: htup_details.h:457
Trigger * tg_trigger
Definition: trigger.h:37
HeapTuple tg_newtuple
Definition: trigger.h:36
#define VARSIZE_ANY(PTR)
Definition: postgres.h:348
Datum widget_out(PG_FUNCTION_ARGS)
Definition: regress.c:198
char * SPI_getrelname(Relation rel)
Definition: spi.c:1222
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:83
#define ereport(elevel,...)
Definition: elog.h:157
Datum widget_in(PG_FUNCTION_ARGS)
Definition: regress.c:169
Datum pt_in_widget(PG_FUNCTION_ARGS)
Definition: regress.c:210
#define PG_RETURN_VOID()
Definition: fmgr.h:349
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
Definition: atomics.h:328
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:588
#define CALLED_AS_TRIGGER(fcinfo)
Definition: trigger.h:25
#define Assert(condition)
Definition: c.h:804
float8 y
Definition: geo_decls.h:98
TriggerEvent tg_event
Definition: trigger.h:33
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
static void test_atomic_uint64(void)
Definition: regress.c:759
size_t Size
Definition: c.h:540
#define NARGS
Definition: regress.c:166
Datum interpt_pp(PG_FUNCTION_ARGS)
Definition: regress.c:88
#define PG_GETARG_BYTEA_PP(n)
Definition: fmgr.h:308
Oid FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
Definition: namespace.c:3709
Point p[2]
Definition: geo_decls.h:108
#define PG_INT16_MAX
Definition: c.h:521
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:221
struct varlena * pointer
Definition: postgres.h:96
static uint64 pg_atomic_fetch_and_u64(volatile pg_atomic_uint64 *ptr, uint64 and_)
Definition: atomics.h:486
static bool pg_atomic_unlocked_test_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:198
Datum test_enc_conversion(PG_FUNCTION_ARGS)
Definition: regress.c:1083
#define S_UNLOCK(lock)
Definition: s_lock.h:942
Datum overpaid(PG_FUNCTION_ARGS)
Definition: regress.c:140
#define DatumGetPointer(X)
Definition: postgres.h:593
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
Definition: heaptuple.c:1249
#define TRIGGER_FIRED_BEFORE(event)
Definition: trigger.h:127
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define MAX_CONVERSION_GROWTH
Definition: pg_wchar.h:316
Datum wait_pid(PG_FUNCTION_ARGS)
Definition: regress.c:651
static uint64 pg_atomic_add_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
Definition: atomics.h:504
char * text_to_cstring(const text *t)
Definition: varlena.c:223
Datum trigger_return_old(PG_FUNCTION_ARGS)
Definition: regress.c:247
#define Int32GetDatum(X)
Definition: postgres.h:523
#define TRIGGER_FIRED_BY_INSERT(event)
Definition: trigger.h:109
#define ItemPointerSetInvalid(pointer)
Definition: itemptr.h:172
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
Definition: atomics.h:429
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:354
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
Point center
Definition: regress.c:159
#define elog(elevel,...)
Definition: elog.h:232
int i
int SPI_execp(SPIPlanPtr plan, Datum *Values, const char *Nulls, long tcount)
Definition: spi.c:609
#define NameStr(name)
Definition: c.h:681
#define CStringGetTextDatum(s)
Definition: builtins.h:82
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
static uint32 pg_atomic_fetch_or_u32(volatile pg_atomic_uint32 *ptr, uint32 or_)
Definition: atomics.h:372
Datum int44out(PG_FUNCTION_ARGS)
Definition: regress.c:519
Definition: c.h:621
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
Selectivity join_selectivity(PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
Definition: plancat.c:1873
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:102
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:223
Datum ttdummy(PG_FUNCTION_ARGS)
Definition: regress.c:268
Datum regress_setenv(PG_FUNCTION_ARGS)
Definition: regress.c:633
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:258
#define ReleaseTupleDesc(tupdesc)
Definition: tupdesc.h:122
#define TRIGGER_FIRED_FOR_ROW(event)
Definition: trigger.h:121
int pg_do_encoding_conversion_buf(Oid proc, int src_encoding, int dest_encoding, unsigned char *src, int srclen, unsigned char *dest, int destlen, bool noError)
Definition: mbutils.c:469
static void pg_atomic_init_flag(volatile pg_atomic_flag *ptr)
Definition: atomics.h:172
Definition: pg_list.h:50
#define snprintf
Definition: port.h:216
#define S_LOCK(lock)
Definition: s_lock.h:955
#define TRIGGER_FIRED_BY_UPDATE(event)
Definition: trigger.h:115
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:628
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PointPGetDatum(X)
Definition: geo_decls.h:176
static void test_atomic_spin_nest(void)
Definition: regress.c:923
#define PG_GETARG_NAME(n)
Definition: fmgr.h:278
int s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
Definition: s_lock.c:91
#define LDELIM
Definition: regress.c:75
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
Definition: atomics.h:241
Relation tg_relation
Definition: trigger.h:34
#define HeapTupleHeaderGetDatumLength(tup)
Definition: htup_details.h:451