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