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