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